From d87e105a873716243d087372a60b3913f0bd7b3d Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Fri, 18 Mar 2022 22:42:09 +0800 Subject: [PATCH] udpate xts Signed-off-by: panqiangbiao --- .../FileAssetGetThumbnailCallBack.test.js | 1541 +++++---- .../test/FileAssetGetThumbnailPromise.test.js | 1518 ++++---- .../src/main/js/test/List.test.js | 89 +- .../test/albumGetFileAssetsCallback.test.js | 500 +++ .../js/test/albumGetFileAssetsPromise.test.js | 805 ++--- .../main/js/test/albumTestCallBack.test.js | 1187 ++++--- .../src/main/js/test/albumTestPromise.test.js | 1567 ++++----- .../main/js/test/distributedCallback.test.js | 91 + .../main/js/test/distributedPromise.test.js | 85 + .../main/js/test/favoriteTestCallBack.test.js | 2875 ++++++++-------- .../main/js/test/favoriteTestPromise.test.js | 2224 ++++++------ .../js/test/fetchFileResultCallBack.test.js | 899 ++--- .../js/test/fetchFileResultPromise.test.js | 1503 ++++---- .../main/js/test/fileAssetCallBack2.test.js | 440 +++ .../main/js/test/fileAssetPromise2.test.js | 398 +++ .../js/test/fileAssetTestCallback.test.js | 1143 ++++++ .../main/js/test/fileAssetTestPromise.test.js | 1826 +++++----- .../js/test/fileAssetUriTestCallBack.test.js | 153 +- .../js/test/fileAssetUriTestPromiese.test.js | 88 + .../src/main/js/test/fileTestCallBack.test.js | 3060 ++--------------- .../src/main/js/test/fileTestPromise.test.js | 1456 ++++---- .../main/js/test/filekeyTestCallBack.test.js | 290 ++ .../main/js/test/filekeyTestPromise.test.js | 6 +- .../getAllPeersDeviceTestCallback.test.js | 241 ++ .../test/getAllPeersDeviceTestPromise.test.js | 83 +- .../js/test/getAllPeersTestCallback.test.js | 307 ++ .../js/test/getAllPeersTestPromise.test.js | 138 +- .../js/test/mediaLibraryTestCallBack.test.js | 938 +++++ .../js/test/mediaLibraryTestPromise.test.js | 1693 ++++----- 29 files changed, 14802 insertions(+), 12342 deletions(-) create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumGetFileAssetsCallback.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributedCallback.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributedPromise.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetCallBack2.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetPromise2.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetTestCallback.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetUriTestPromiese.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/filekeyTestCallBack.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersDeviceTestCallback.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersTestCallback.test.js create mode 100644 multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestCallBack.test.js 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 b546df920..6813d4f2d 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,731 +1,810 @@ -/* - * 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(); - } - }); - }); -}); +/* + * 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_CALLBACK_001_01 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 128, height: 128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_01', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 128, height: 128 }; + asset.getThumbnail(size,async (err, pixelmap) => { + if(pixelmap == undefined){ + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_01 failed'); + done(); + } else { + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_01 pixel image info ' + info); + console.info('MediaLibraryTest : 001_01 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_01 pixel height ' + info.size.height); + expect(info.size.width == size.width).assertTrue(); + expect(info.size.height == size.height).assertTrue(); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_01 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_01 failed'); + done(); + } + } + }); + + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_01 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_02 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 128, height: 256 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_02', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 128, height: 256 }; + asset.getThumbnail(size,async (err, pixelmap) => { + if(pixelmap == undefined) { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_02 failed'); + done(); + } else { + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_02 pixel image info ' + info); + console.info('MediaLibraryTest : 001_02 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_02 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_02 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_02 failed'); + done(); + } + } + }); + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_02 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_03 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by no arg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_03', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 256, height: 256 }; + asset.getThumbnail(async (err,pixelmap) => { + if(pixelmap == undefined) { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_03 failed'); + done(); + } else { + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_03 pixel image info ' + info); + console.info('MediaLibraryTest : 001_03 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_03 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_03 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_03 failed'); + done(); + } + } + }); + + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_03 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_04 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 1, height: 1 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_04', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 1, height: 1 }; + asset.getThumbnail(size,async (err, pixelmap) => { + if(pixelmap == undefined) { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_04 failed'); + done(); + } else{ + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_04 pixel image info ' + info); + console.info('MediaLibraryTest : 001_04 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_04 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_04 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_04 failed'); + done(); + } + } + }); + + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 001_04 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_05 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: 0, height: 0 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_05', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 0, height: 0 }; + asset.getThumbnail(size,async (err, pixelmap) => { + if(pixelmap == undefined) { + expect(true).assertTrue(); + done(); + } else { + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_05 pixel image info ' + info); + console.info('MediaLibraryTest : 001_05 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_05 pixel height ' + info.size.height); + expect(info.size.width == size.width || info.size.height == size.height).assertFalse(); + console.info('MediaLibraryTest : getFileAssets 001_05 failed'); + done(); + } + }); + + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 001_05 failed'); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_06', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: -128, height: -128 }; + asset.getThumbnail(size,async (err, pixelmap) => { + if(pixelmap == undefined) { + expect(true).assertTrue(); + done(); + } else { + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_06 pixel image info ' + info); + console.info('MediaLibraryTest : 001_06 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_06 pixel height ' + info.size.height); + expect(info.size.width == size.width || info.size.height == size.height).assertFalse(); + console.info('MediaLibraryTest : getThumbnail 001_06 failed'); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 001_06 failed '); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_001_07', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 1024, height: 1024 }; + asset.getThumbnail(size,async (err, pixelmap) => { + if(pixelmap == undefined) { + expect(false).assertTrue(); + done(); + } else { + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 003_06 pixel image info ' + info); + console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_07 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_07 failed'); + done(); + } + } + }); + + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_07 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------image type end-------------------------- + + // // ------------------------------video type start ----------------------- + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_01 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 128, height: 128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_01', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 128 }; + // 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_CALLBACK_002_02 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 128, height: 256 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_02', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 256 }; + // 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_CALLBACK_002_03 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by no arg + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_03', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 256, height: 256 }; + // 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_CALLBACK_002_04 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 1, height: 1 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_04', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1, height: 1 }; + // 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_CALLBACK_002_05 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 0, height: 0 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_05', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 0, height: 0 }; + // 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_CALLBACK_002_06 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: -128, height: -128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_06', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: -128, height: -128 }; + // const pixelmap = await asset.getThumbnail(size); + // 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_CALLBACK_002_07 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_002_07', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1024, height: 1024 }; + // 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_CALLBACK_003_01 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 128, height: 128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_01', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 128 }; + // 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_CALLBACK_003_02 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 128, height: 256 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_02', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 256 }; + // 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_CALLBACK_003_03 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by no arg + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_03', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 256, height: 256 }; + // 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_CALLBACK_003_04 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 1, height: 1 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_04', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1, height: 1 }; + // 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_CALLBACK_003_05 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 0, height: 0 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_05', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 0, height: 0 }; + // 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_CALLBACK_003_06 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: -128, height: -128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_06', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: -128, height: -128 }; + // 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_CALLBACK_003_07 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_CALLBACK_003_07', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(audioFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1024, height: 1024 }; + // 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/FileAssetGetThumbnailPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/FileAssetGetThumbnailPromise.test.js index a1c19f938..a5e127dcd 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,759 +1,759 @@ -/* - * 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-------------------------- -}); +/* + * 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(false).assertTrue(); + console.info('MediaLibraryTest : getFileAssets 001_05 failed'); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 001_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(image) by { width: -128, height: -128 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: -128, height: -128 }; + const pixelmap = await asset.getThumbnail(size); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 001_06 pixel image info ' + info); + console.info('MediaLibraryTest : 001_06 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 001_06 pixel height ' + info.size.height); + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_06 failed'); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 001_06 passed '); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07 + * @tc.name : getThumbnail + * @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 } + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageFetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset = dataList[0]; + let size = { width: 1024, height: 1024 }; + const pixelmap = await asset.getThumbnail(size); + const info = await pixelmap.getImageInfo(); + console.info('MediaLibraryTest : 003_06 pixel image info ' + info); + console.info('MediaLibraryTest : 003_06 pixel width ' + info.size.width); + console.info('MediaLibraryTest : 003_06 pixel height ' + info.size.height); + if (info.size.width == size.width && info.size.height == size.height) { + expect(true).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_07 passed'); + done(); + } else { + expect(false).assertTrue(); + console.info('MediaLibraryTest : getThumbnail 001_07 failed'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : getThumbnail 001_07 failed ' + error.message); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------image type end-------------------------- + + // // ------------------------------video type start ----------------------- + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 128, height: 128 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 128 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_01 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_01 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_01 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_01 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_01 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_01 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 128, height: 256 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 128, height: 256 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_02 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_02 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_02 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_02 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_02 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_02 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by no arg + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 256, height: 256 }; + // const pixelmap = await asset.getThumbnail(); + // console.info('MediaLibraryTest : getThumbnail 002_03 Successfull ' + pixelmap); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_03 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_03 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_03 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_03 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 002_03 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_03 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 1, height: 1 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 1, height: 1 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_04 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_04 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_04 pixel height ' + info.size.height); + // if (info.size.width == size.width && info.size.height == size.height) { + // expect(true).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 001_05 passed'); + // done(); + // } else { + // expect(false).assertTrue(); + // console.info('MediaLibraryTest : getThumbnail 001_05 failed'); + // done(); + // } + // } catch (error) { + // console.info('MediaLibraryTest : getThumbnail 002_04 failed ' + error.message); + // expect(false).assertTrue(); + // done(); + // } + // }); + + // /** + // * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05 + // * @tc.name : getThumbnail + // * @tc.desc : getThumbnail(video) by { width: 0, height: 0 } + // * @tc.size : MEDIUM + // * @tc.type : Function + // * @tc.level : Level 0 + // */ + // it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05', 0, async function (done) { + // try { + // const fetchFileResult = await media.getFileAssets(videoFetchOp); + // const dataList = await fetchFileResult.getAllObject(); + // const asset = dataList[0]; + // let size = { width: 0, height: 0 }; + // const pixelmap = await asset.getThumbnail(size); + // const info = await pixelmap.getImageInfo(); + // console.info('MediaLibraryTest : 002_05 pixel image info ' + info); + // console.info('MediaLibraryTest : 002_05 pixel width ' + info.size.width); + // console.info('MediaLibraryTest : 002_05 pixel height ' + info.size.height); + // console.info('MediaLibraryTest : getThumbnail 002_05 failed'); + // expect(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 fbcb969a8..b6b835a0a 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,38 +1,51 @@ -/* - * 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('./getPermission.test.js') -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') - +/* + * 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('./getPermission.test.js') +require('./albumGetFileAssetsCallback.test.js') +require('./albumGetFileAssetsPromise.test.js') +require('./distributedCallback.test.js') +require('./distributedPromise.test.js') +require('./favoriteTestCallBack.test.js') +require('./favoriteTestPromise.test.js') +require('./fetchFileResultCallBack.test.js') +require('./fetchFileResultPromise.test.js') +require('./fileAssetCallBack2.test.js') +require('./FileAssetGetThumbnailCallBack.test.js') +require('./FileAssetGetThumbnailPromise.test.js') +require('./fileAssetPromise2.test.js') +require('./fileAssetTestCallback.test.js') +require('./fileAssetTestPromise.test.js') +require('./fileAssetUriTestCallBack.test.js') +require('./fileAssetUriTestPromiese.test.js') +require('./filekeyTestCallBack.test.js') +require('./filekeyTestPromise.test.js') +require('./fileTestCallBack.test.js') +require('./fileTestPromise.test.js') +require('./getAllPeersDeviceTestCallback.test.js') +require('./getAllPeersDeviceTestPromise.test.js') +require('./getAllPeersTestCallback.test.js') +require('./getAllPeersTestPromise.test.js') +require('./mediaLibraryTestCallBack.test.js') +require('./mediaLibraryTestPromise.test.js') +require('./mediaLibraryTestPromiseOnOff.test.js') +require('./albumTestCallBack.test.js') +require('./albumTestPromise.test.js') + + + + + + diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumGetFileAssetsCallback.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumGetFileAssetsCallback.test.js new file mode 100644 index 000000000..5a8aa53d3 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/albumGetFileAssetsCallback.test.js @@ -0,0 +1,500 @@ +/* + * 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('albumGetFileAssetsCallback.test.js', async 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() {}); + + const fileKeyObj = mediaLibrary.FileKey; + + let imageType = mediaLibrary.MediaType.IMAGE; + let videoType = mediaLibrary.MediaType.VIDEO; + let audioType = mediaLibrary.MediaType.AUDIO; + const count = 3; + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_01 + * @tc.name : getFileAssets + * @tc.desc : more file type all + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_01', 0, async function(done) { + try { + let allTypefetchOp = { + selections : '', + selectionArgs : [], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + album.getFileAssets(allTypefetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_02 + * @tc.name : getFileAssets + * @tc.desc : more file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_02', 0, async function(done) { + try { + let imageAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(imageAlbumfetchOp); + const album = albumList[0]; + album.getFileAssets(imageAlbumfetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_03 + * @tc.name : getFileAssets + * @tc.desc : more file type audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_03', 0, async function(done) { + try { + let audioAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ audioType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(audioAlbumfetchOp); + const album = albumList[0]; + album.getFileAssets(audioAlbumfetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_04 + * @tc.name : getFileAssets + * @tc.desc : more file type video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_04', 0, async function(done) { + try { + let videoAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ videoType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(videoAlbumfetchOp); + const album = albumList[0]; + album.getFileAssets(videoAlbumfetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_05 + * @tc.name : getFileAssets + * @tc.desc : more file type image and video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_05', 0, async function(done) { + try { + let imageAndVideoAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString(), videoType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp); + const album = albumList[0]; + album.getFileAssets(imageAndVideoAlbumfetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_06 + * @tc.name : getFileAssets + * @tc.desc : more file type image and audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_06', 0, async function(done) { + try { + let imageAndAudioAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString(), audioType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp); + const album = albumList[0]; + album.getFileAssets(imageAndAudioAlbumfetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** order: 'date_added DESC LIMIT 0,500' + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_07 + * @tc.name : getFileAssets + * @tc.desc : more file type video and audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_07', 0, async function(done) { + try { + let videoAndAudioAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ videoType.toString(), audioType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp); + const album = albumList[0]; + album.getFileAssets(videoAndAudioAlbumfetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_08 + * @tc.name : getFileAssets + * @tc.desc : more file type image video and audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_08', 0, async function(done) { + try { + let imgAndVideoAndAudioAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString(), videoType.toString(), audioType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(imgAndVideoAndAudioAlbumfetchOp); + const album = albumList[0]; + album.getFileAssets(imgAndVideoAndAudioAlbumfetchOp, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_09 + * @tc.name : getFileAssets + * @tc.desc : one file tpe image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_09', 0, async function(done) { + try { + let albumfetchOpOne = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpOne); + const album = albumList[0]; + album.getFileAssets(albumfetchOpOne, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_10 + * @tc.name : getFileAssets + * @tc.desc : one file type audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_10', 0, async function(done) { + try { + let albumfetchOpOne = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ audioType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpOne); + const album = albumList[0]; + album.getFileAssets(albumfetchOpOne, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_11 + * @tc.name : getFileAssets + * @tc.desc : one file type audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_11', 0, async function(done) { + try { + let albumfetchOpOne = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ videoType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpOne); + const album = albumList[0]; + album.getFileAssets(albumfetchOpOne, (error, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 + * @tc.name : getFileAssets + * @tc.desc : no file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12', 0, async function(done) { + try { + let albumfetchOpNone = { + selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', + selectionArgs : [ imageType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + media.getAlbums(albumfetchOpNone, (error, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 albumList == undefined'); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 albumList.length:' + + albumList.length); + expect(albumList.length == 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 done'); + done(); + } + }); + } catch (error) { + expect(false).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 error:' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_13 + * @tc.name : getFileAssets + * @tc.desc : no file type audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_13', 0, async function(done) { + try { + let albumfetchOpNone = { + selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', + selectionArgs : [ audioType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + + media.getAlbums(albumfetchOpNone, (error, albumList) => { + if (albumList == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_13 albumList == undefined'); + expect(false).assertTrue(); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_13 albumList.length:' + + albumList.length); + expect(albumList.length == 0).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_13 error:' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_14 + * @tc.name : getFileAssets + * @tc.desc : no file type video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_14', 0, async function(done) { + try { + let albumfetchOpNone = { + selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', + selectionArgs : [ videoType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + media.getAlbums(albumfetchOpNone, (error, albumList) => { + if (albumList == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_14 albumList == undefined'); + expect(false).assertTrue(); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_14 albumList.length:' + + albumList.length); + expect(albumList.length == 0).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_14 error:' + error); + expect(false).assertTrue(); + done(); + } + }); +}); \ No newline at end of file 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 f7d775f13..d3457a15a 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 @@ -1,399 +1,406 @@ -/* - * 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('albumGetFileAssetsPromise.test.js', async 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 () {}); - - const fileKeyObj = mediaLibrary.FileKey; - - let imageType = mediaLibrary.MediaType.IMAGE; - let videoType = mediaLibrary.MediaType.VIDEO; - let audioType = mediaLibrary.MediaType.AUDIO; - const count = 3; - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01 - * @tc.name : getFileAssets - * @tc.desc : more file type all - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function (done) { - try { - let allTypefetchOp = { - selections: '', - selectionArgs: [], - order: 'date_added DESC LIMIT 0,3', - }; - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(allTypefetchOp); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02 - * @tc.name : getFileAssets - * @tc.desc : more file type image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function (done) { - try { - let imageAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: 'date_added DESC LIMIT 0,3', - }; - const albumList = await media.getAlbums(imageAlbumfetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(imageAlbumfetchOp); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03 - * @tc.name : getFileAssets - * @tc.desc : more file type audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function (done) { - try { - let audioAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], - order: 'date_added DESC LIMIT 0,3', - }; - const albumList = await media.getAlbums(audioAlbumfetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(audioAlbumfetchOp); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04 - * @tc.name : getFileAssets - * @tc.desc : more file type video - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function (done) { - try { - let videoAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], - order: 'date_added DESC LIMIT 0,3', - }; - const albumList = await media.getAlbums(videoAlbumfetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(videoAlbumfetchOp); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05 - * @tc.name : getFileAssets - * @tc.desc : more file type image and video - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function (done) { - try { - let imageAndVideoAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString(), videoType.toString()], - order: 'date_added DESC LIMIT 0,3', - }; - const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(imageAndVideoAlbumfetchOp); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06 - * @tc.name : getFileAssets - * @tc.desc : more file type image and audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function (done) { - try { - let imageAndAudioAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString(), audioType.toString()], - order: 'date_added DESC LIMIT 0,3', - }; - const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(imageAndAudioAlbumfetchOp); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** order: 'date_added DESC LIMIT 0,500' - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07 - * @tc.name : getFileAssets - * @tc.desc : more file type video and audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function (done) { - try { - let videoAndAudioAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString(), audioType.toString()], - order: 'date_added DESC LIMIT 0,3', - }; - const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(videoAndAudioAlbumfetchOp); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08 - * @tc.name : getFileAssets - * @tc.desc : more file type image video and audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08', 0, async function (done) { - try { - let imgAndVideoAndAudioAlbumfetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: [imageType.toString(), videoType.toString(), audioType.toString()], - order: 'date_added DESC LIMIT 0,3', - }; - const albumList = await media.getAlbums(imgAndVideoAndAudioAlbumfetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(imgAndVideoAndAudioAlbumfetchOp); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09 - * @tc.name : getFileAssets - * @tc.desc : one file tpe image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09', 0, async function (done) { - try { - let albumfetchOpOne = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], - order: 'date_added DESC LIMIT 0,1', - }; - const albumList = await media.getAlbums(albumfetchOpOne); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(albumfetchOpOne); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10 - * @tc.name : getFileAssets - * @tc.desc : one file type audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10', 0, async function (done) { - try { - let albumfetchOpOne = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], - order: 'date_added DESC LIMIT 0,1', - }; - const albumList = await media.getAlbums(albumfetchOpOne); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(albumfetchOpOne); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11 - * @tc.name : getFileAssets - * @tc.desc : one file type audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11', 0, async function (done) { - try { - let albumfetchOpOne = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], - order: 'date_added DESC LIMIT 0,1', - }; - const albumList = await media.getAlbums(albumfetchOpOne); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(albumfetchOpOne); - expect(fetchFileResult.getCount() <= count).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 - * @tc.name : getFileAssets - * @tc.desc : no file type image - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12', 0, async function (done) { - try { - let albumfetchOpNone = { - selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', - selectionArgs: [imageType.toString()], - order: 'date_added DESC LIMIT 0,1', - }; - const albumList = await media.getAlbums(albumfetchOpNone); - expect(albumList.length == 0).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 - * @tc.name : getFileAssets - * @tc.desc : no file type audio - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13', 0, async function (done) { - try { - let albumfetchOpNone = { - selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', - selectionArgs: [audioType.toString()], - order: 'date_added DESC LIMIT 0,1', - }; - const albumList = await media.getAlbums(albumfetchOpNone); - expect(albumList.length == 0).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14 - * @tc.name : getFileAssets - * @tc.desc : no file type video - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14', 0, async function (done) { - try { - let albumfetchOpNone = { - selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', - selectionArgs: [videoType.toString()], - order: 'date_added DESC LIMIT 0,1', - }; - const albumList = await media.getAlbums(albumfetchOpNone); - expect(albumList.length == 0).assertTrue(); - done(); - } catch (error) { - expect(false).assertTrue(); - done(); - } - }); -}); +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'; + +describe('albumGetFileAssetsPromise.test.js', async 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() {}); + + const fileKeyObj = mediaLibrary.FileKey; + + let imageType = mediaLibrary.MediaType.IMAGE; + let videoType = mediaLibrary.MediaType.VIDEO; + let audioType = mediaLibrary.MediaType.AUDIO; + const count = 3; + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01 + * @tc.name : getFileAssets + * @tc.desc : more file type all + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function(done) { + try { + let allTypefetchOp = { + selections : '', + selectionArgs : [], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(allTypefetchOp); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02 + * @tc.name : getFileAssets + * @tc.desc : more file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function(done) { + try { + let imageAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(imageAlbumfetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(imageAlbumfetchOp); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03 + * @tc.name : getFileAssets + * @tc.desc : more file type audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function(done) { + try { + let audioAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ audioType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(audioAlbumfetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(audioAlbumfetchOp); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04 + * @tc.name : getFileAssets + * @tc.desc : more file type video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function(done) { + try { + let videoAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ videoType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(videoAlbumfetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(videoAlbumfetchOp); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05 + * @tc.name : getFileAssets + * @tc.desc : more file type image and video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function(done) { + try { + let imageAndVideoAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString(), videoType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(imageAndVideoAlbumfetchOp); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06 + * @tc.name : getFileAssets + * @tc.desc : more file type image and audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function(done) { + try { + let imageAndAudioAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString(), audioType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(imageAndAudioAlbumfetchOp); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** order: 'date_added DESC LIMIT 0,500' + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07 + * @tc.name : getFileAssets + * @tc.desc : more file type video and audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function(done) { + try { + let videoAndAudioAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ videoType.toString(), audioType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(videoAndAudioAlbumfetchOp); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08 + * @tc.name : getFileAssets + * @tc.desc : more file type image video and audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08', 0, async function(done) { + try { + let imgAndVideoAndAudioAlbumfetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString(), videoType.toString(), audioType.toString() ], + order : 'date_added DESC LIMIT 0,3', + }; + const albumList = await media.getAlbums(imgAndVideoAndAudioAlbumfetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(imgAndVideoAndAudioAlbumfetchOp); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09 + * @tc.name : getFileAssets + * @tc.desc : one file tpe image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09', 0, async function(done) { + try { + let albumfetchOpOne = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ imageType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpOne); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(albumfetchOpOne); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10 + * @tc.name : getFileAssets + * @tc.desc : one file type audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10', 0, async function(done) { + try { + let albumfetchOpOne = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ audioType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpOne); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(albumfetchOpOne); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11 + * @tc.name : getFileAssets + * @tc.desc : one file type audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11', 0, async function(done) { + try { + let albumfetchOpOne = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ videoType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpOne); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(albumfetchOpOne); + expect(fetchFileResult.getCount() <= count).assertTrue(); + done(); + } catch (error) { + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 + * @tc.name : getFileAssets + * @tc.desc : no file type image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12', 0, async function(done) { + try { + let albumfetchOpNone = { + selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', + selectionArgs : [ imageType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpNone); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 albumList.length:' + + albumList.length); + expect(albumList.length == 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 done'); + done(); + } catch (error) { + expect(false).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 error:' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 + * @tc.name : getFileAssets + * @tc.desc : no file type audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13', 0, async function(done) { + try { + let albumfetchOpNone = { + selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', + selectionArgs : [ audioType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpNone); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 albumList.length:' + + albumList.length); + expect(albumList.length == 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 done'); + done(); + } catch (error) { + expect(false).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 error:' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14 + * @tc.name : getFileAssets + * @tc.desc : no file type video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14', 0, async function(done) { + try { + let albumfetchOpNone = { + selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', + selectionArgs : [ videoType.toString() ], + order : 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumfetchOpNone); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14 albumList.length:' + + albumList.length); + expect(albumList.length == 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14 done'); + done(); + } catch (error) { + expect(false).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 error:' + error); + done(); + } + }); +}); \ No newline at end of file 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 c31f4bbfe..42f3a2782 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,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 @@ -18,616 +18,911 @@ 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 = { +let imageType = mediaLibrary.MediaType.IMAGE; +let videoType = mediaLibrary.MediaType.VIDEO; +let audioType = mediaLibrary.MediaType.AUDIO; + +let allTypefetchOp = { selections: '', selectionArgs: [], }; -let AlbumHasArgsfetchOp = { +let albumCoverUrifetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.ALBUM_NAME + '= ?', + selectionArgs: ['pictures/','weixin'], +}; +let imageAlbumfetchOp = { selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [mediaType.toString()], + selectionArgs: [imageType.toString()], }; - -let fileHasArgsfetchOp = { +let videoAlbumfetchOp = { selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [mediaType.toString()], + selectionArgs: [videoType.toString()], }; -let fileNoArgsfetchOp = { - selections: '', - selectionArgs: [], +let audioAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], +}; +let imageAndVideoAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString(), videoType.toString()], }; +let imageAndAudioAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString(), audioType.toString()], +}; +let videoAndAudioAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString(), audioType.toString()], +}; +function printAlbumMessage(testNum, album) { + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumId: ${album.albumId}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumName: ${album.albumName}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumUri: ${album.albumUri}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.dateModified: ${album.dateModified}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.count: ${album.count}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.relativePath: ${album.relativePath}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.coverUri: ${album.coverUri}`); +} +function checkAlbumAttr(done, album) { + if ( + album.albumId == undefined || + album.albumName == undefined || + album.albumUri == undefined || + album.count == undefined || + album.relativePath == undefined || + album.coverUri == undefined + ) { + console.info('ALBUM_CALLBACK getAlbum 001_01 failed'); + expect(false).assertTrue(); + done(); + } +} -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); +describe('albumTestCallBack.test.js', async function () { 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.'); + beforeAll(function () { }); + beforeEach(function () { }); + afterEach(function () { }); + afterAll(function () { }); + + // ------------------------------ 001 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01 + * @tc.name : getAlbums + * @tc.desc : Get Album by AllTypefetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01', 0, async function (done) { + try { + media.getAlbums(allTypefetchOp, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + const album = albumList[0]; + printAlbumMessage('001_01', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_CALLBACK getAlbum 001_01 success'); + expect(true).assertTrue(); + done(); + } + }); + + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 001_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } }); - afterEach(function () { - console.info('Album Callback MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02', 0, async function (done) { + try { + media.getAlbums(imageAlbumfetchOp, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + const album = albumList[0]; + printAlbumMessage('001_02', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_CALLBACK getAlbum 001_02 success'); + expect(true).assertTrue(); + done(); + } + }); + + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 001_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } }); - 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_03 + * @tc.name : getAlbums + * @tc.desc : Get Album by videoAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_03', 0, async function (done) { + try { + media.getAlbums(videoAlbumfetchOp, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + const album = albumList[0]; + printAlbumMessage('001_03', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_CALLBACK getAlbum 001_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 001_03 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_01 - * @tc.name : media.getAlbums - * @tc.desc : Get Album by AlbumNoArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_04 + * @tc.name : getAlbums + * @tc.desc : Get Album by audioAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_04', 0, async function (done) { + try { + media.getAlbums(audioAlbumfetchOp, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + const album = albumList[0]; + printAlbumMessage('001_04', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_CALLBACK getAlbum 001_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 001_04 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); - 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_05 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndVideoAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_05', 0, async function (done) { + try { + media.getAlbums(imageAndVideoAlbumfetchOp, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + const album = albumList[0]; + + printAlbumMessage('001_05', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_CALLBACK getAlbum 001_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 001_05 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_02 - * @tc.name : media.getAlbums - * @tc.desc : Get Album by null + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_06 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndAudioAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_06', 0, async function (done) { + try { + media.getAlbums(imageAndAudioAlbumfetchOp, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + const album = albumList[0]; + printAlbumMessage('001_06', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_CALLBACK getAlbum 001_06 passed'); + expect(true).assertTrue(); + done(); + } + }); + + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 001_06 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); - 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_001_07 + * @tc.name : getAlbums + * @tc.desc : Get Album by videoAndAudioAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001_07', 0, async function (done) { + try { + media.getAlbums(videoAndAudioAlbumfetchOp, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + const album = albumList[0]; + printAlbumMessage('001_07', album); + checkAlbumAttr(done, album); + console.info('ALBUM_CALLBACK getAlbum 001_07 passed'); + expect(true).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 001_07 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } }); + // ------------------------------ 001 test end ------------------------- + // ------------------------------ 002 test start ------------------------- /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_01 - * @tc.name : media.getAlbums - * @tc.desc : Get Album by AlbumHasArgsfetchOp + * @tc.name : getAlbums + * @tc.desc : Get Album by 666 * @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(); + try { + media.getAlbums(666, (err, albumList) => { + if (albumList == undefined) { + console.info('ALBUM_CALLBACK getalbum 002_01 passed'); + expect(true).assertTrue(); + done(); + } else { + expect(false).assertTrue(); + console.info('ALBUM_CALLBACK getalbum 002_01 failed'); + done(); + } + }); + + } catch (error) { + console.info('ALBUM_CALLBACK getalbum 002_01 passed'); + expect(true).assertTrue(); + done(); + } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_02 - * @tc.name : media.getAlbums - * @tc.desc : Get Album by 666 + * @tc.name : 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(); + try { + media.getAlbums('666', (err, albumList) => { + if (albumList == undefined) { + console.info('ALBUM_CALLBACK getalbum 002_02 passed'); + expect(true).assertTrue(); + done(); + } else { + expect(false).assertTrue(); + console.info('ALBUM_CALLBACK getalbum 002_02 failed'); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getalbum 002_02 passed'); + expect(true).assertTrue(); + done(); + } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_03 - * @tc.name : media.getAlbums - * @tc.desc : Get Album by '666' + * @tc.name : getAlbums + * @tc.desc : Get Album by 0 * @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(); + try { + media.getAlbums(0, (err, albumList) => { + if (albumList == undefined) { + console.info('ALBUM_CALLBACK getalbum 002_03 passed'); + expect(true).assertTrue(); + done(); + } else { + expect(false).assertTrue(); + console.info('ALBUM_CALLBACK getalbum 002_03 failed'); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getalbum 002_03 passed'); + expect(true).assertTrue(); + done(); + } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_04 - * @tc.name : media.getAlbums - * @tc.desc : Get Album by 0.666 + * @tc.name : getAlbums + * @tc.desc : Get Album by true * @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(); + try { + media.getAlbums(true, (err, albumList) => { + if (albumList == undefined) { + console.info('ALBUM_CALLBACK getalbum 002_04 passed'); + expect(true).assertTrue(); + done(); + } else { + expect(false).assertTrue(); + console.info('ALBUM_CALLBACK getalbum 002_04 failed'); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getalbum 002_04 passed'); + expect(true).assertTrue(); + done(); + } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002_05 - * @tc.name : media.getAlbums - * @tc.desc : Get Album true + * @tc.name : getAlbums + * @tc.desc : Get Album by false * @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(); + try { + media.getAlbums(false, (err, albumList) => { + if (albumList == undefined) { + console.info('ALBUM_CALLBACK getalbum 002_05 passed'); + expect(true).assertTrue(); + done(); + } else { + expect(false).assertTrue(); + console.info('ALBUM_CALLBACK getalbum 002_05 failed'); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getalbum 002_05 passed'); + expect(true).assertTrue(); + done(); + } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01 - * @tc.name : album.commitModify - * @tc.desc : Modify Album name 'hello' + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_06 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_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(); - } - }); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_06', 0, async function (done) { + let fileHasArgsfetchOp3 = { + selections: fileKeyObj.MEDIA_TYPE + ' = ?', + selectionArgs: ['666'], + }; + try { + media.getAlbums(fileHasArgsfetchOp3, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + console.info('GETALBUMASSETS_CALLBACK_002_06 length:' + albumList.length); + expect(albumList.length == 0).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getFileAssets 002_06 passed'); + expect(false).assertTrue(); + done(); + } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02 - * @tc.name : album.commitModify - * @tc.desc : Modify Album name '' + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_07 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_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(); - } - }); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_07', 0, async function (done) { + let fileHasArgsfetchOp4 = { + selections: '666' + '= ?', + selectionArgs: [videoType.toString()], + }; + try { + media.getAlbums(fileHasArgsfetchOp4, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + console.info('GETALBUMASSETS_CALLBACK_002_07 length:' + albumList.length); + expect(albumList.length == 0).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getFileAssets 002_07 passed'); + expect(false).assertTrue(); + done(); + } }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_03 - * @tc.name : album.commitModify - * @tc.desc : Modify Album name '?*hello' + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_08 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_002_08', 0, async function (done) { + let fileHasArgsfetchOp5 = { + selections: '666' + '= ?', + selectionArgs: ['666'], + }; - 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(); - } - }); + try { + media.getAlbums(fileHasArgsfetchOp5, (err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + console.info('GETALBUMASSETS_CALLBACK_002_08 length:' + albumList.length); + expect(albumList.length == 0).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getFileAssets 002_08 passed'); + expect(false).assertTrue(); + done(); + } }); + // ------------------------------ 002 test end ------------------------- + // ------------------------------ 003 test start ------------------------- /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04 - * @tc.name : album.commitModify - * @tc.desc : Modify Album name 'i123456...119' + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01 + * @tc.name : commitModify + * @tc.desc : Modify Album name to 'hello' * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_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'; + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_01', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_CALLBACK Modify 003_01 album.albumName(old) = ' + album.albumName); + const newName = 'newhello'; + album.albumName = newName; + + album.commitModify(async () => { + try { + const newAlbumList = await media.getAlbums(allTypefetchOp); + let passed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_CALLBACK Modify 003_01 passed'); + expect(true).assertTrue(); + done(); + passed = true; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_01 commitModify failed, message = ' + error); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_01 failed, message = ' + error); + expect(false).assertTrue(); } - 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(); - } - }); + done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_004_01 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileNoArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02 + * @tc.name : commitModify + * @tc.desc : Modify Album name '' * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_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(); + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_02', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_CALLBACK Modify 003_02 album.albumName(old) = ' + album.albumName); + const newName = ''; + album.albumName = newName; + + album.commitModify(async () => { + try { + const newAlbumList = await media.getAlbums(allTypefetchOp); + let changed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_CALLBACK Modify 003_02 failed'); + expect(false).assertTrue(); + done(); + changed = true; + } } - }); - } else { - console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 004_01 fail, message = ' + err); - expect(false).assertTrue(); - done(); - } - }); + expect(!changed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_02 commitModify failed, message = ' + error); + } + + }); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_02 passed'); + expect(true).assertTrue(); + } + done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_004_01 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by null + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_03 + * @tc.name : commitModify + * @tc.desc : Modify Album name 'i123456...119' * @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(); + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_03', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_CALLBACK Modify 003_03 album.albumName(old) = ' + album.albumName); + let newName = true; + for (var i = 0; i < 1200; i++) { + newName += 'i'; } - }); + album.albumName = newName; + + album.commitModify(async () => { + try { + const newAlbumList = await media.getAlbums(allTypefetchOp); + let changed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_CALLBACK Modify 003_03 failed'); + expect(false).assertTrue(); + done(); + changed = true; + } + } + expect(!changed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_03 commitModify failed, message = ' + error); + } + }); + + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_03 passed'); + expect(true).assertTrue(); + } + done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_01 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04 + * @tc.name : commitModify + * @tc.desc : Modify Album name true * @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(); + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_04', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_CALLBACK Modify 003_04 album.albumName(old) = ' + album.albumName); + const newName = true; + album.albumName = newName; + + album.commitModify(async () => { + try { + const newAlbumList = await media.getAlbums(allTypefetchOp); + let changed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_CALLBACK Modify 003_04 failed'); + expect(false).assertTrue(); + done(); + changed = true; + } } - }); - } else { - console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_01 fail, message = ' + err); - expect(false).assertTrue(); - done(); - } - }); + expect(!changed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_04 commitModify failed, message = ' + error); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_04 passed'); + expect(true).assertTrue(); + } + done(); }); /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_02 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp2 + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_05 + * @tc.name : commitModify + * @tc.desc : Modify Album name false * @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(); + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_003_05', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_CALLBACK Modify 003_05 album.albumName(old) = ' + album.albumName); + const newName = false; + album.albumName = newName; + album.commitModify(async () => { + try { + const newAlbumList = await media.getAlbums(allTypefetchOp); + let changed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_CALLBACK Modify 003_05 failed'); + expect(false).assertTrue(); + done(); + changed = true; + } } - }); - } else { - console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_02 fail, message = ' + err); - expect(false).assertTrue(); - done(); - } - }); + expect(!changed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_05 commitModify failed, message = ' + error); + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK Modify 003_05 passed'); + expect(true).assertTrue(); + } + done(); }); + // ------------------------------ 003 test end ------------------------- + // ------------------------------ 004 test start ------------------------- /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_03 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_004_01 + * @tc.name : album.coverUri + * @tc.desc : check album.coverUri * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - - it('SUB_MEDIA_MEDIALIBRARY_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'); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_004_01', 0, async function (done) { + try { + let coverUrifetchOp = { + selections: '', + selectionArgs: [], + order: 'date_added DESC LIMIT 0,1', + }; + media.getAlbums(albumCoverUrifetchOp, async(err, albumList) => { + if (albumList == undefined) { + expect(false).assertTrue(); + done(); + } else { + const album = albumList[0]; + console.info('ALBUM_CALLBACK getAlbum 004_01 album name = ' + album.albumName); + console.info('ALBUM_CALLBACK getAlbum 004_01 album id = ' + album.albumId); + const fetchFileResult = await album.getFileAssets(coverUrifetchOp); + const asset = await fetchFileResult.getFirstObject(); + if (asset == undefined) { 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(); + console.info('ALBUM_CALLBACK getAlbum 004_01 coveruri = ' + album.coverUri); + console.info('ALBUM_CALLBACK getAlbum 004_01 asset.uri = ' + asset.uri); + expect(asset.uri == album.coverUri).assertTrue(); done(); - } - }); - } else { - console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 fail, message = ' + err); - expect(true).assertTrue(); - done(); - } - }); + } + } + }); + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 004_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } }); + // ------------------------------ 004 test end ------------------------- + // ------------------------------ 005 test start ------------------------- /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_04 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_005_01 + * @tc.name : deleteAsset + * @tc.desc : delete album * @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(); + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_005_01', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + + const album = albumList[0]; + let fetchFileResult = await album.getFileAssets(allTypefetchOp); + + let datas = await fetchFileResult.getAllObject(); + + const assetsLength = datas.length; + + for (let j = 0; j < assetsLength; j++) { + const asset = datas[j]; + if (j == assetsLength - 1) { + media.deleteAsset(asset.uri, async () => { + const albumId = album.albumId; + const newAlbumList = await media.getAlbums(allTypefetchOp); + + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId) { + console.info('ALBUM_CALLBACK getAlbum 005_01 failed'); + expect(false).assertTrue(); + done(); + } + } + console.info('ALBUM_CALLBACK getAlbum 005_01 passed'); + expect(true).assertTrue(); done(); - } - }); - } else { - console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssets 005_03 fail, message = ' + err); - expect(true).assertTrue(); - done(); + }); + } else { + await media.deleteAsset(asset.uri); + } } - }); + } catch (error) { + console.info('ALBUM_CALLBACK getAlbum 005_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } }); + // ------------------------------ 005 test end ------------------------- + // ------------------------------ 006 test start ------------------------- /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_CALLBACK_005_05 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_006_01 + * @tc.name : commitModify + * @tc.desc : Modify Album albumUri * @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(); - } - }); + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_006_01', 0, async function (done) { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + try { + album.albumUri = 'testalbumUri'; + expect(false).assertTrue(); + done(); + } catch (error) { + expect(true).assertTrue(); + done(); + console.info('ALBUM_CALLBACK Modify 006_01 003 album.albumUri error = album.albumUri has no setter'); + } }); - 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'); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_006_02 + * @tc.name : commitModify + * @tc.desc : Modify Album name false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_CALLBACK_006_02', 0, async function (done) { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + try { + album.coverUri = 'testcoverUri'; + expect(false).assertTrue(); + done(); + } catch (error) { + expect(true).assertTrue(); + console.info('ALBUM_CALLBACK Modify 006_01 003 album.albumUri error = album.coverUri has no setter'); + done(); } - } + }); + // ------------------------------ 006 test end ------------------------- }); 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 dcc4519c6..c6b8f4751 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 @@ -1,775 +1,792 @@ -/* - * 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 imageType = mediaLibrary.MediaType.IMAGE; -let videoType = mediaLibrary.MediaType.VIDEO; -let audioType = mediaLibrary.MediaType.AUDIO; - -let allTypefetchOp = { - selections: '', - selectionArgs: [], -}; - -let imageAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], -}; -let videoAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], -}; -let audioAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], -}; -let imageAndVideoAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString(), videoType.toString()], -}; -let imageAndAudioAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString(), audioType.toString()], -}; -let videoAndAudioAlbumfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString(), audioType.toString()], -}; -function printAlbumMessage(testNum, album) { - console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumId: ${album.albumId}`); - console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumName: ${album.albumName}`); - console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumUri: ${album.albumUri}`); - console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.dateModified: ${album.dateModified}`); - console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.count: ${album.count}`); - console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.relativePath: ${album.relativePath}`); - console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.coverUri: ${album.coverUri}`); -} -function checkAlbumAttr(done, album) { - if ( - album.albumId == undefined || - album.albumName == undefined || - album.albumUri == undefined || - album.count == undefined || - album.relativePath == undefined || - album.coverUri == undefined - ) { - console.info('ALBUM_PROMISE getAlbum 001_01 failed'); - expect(false).assertTrue(); - done(); - } -} - -describe('albumTestPromise.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_GETALBUM_PROMISE_001_01 - * @tc.name : getAlbums - * @tc.desc : Get Album by AllTypefetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - printAlbumMessage('001_01', album); - checkAlbumAttr(done, album); - - console.info('ALBUM_PROMISE getAlbum 001_01 success'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 001_01 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAlbumfetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) { - try { - const albumList = await media.getAlbums(imageAlbumfetchOp); - const album = albumList[0]; - printAlbumMessage('001_02', album); - checkAlbumAttr(done, album); - - console.info('ALBUM_PROMISE getAlbum 001_02 success'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 001_02 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03 - * @tc.name : getAlbums - * @tc.desc : Get Album by videoAlbumfetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03', 0, async function (done) { - try { - const albumList = await media.getAlbums(videoAlbumfetchOp); - const album = albumList[0]; - printAlbumMessage('001_03', album); - checkAlbumAttr(done, album); - - console.info('ALBUM_PROMISE getAlbum 001_03 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 001_03 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04 - * @tc.name : getAlbums - * @tc.desc : Get Album by audioAlbumfetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04', 0, async function (done) { - try { - const albumList = await media.getAlbums(audioAlbumfetchOp); - const album = albumList[0]; - printAlbumMessage('001_04', album); - checkAlbumAttr(done, album); - - console.info('ALBUM_PROMISE getAlbum 001_04 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 001_04 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAndVideoAlbumfetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05', 0, async function (done) { - try { - const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp); - const album = albumList[0]; - - printAlbumMessage('001_05', album); - checkAlbumAttr(done, album); - - console.info('ALBUM_PROMISE getAlbum 001_05 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 001_05 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06 - * @tc.name : getAlbums - * @tc.desc : Get Album by imageAndAudioAlbumfetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06', 0, async function (done) { - try { - const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp); - const album = albumList[0]; - printAlbumMessage('001_06', album); - checkAlbumAttr(done, album); - - console.info('ALBUM_PROMISE getAlbum 001_06 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 001_06 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07 - * @tc.name : getAlbums - * @tc.desc : Get Album by videoAndAudioAlbumfetchOp, print all album info, - * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), - * check media types (imageType, audioType) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07', 0, async function (done) { - try { - const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp); - const album = albumList[0]; - printAlbumMessage('001_07', album); - checkAlbumAttr(done, album); - - console.info('ALBUM_PROMISE getAlbum 001_07 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 001_07 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 001 test end ------------------------- - - // ------------------------------ 002 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01 - * @tc.name : getAlbums - * @tc.desc : Get Album by 666 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01', 0, async function (done) { - try { - await media.getAlbums(666); - expect(false).assertTrue(); - console.info('ALBUM_PROMISE getalbum 002_01 failed'); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getalbum 002_01 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02 - * @tc.name : getAlbums - * @tc.desc : Get Album by '666' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02', 0, async function (done) { - try { - await media.getAlbums('666'); - console.info('ALBUM_PROMISE getalbum 002_02 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getalbum 002_02 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03 - * @tc.name : getAlbums - * @tc.desc : Get Album by 0 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03', 0, async function (done) { - try { - await media.getAlbums(0); - console.info('ALBUM_PROMISE getalbum 002_03 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getalbum 002_03 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04 - * @tc.name : getAlbums - * @tc.desc : Get Album by true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04', 0, async function (done) { - try { - await media.getAlbums(true); - console.info('ALBUM_PROMISE getalbum 002_04 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getalbum 002_04 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05 - * @tc.name : getAlbums - * @tc.desc : Get Album by false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05', 0, async function (done) { - try { - await media.getAlbums(false); - console.info('ALBUM_PROMISE getalbum 002_05 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getalbum 002_05 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06', 0, async function (done) { - let fileHasArgsfetchOp3 = { - selections: fileKeyObj.MEDIA_TYPE + ' = ?', - selectionArgs: ['666'], - }; - try { - const albumList = await media.getAlbums(fileHasArgsfetchOp3); - console.info('GETALBUMASSETS_PROMISE_002_06 length:' + albumList.length); - expect(albumList.length == 0).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getFileAssets 002_06 passed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07', 0, async function (done) { - let fileHasArgsfetchOp4 = { - selections: '666' + '= ?', - selectionArgs: [videoType.toString()], - }; - try { - const albumList = await media.getAlbums(fileHasArgsfetchOp4); - console.info('GETALBUMASSETS_PROMISE_002_07 length:' + albumList.length); - expect(albumList.length == 0).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getFileAssets 002_07 passed'); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08 - * @tc.name : album.getFileAssets - * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08', 0, async function (done) { - let fileHasArgsfetchOp5 = { - selections: '666' + '= ?', - selectionArgs: ['666'], - }; - - try { - const albumList = await media.getAlbums(fileHasArgsfetchOp5); - console.info('GETALBUMASSETS_PROMISE_002_08 length:' + albumList.length); - expect(albumList.length == 0).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getFileAssets 002_08 passed'); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 002 test end ------------------------- - - // ------------------------------ 003 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01 - * @tc.name : commitModify - * @tc.desc : Modify Album name to 'hello' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const albumId = album.albumId; - - console.info('ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName); - const newName = 'newhello'; - album.albumName = newName; - - await album.commitModify(); - const newAlbumList = await media.getAlbums(allTypefetchOp); - let passed = false; - for (let i = 0; i < newAlbumList.length; i++) { - const album = newAlbumList[i]; - if (album.albumId == albumId && album.albumName == newName) { - console.info('ALBUM_PROMISE Modify 003_01 passed'); - expect(true).assertTrue(); - done(); - passed = true; - } - } - expect(passed).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE Modify 003_01 failed, message = ' + error); - expect(false).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02 - * @tc.name : commitModify - * @tc.desc : Modify Album name '' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const albumId = album.albumId; - - console.info('ALBUM_PROMISE Modify 003_02 album.albumName(old) = ' + album.albumName); - const newName = ''; - album.albumName = newName; - - await album.commitModify(); - const newAlbumList = await media.getAlbums(allTypefetchOp); - let changed = false; - for (let i = 0; i < newAlbumList.length; i++) { - const album = newAlbumList[i]; - if (album.albumId == albumId && album.albumName == newName) { - console.info('ALBUM_PROMISE Modify 003_02 failed'); - expect(false).assertTrue(); - done(); - changed = true; - } - } - expect(!changed).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE Modify 003_02 passed'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04 - * @tc.name : commitModify - * @tc.desc : Modify Album name 'i123456...119' - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const albumId = album.albumId; - - console.info('ALBUM_PROMISE Modify 003_04 album.albumName(old) = ' + album.albumName); - let newName = true; - for (var i = 0; i < 1200; i++) { - newName += 'i'; - } - album.albumName = newName; - - await album.commitModify(); - const newAlbumList = await media.getAlbums(allTypefetchOp); - let changed = false; - for (let i = 0; i < newAlbumList.length; i++) { - const album = newAlbumList[i]; - if (album.albumId == albumId && album.albumName == newName) { - console.info('ALBUM_PROMISE Modify 003_04 failed'); - expect(false).assertTrue(); - done(); - changed = true; - } - } - expect(!changed).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE Modify 003_04 passed'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05 - * @tc.name : commitModify - * @tc.desc : Modify Album name true - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const albumId = album.albumId; - - console.info('ALBUM_PROMISE Modify 003_05 album.albumName(old) = ' + album.albumName); - const newName = true; - album.albumName = newName; - - await album.commitModify(); - const newAlbumList = await media.getAlbums(allTypefetchOp); - let changed = false; - for (let i = 0; i < newAlbumList.length; i++) { - const album = newAlbumList[i]; - if (album.albumId == albumId && album.albumName == newName) { - console.info('ALBUM_PROMISE Modify 003_05 failed'); - expect(false).assertTrue(); - done(); - changed = true; - } - } - expect(!changed).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE Modify 003_05 passed'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06 - * @tc.name : commitModify - * @tc.desc : Modify Album name false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const albumId = album.albumId; - - console.info('ALBUM_PROMISE Modify 003_06 album.albumName(old) = ' + album.albumName); - const newName = false; - album.albumName = newName; - - await album.commitModify(); - const newAlbumList = await media.getAlbums(allTypefetchOp); - let changed = false; - for (let i = 0; i < newAlbumList.length; i++) { - const album = newAlbumList[i]; - if (album.albumId == albumId && album.albumName == newName) { - console.info('ALBUM_PROMISE Modify 003_06 failed'); - expect(false).assertTrue(); - done(); - changed = true; - } - } - expect(!changed).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE Modify 003_06 passed'); - expect(true).assertTrue(); - } - done(); - }); - // ------------------------------ 003 test end ------------------------- - - // ------------------------------ 004 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01 - * @tc.name : album.coverUri - * @tc.desc : check album.coverUri - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - const fetchFileResult = await album.getFileAssets(allTypefetchOp); - const asset = await fetchFileResult.getFirstObject(); - expect(asset.uri == album.coverUri).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 004_01 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 004 test end ------------------------- - - // ------------------------------ 006 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01 - * @tc.name : commitModify - * @tc.desc : Modify Album albumUri - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - album.albumUri = 'testalbumUri'; - await album.commitModify(); - console.info('ALBUM_PROMISE Modify 006_01 failed'); - expect(false).assertTrue(); - } catch (error) { - console.info('ALBUM_PROMISE Modify 006_01 passed'); - expect(true).assertTrue(); - } - done(); - }); - - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02 - * @tc.name : commitModify - * @tc.desc : Modify Album name false - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - const album = albumList[0]; - album.coverUri = 'testcoverUri'; - await album.commitModify(); - console.info('ALBUM_PROMISE Modify 006_02 failed'); - expect(false).assertTrue(); - } catch (error) { - console.info('ALBUM_PROMISE Modify 006_02 passed'); - expect(true).assertTrue(); - } - done(); - }); - // ------------------------------ 006 test end ------------------------- - - // ------------------------------ 005 test start ------------------------- - /** - * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01 - * @tc.name : deleteAsset - * @tc.desc : delete album - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - - it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01', 0, async function (done) { - try { - const albumList = await media.getAlbums(allTypefetchOp); - - const album = albumList[0]; - let fetchFileResult = await album.getFileAssets(allTypefetchOp); - - let datas = await fetchFileResult.getAllObject(); - - for (let j = 0; j < datas.length; j++) { - const asset = datas[j]; - await media.deleteAsset(asset.uri); - } - - const albumId = album.albumId; - const newAlbumList = await media.getAlbums(allTypefetchOp); - - for (let i = 0; i < newAlbumList.length; i++) { - const album = newAlbumList[i]; - if (album.albumId == albumId) { - console.info('ALBUM_PROMISE getAlbum 005_01 failed'); - expect(false).assertTrue(); - done(); - } - } - console.info('ALBUM_PROMISE getAlbum 005_01 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info('ALBUM_PROMISE getAlbum 005_01 failed, message = ' + error); - expect(false).assertTrue(); - done(); - } - }); - // ------------------------------ 005 test end ------------------------- -}); +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +let fileKeyObj = mediaLibrary.FileKey; +let imageType = mediaLibrary.MediaType.IMAGE; +let videoType = mediaLibrary.MediaType.VIDEO; +let audioType = mediaLibrary.MediaType.AUDIO; + +let allTypefetchOp = { + selections: '', + selectionArgs: [], +}; +let albumCoverUrifetchOp = { + selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.ALBUM_NAME + '= ?', + selectionArgs: ['pictures/','weixin'], +}; +let imageAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], +}; +let videoAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], +}; +let audioAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], +}; +let imageAndVideoAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString(), videoType.toString()], +}; +let imageAndAudioAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString(), audioType.toString()], +}; +let videoAndAudioAlbumfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString(), audioType.toString()], +}; +function printAlbumMessage(testNum, album) { + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumId: ${album.albumId}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumName: ${album.albumName}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumUri: ${album.albumUri}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.dateModified: ${album.dateModified}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.count: ${album.count}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.relativePath: ${album.relativePath}`); + console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.coverUri: ${album.coverUri}`); +} +function checkAlbumAttr(done, album) { + if ( + album.albumId == undefined || + album.albumName == undefined || + album.albumUri == undefined || + album.count == undefined || + album.relativePath == undefined || + album.coverUri == undefined + ) { + console.info('ALBUM_PROMISE getAlbum 001_01 failed'); + expect(false).assertTrue(); + done(); + } +} + +describe('albumTestPromise.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_GETALBUM_PROMISE_001_01 + * @tc.name : getAlbums + * @tc.desc : Get Album by AllTypefetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + printAlbumMessage('001_01', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_PROMISE getAlbum 001_01 success'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getAlbum 001_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) { + try { + const albumList = await media.getAlbums(imageAlbumfetchOp); + const album = albumList[0]; + printAlbumMessage('001_02', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_PROMISE getAlbum 001_02 success'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getAlbum 001_02 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03 + * @tc.name : getAlbums + * @tc.desc : Get Album by videoAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03', 0, async function (done) { + try { + const albumList = await media.getAlbums(videoAlbumfetchOp); + const album = albumList[0]; + printAlbumMessage('001_03', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_PROMISE getAlbum 001_03 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getAlbum 001_03 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04 + * @tc.name : getAlbums + * @tc.desc : Get Album by audioAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04', 0, async function (done) { + try { + const albumList = await media.getAlbums(audioAlbumfetchOp); + const album = albumList[0]; + printAlbumMessage('001_04', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_PROMISE getAlbum 001_04 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getAlbum 001_04 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndVideoAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05', 0, async function (done) { + try { + const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp); + const album = albumList[0]; + + printAlbumMessage('001_05', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_PROMISE getAlbum 001_05 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getAlbum 001_05 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06 + * @tc.name : getAlbums + * @tc.desc : Get Album by imageAndAudioAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06', 0, async function (done) { + try { + const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp); + const album = albumList[0]; + printAlbumMessage('001_06', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_PROMISE getAlbum 001_06 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getAlbum 001_06 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07 + * @tc.name : getAlbums + * @tc.desc : Get Album by videoAndAudioAlbumfetchOp, print all album info, + * print all asset info, check asset info (mediaType, albumId, albumUri, albumName), + * check media types (imageType, audioType) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07', 0, async function (done) { + try { + const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp); + const album = albumList[0]; + printAlbumMessage('001_07', album); + checkAlbumAttr(done, album); + + console.info('ALBUM_PROMISE getAlbum 001_07 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getAlbum 001_07 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 001 test end ------------------------- + + // ------------------------------ 002 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01 + * @tc.name : getAlbums + * @tc.desc : Get Album by 666 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01', 0, async function (done) { + try { + await media.getAlbums(666); + expect(false).assertTrue(); + console.info('ALBUM_PROMISE getalbum 002_01 failed'); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getalbum 002_01 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02 + * @tc.name : getAlbums + * @tc.desc : Get Album by '666' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02', 0, async function (done) { + try { + await media.getAlbums('666'); + console.info('ALBUM_PROMISE getalbum 002_02 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getalbum 002_02 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03 + * @tc.name : getAlbums + * @tc.desc : Get Album by 0 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03', 0, async function (done) { + try { + await media.getAlbums(0); + console.info('ALBUM_PROMISE getalbum 002_03 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getalbum 002_03 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04 + * @tc.name : getAlbums + * @tc.desc : Get Album by true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04', 0, async function (done) { + try { + await media.getAlbums(true); + console.info('ALBUM_PROMISE getalbum 002_04 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getalbum 002_04 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05 + * @tc.name : getAlbums + * @tc.desc : Get Album by false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05', 0, async function (done) { + try { + await media.getAlbums(false); + console.info('ALBUM_PROMISE getalbum 002_05 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getalbum 002_05 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp3 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06', 0, async function (done) { + let fileHasArgsfetchOp3 = { + selections: fileKeyObj.MEDIA_TYPE + ' = ?', + selectionArgs: ['666'], + }; + try { + const albumList = await media.getAlbums(fileHasArgsfetchOp3); + console.info('GETALBUMASSETS_PROMISE_002_06 length:' + albumList.length); + expect(albumList.length == 0).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getFileAssets 002_06 passed'); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp4 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07', 0, async function (done) { + let fileHasArgsfetchOp4 = { + selections: '666' + '= ?', + selectionArgs: [videoType.toString()], + }; + try { + const albumList = await media.getAlbums(fileHasArgsfetchOp4); + console.info('GETALBUMASSETS_PROMISE_002_07 length:' + albumList.length); + expect(albumList.length == 0).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getFileAssets 002_07 passed'); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08 + * @tc.name : album.getFileAssets + * @tc.desc : Get Album Assets by fileHasArgsfetchOp5 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08', 0, async function (done) { + let fileHasArgsfetchOp5 = { + selections: '666' + '= ?', + selectionArgs: ['666'], + }; + + try { + const albumList = await media.getAlbums(fileHasArgsfetchOp5); + console.info('GETALBUMASSETS_PROMISE_002_08 length:' + albumList.length); + expect(albumList.length == 0).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getFileAssets 002_08 passed'); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 002 test end ------------------------- + + // ------------------------------ 003 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01 + * @tc.name : commitModify + * @tc.desc : Modify Album name to 'hello' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName); + const newName = 'newhello'; + album.albumName = newName; + + await album.commitModify(); + const newAlbumList = await media.getAlbums(allTypefetchOp); + let passed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_PROMISE Modify 003_01 passed'); + expect(true).assertTrue(); + done(); + passed = true; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE Modify 003_01 failed, message = ' + error); + expect(false).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02 + * @tc.name : commitModify + * @tc.desc : Modify Album name '' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_PROMISE Modify 003_02 album.albumName(old) = ' + album.albumName); + const newName = ''; + album.albumName = newName; + + await album.commitModify(); + const newAlbumList = await media.getAlbums(allTypefetchOp); + let changed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_PROMISE Modify 003_02 failed'); + expect(false).assertTrue(); + done(); + changed = true; + } + } + expect(!changed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE Modify 003_02 passed'); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04 + * @tc.name : commitModify + * @tc.desc : Modify Album name 'i123456...119' + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_PROMISE Modify 003_04 album.albumName(old) = ' + album.albumName); + let newName = true; + for (var i = 0; i < 1200; i++) { + newName += 'i'; + } + album.albumName = newName; + + await album.commitModify(); + const newAlbumList = await media.getAlbums(allTypefetchOp); + let changed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_PROMISE Modify 003_04 failed'); + expect(false).assertTrue(); + done(); + changed = true; + } + } + expect(!changed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE Modify 003_04 passed'); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05 + * @tc.name : commitModify + * @tc.desc : Modify Album name true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_PROMISE Modify 003_05 album.albumName(old) = ' + album.albumName); + const newName = true; + album.albumName = newName; + + await album.commitModify(); + const newAlbumList = await media.getAlbums(allTypefetchOp); + let changed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_PROMISE Modify 003_05 failed'); + expect(false).assertTrue(); + done(); + changed = true; + } + } + expect(!changed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE Modify 003_05 passed'); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06 + * @tc.name : commitModify + * @tc.desc : Modify Album name false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const albumId = album.albumId; + + console.info('ALBUM_PROMISE Modify 003_06 album.albumName(old) = ' + album.albumName); + const newName = false; + album.albumName = newName; + + await album.commitModify(); + const newAlbumList = await media.getAlbums(allTypefetchOp); + let changed = false; + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId && album.albumName == newName) { + console.info('ALBUM_PROMISE Modify 003_06 failed'); + expect(false).assertTrue(); + done(); + changed = true; + } + } + expect(!changed).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE Modify 003_06 passed'); + expect(true).assertTrue(); + } + done(); + }); + // ------------------------------ 003 test end ------------------------- + + // ------------------------------ 004 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01 + * @tc.name : album.coverUri + * @tc.desc : check album.coverUri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) { + try { + let coverUrifetchOp = { + selections: '', + selectionArgs: [], + order: 'date_added DESC LIMIT 0,1', + }; + const albumList = await media.getAlbums(albumCoverUrifetchOp); + const album = albumList[0]; + console.info('PROMISE getAlbum 004_01 album name = ' + album.albumName); + console.info('PROMISE getAlbum 004_01 album id = ' + album.albumId); + const fetchFileResult = await album.getFileAssets(coverUrifetchOp); + const asset = await fetchFileResult.getFirstObject(); + if (asset == undefined) { + expect(false).assertTrue(); + done(); + } else { + console.info('PROMISE getAlbum 004_01 coveruri = ' + album.coverUri); + console.info('PROMISE getAlbum 004_01 asset.uri = ' + asset.uri); + expect(asset.uri == album.coverUri).assertTrue(); + done(); + } + } catch (error) { + console.info('PROMISE getAlbum 004_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 004 test end ------------------------- + + // ------------------------------ 006 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01 + * @tc.name : commitModify + * @tc.desc : Modify Album albumUri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + album.albumUri = 'testalbumUri'; + await album.commitModify(); + console.info('ALBUM_PROMISE Modify 006_01 failed'); + expect(false).assertTrue(); + } catch (error) { + console.info('ALBUM_PROMISE Modify 006_01 passed'); + expect(true).assertTrue(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02 + * @tc.name : commitModify + * @tc.desc : Modify Album name false + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + album.coverUri = 'testcoverUri'; + await album.commitModify(); + console.info('ALBUM_PROMISE Modify 006_02 failed'); + expect(false).assertTrue(); + } catch (error) { + console.info('ALBUM_PROMISE Modify 006_02 passed'); + expect(true).assertTrue(); + } + done(); + }); + // ------------------------------ 006 test end ------------------------- + + // ------------------------------ 005 test start ------------------------- + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01 + * @tc.name : deleteAsset + * @tc.desc : delete album + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + + it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + + const album = albumList[0]; + let fetchFileResult = await album.getFileAssets(allTypefetchOp); + + let datas = await fetchFileResult.getAllObject(); + + for (let j = 0; j < datas.length; j++) { + const asset = datas[j]; + await media.deleteAsset(asset.uri); + } + + const albumId = album.albumId; + const newAlbumList = await media.getAlbums(allTypefetchOp); + + for (let i = 0; i < newAlbumList.length; i++) { + const album = newAlbumList[i]; + if (album.albumId == albumId) { + console.info('ALBUM_PROMISE getAlbum 005_01 failed'); + expect(false).assertTrue(); + done(); + } + } + console.info('ALBUM_PROMISE getAlbum 005_01 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info('ALBUM_PROMISE getAlbum 005_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 005 test end ------------------------- +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributedCallback.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributedCallback.test.js new file mode 100644 index 000000000..f3d215ec2 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributedCallback.test.js @@ -0,0 +1,91 @@ +/* + * 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('distributedCallback.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. Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + }) + + beforeEach(function() { + console.info( + 'Distributed. Callback MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.'); + }) + afterEach(function() { + console.info( + 'Distributed. Callback MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + }) + afterAll(function() { + console.info( + 'Distributed. Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + }) + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01 + * @tc.name : getActivePeers + * @tc.desc : getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01', 0, async function(done) { + try { + done(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01 begin'); + media.getActivePeers((error, peers) => { + expect(error == undefined).assertTrue(); + }); + done(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01 done'); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01 fail, message = ' + + error); + done(); + } + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_02 + * @tc.name : getAllPeers + * @tc.desc : getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_02', 0, async function(done) { + try { + done(); + media.getAllPeers((error, peers) => { + expect(error == undefined).assertTrue(); + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_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/distributedPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributedPromise.test.js new file mode 100644 index 000000000..91afc54c0 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/distributedPromise.test.js @@ -0,0 +1,85 @@ +/* + * 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('distributedPromise.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/favoriteTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/favoriteTestCallBack.test.js index 1c94e83fb..f92644d06 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,1375 +1,1500 @@ -/* - * 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 ------------------------ -}); +/* + * 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(); + } else { + 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(); + } + }); + }); + } + }); + }); + } else { + 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(); + } else { + 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(); + } + }); + }); + } + }); + }); + } else { + 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(); + } else { + 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(); + } + }); + }); + } + }); + }); + } else { + 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(); + } else { + 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(); + } + }); + }); + } + }); + }); + } else { + 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(); + } else { + 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(); + } + }); + }); + } + }); + }); + } else { + 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(); + } else { + 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(); + } + }); + }); + } + }); + }); + } else { + 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(); + } else { + 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(); + } + }); + }); + } + }); + }); + } else { + 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(); + } else { + 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(); + } + }); + }); + } + }); + }); + } else { + 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 a180a8414..06326bcb8 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('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 ------------------------ -}); +/* + * 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 index bb7bfde9e..e8ef00c71 100644 --- 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 @@ -16,420 +16,88 @@ import mediaLibrary from '@ohos.multimedia.medialibrary'; import featureAbility from '@ohos.ability.featureAbility'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'; let fileKeyObj = mediaLibrary.FileKey; -let fileType = mediaLibrary.MediaType.IMAGE; +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, - extendArgs: 'LIMIT 0,1', + 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, - extendArgs: 'LIMIT 0,2', + 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, - extendArgs: 'LIMIT 0,10', + 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, - extendArgs: 'LIMIT 0,100', + 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, - extendArgs: 'LIMIT 0,5', -}; + 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, - extendArgs: 'LIMIT 0,1', -}; + 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, - extendArgs: 'LIMIT 0,1', -}; + 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, - extendArgs: 'LIMIT 0,100', -}; + selections : fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs : [ 'camera/' ], + order : fileKeyObj.ID + " DESC LIMIT 0,100", + extendArgs : "", +} let getFileCountZeroOp = { - selections: - fileKeyObj.DISPLAY_NAME + - '= "The world has kissed my soul with its pain, asking for its return in songs."', + selections : fileKeyObj.DISPLAY_NAME + '=?', + selectionArgs : [ '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(); - } +let getFileOp = { + selections : fileKeyObj.DISPLAY_NAME + '= ? AND ' + fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs : [ '01.jpg', 'camera/' ], + order : fileKeyObj.ID + " DESC LIMIT 0,100", + extendArgs : "", } -describe('fetch.file.result.callback.test.js', async function () { +describe('fetchFileResultCallback.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 ------------------------- + beforeAll(function() {}); + beforeEach(function() {}); + afterEach(function() {}); + afterAll(function() {}); // ------------------------------ 004 test start ------------------------- /** @@ -440,22 +108,29 @@ describe('fetch.file.result.callback.test.js', async function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004', 0, async function(done) { try { - console.info('MediaLibraryTest : GETFIRSTOBJECT begin'); + console.info('MediaLibraryTest : FETCHRESULT getFirstObject begin'); let fetchFileResult = await media.getFileAssets(getFirstObjectOp); - fetchFileResult.getFirstObject(objectCheckCallback); - fetchFileResult.close(); - console.info('MediaLibraryTest : GETFIRSTOBJECT end'); - done(); + fetchFileResult.getFirstObject(async (error, firstObject) => { + if (firstObject == undefined) { + expect(false).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 004 fail'); + done(); + } else { + expect(firstObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getFirstObject 004 end'); + done(); + } + }); } catch (error) { - console.info( - 'MediaLibraryTest : FETCHRESULT getFirstObject 004 failed, message = ' + error - ); + console.info('MediaLibraryTest : FETCHRESULT getFirstObject 004 failed, message = ' + error); expect(false).assertTrue(); done(); } }); + // ------------------------------ 004 test end ------------------------- // ------------------------------ 005 test start ------------------------- @@ -467,19 +142,27 @@ describe('fetch.file.result.callback.test.js', async function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETNEXTOBJECT_CALLBACK_005', 0, async function(done) { try { - console.info('MediaLibraryTest : GETNEXTOBJECT begin'); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 005 begin'); let fetchFileResult = await media.getFileAssets(getFirstObjectOp); let firstObject = await fetchFileResult.getFirstObject(); - fetchFileResult.getNextObject(objectCheckCallback); - fetchFileResult.close(); - done(); - console.info('MediaLibraryTest : GETNEXTOBJECT end'); + expect(firstObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.getNextObject(async (error, nextObject) => { + if (nextObject == undefined) { + expect(false).assertTrue(); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 005 fail'); + } else { + expect(nextObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 005 end'); + done(); + } + }); } catch (error) { - console.info( - 'MediaLibraryTest : FETCHRESULT getNextObject 005 failed, message = ' + error - ); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 005 failed, message = ' + error); expect(false).assertTrue(); done(); } @@ -489,24 +172,31 @@ describe('fetch.file.result.callback.test.js', async function () { // ------------------------------ 006 test start ------------------------- /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006 - * @tc.name : getNextObject + * @tc.name : getLastObject * @tc.desc : Get FetchResult, get first object, get next object, check result * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_CALLBACK_006', 0, async function(done) { try { - console.info('MediaLibraryTest : GETLASTOBJECT begin'); + console.info('MediaLibraryTest : FETCHRESULT getLastObject begin'); let fetchFileResult = await media.getFileAssets(getFirstObjectOp); - fetchFileResult.getLastObject(objectCheckCallback); - fetchFileResult.close(); - done(); - console.info('MediaLibraryTest : GETLASTOBJECT end'); + fetchFileResult.getLastObject(async (error, lastObject) => { + if (lastObject == undefined) { + expect(false).assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 006 fail'); + done(); + } else { + expect(lastObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 006 end'); + done(); + } + }); } catch (error) { - console.info( - 'MediaLibraryTest : FETCHRESULT getLastObject 006 failed, message = ' + error - ); + console.info('MediaLibraryTest : FETCHRESULT getLastObject 006 failed, message = ' + error); expect(false).assertTrue(); done(); } @@ -522,27 +212,29 @@ describe('fetch.file.result.callback.test.js', async function () { * @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(); - } + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_01', 0, async function(done) { + try { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_01 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + fetchFileResult.getPositionObject(0, async (error, targetObject) => { + if (targetObject == undefined) { + expect(false).assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 007_01 fail'); + done(); + } else { + expect(targetObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_01 end'); + done(); + } + }); + } 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 @@ -552,28 +244,29 @@ describe('fetch.file.result.callback.test.js', async function () { * @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(); - } + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_02', 0, async function(done) { + try { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_02 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + fetchFileResult.getPositionObject(1, async (error, targetObject) => { + if (targetObject == undefined) { + expect(false).assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 007_02 fail'); + done(); + } else { + expect(targetObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_02 end'); + done(); + } + }); + } 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 @@ -583,29 +276,30 @@ describe('fetch.file.result.callback.test.js', async function () { * @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(); - } + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_03', 0, async function(done) { + try { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_03 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + const count = await fetchFileResult.getCount(); + fetchFileResult.getPositionObject(count - 1, async (error, targetObject) => { + if (targetObject == undefined) { + expect(false).assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 007_03 fail'); + done(); + } else { + expect(targetObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_03 end'); + done(); + } + }); + } 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 @@ -615,41 +309,37 @@ describe('fetch.file.result.callback.test.js', async function () { * @tc.type : Function * @tc.level : Level 0 */ - it( - 'SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04', - 0, - async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETPOSITIONOBJECT_CALLBACK_007_04', 0, async function(done) { + try { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_04 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + const count = await fetchFileResult.getCount(); 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); + fetchFileResult.getPositionObject(count + 100, async (error, targetObject) => { if (targetObject == undefined) { expect(true).assertTrue(); fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 007_04 fail'); + done(); + } else { + expect(false).assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_04 end'); 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(); + }); + } catch (err) { + expect(true).assertTrue(); + fetchFileResult.close(); done(); } + done(); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_04 failed, message = ' + error); + expect(false).assertTrue(); + done(); } - ); + }); // ------------------------------ 007 test end ------------------------- // ------------------------------ 008 test start ------------------------- @@ -661,19 +351,24 @@ describe('fetch.file.result.callback.test.js', async function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_01', 0, async function(done) { try { - nowDone = done; - console.info('MediaLibraryTest : GETALLOBJECT begin'); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_01 begin'); let fetchFileResult = await media.getFileAssets(getAllObjectLimitOneOp); - fetchFileResult.getAllObject(AllObjectCheckCallback); - console.info('MediaLibraryTest : GETALLOBJECT end'); - fetchFileResult.close(); - done(); + fetchFileResult.getAllObject((error, targetObjects) => { + if (targetObjects == undefined) { + expect(false).assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 008_01 fail'); + done(); + } else { + expect(0 < targetObjects.length <= 1).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 008_01 end'); + done(); + } + }); } catch (error) { - console.info( - 'MediaLibraryTest : FETCHRESULT getAllObject 008_01 failed, message = ' + error - ); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_01 failed, message = ' + error); expect(false).assertTrue(); done(); } @@ -687,19 +382,26 @@ describe('fetch.file.result.callback.test.js', async function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_02', 0, async function(done) { try { - nowDone = done; - console.info('MediaLibraryTest : GETALLOBJECT begin'); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_02 begin'); let fetchFileResult = await media.getFileAssets(getAllObjectLimitTwoOp); - fetchFileResult.getAllObject(AllObjectCheckCallback); - console.info('MediaLibraryTest : GETALLOBJECT end'); - fetchFileResult.close(); - done(); + fetchFileResult.getAllObject((error, targetObjects) => { + if (targetObjects == undefined) { + expect(false).assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 008_01 fail'); + done(); + } else { + expect(0 < targetObjects.length <= 2).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_02 targetObjects.length:' + + targetObjects.length); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_02 end'); + done(); + } + }); } catch (error) { - console.info( - 'MediaLibraryTest : FETCHRESULT getAllObject 008_02 failed, message = ' + error - ); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_02 failed, message = ' + error); expect(false).assertTrue(); done(); } @@ -713,21 +415,160 @@ describe('fetch.file.result.callback.test.js', async function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETALLOBJECT_CALLBACK_008_03', 0, async function(done) { try { - console.info('MediaLibraryTest : GETALLOBJECT begin'); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_03 begin'); let fetchFileResult = await media.getFileAssets(getAllObjectLimitOneHundredOp); - fetchFileResult.getAllObject(AllObjectCheckOneCallback); - fetchFileResult.close(); - done(); - console.info('MediaLibraryTest : GETALLOBJECT end'); + fetchFileResult.getAllObject((error, targetObjects) => { + if (targetObjects == undefined) { + expect(false).assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 008_03 fail'); + done(); + } else { + expect(0 < targetObjects.length <= 100).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_03 end'); + done(); + } + }); } catch (error) { - console.info( - 'MediaLibraryTest : FETCHRESULT getAllObject 008_03 failed, message = ' + error - ); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_03 failed, message = ' + error); expect(false).assertTrue(); done(); } }); // ------------------------------ 008 test end ------------------------- -}); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_CALLBACK_009_01 + * @tc.name : getFirstObject + * @tc.desc : Get FetchResult, get first object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_CALLBACK_009_01', 0, async function(done) { + try { + console.info('MediaLibraryTest : FETCHRESULT getAllObject 009_01 begin'); + let fetchFileResult = await media.getFileAssets(getFileOp); + fetchFileResult.getFirstObject(async (error, firstObject) => { + if (firstObject == undefined) { + expect(false).assertTrue(); + done(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 004 fail'); + } else { + expect(firstObject.id != undefined).assertTrue(); + if (firstObject.id == undefined) { + console.info('MediaLibraryTest :firstObject.id == undefined'); + } + + expect(firstObject.uri != undefined).assertTrue(); + if (firstObject.uri == undefined) { + console.info('MediaLibraryTest :firstObject.uri === undefined'); + } + + expect(firstObject.mimeType == 'image/*').assertTrue(); + if (firstObject.mimeType != 'image/*') { + console.info('MediaLibraryTest :firstObject.mimeType:' + firstObject.mimeType); + } + + expect(firstObject.mediaType == imageType).assertTrue(); + if (firstObject.mediaType != imageType) { + console.info('MediaLibraryTest :firstObject.mediaType:' + firstObject.mediaType); + } + + expect(firstObject.displayName == '01.jpg').assertTrue(); + if (firstObject.displayName != '01.jpg') { + console.info('MediaLibraryTest :firstObject.mediaType:' + firstObject.mediaType); + } + + expect(firstObject.title == '01').assertTrue(); + if (firstObject.title != '01') { + console.info('MediaLibraryTest :firstObject.title:' + firstObject.title); + } + + expect(firstObject.relativePath == 'camera/').assertTrue(); + if (firstObject.relativePath != 'camera/') { + console.info('MediaLibraryTest :firstObject.relativePath:' + firstObject.relativePath); + } + + expect(firstObject.parent != undefined).assertTrue(); + if (firstObject.parent == undefined) { + console.info('MediaLibraryTest :firstObject.parent == undefined'); + } + + expect(firstObject.size == 348113).assertTrue(); + if (firstObject.size != 348113) { + console.info('MediaLibraryTest :firstObject.size:' + firstObject.size); + } + + expect(firstObject.dateTaken == 0).assertTrue(); + if (firstObject.dateTaken != 0) { + console.info('MediaLibraryTest :firstObject.dateTaken:' + firstObject.dateTaken); + } + + expect(firstObject.artist == '').assertTrue(); + if (firstObject.artist != '') { + console.info('MediaLibraryTest :firstObject.artist:' + firstObject.artist); + } + + expect(firstObject.audioAlbum == '').assertTrue(); + if (firstObject.audioAlbum != '') { + console.info('MediaLibraryTest :firstObject.audioAlbum:' + firstObject.audioAlbum); + } + + expect(firstObject.width == 1279).assertTrue(); + if (firstObject.width != 1279) { + console.info('MediaLibraryTest :firstObject.width:' + firstObject.width); + } + + expect(firstObject.height == 1706).assertTrue(); + if (firstObject.height != 1706) { + console.info('MediaLibraryTest :firstObject.height:' + firstObject.height); + } + + expect(firstObject.orientation == 0).assertTrue(); + if (firstObject.orientation != 0) { + console.info('MediaLibraryTest :firstObject.orientation:' + firstObject.orientation); + } + + expect(firstObject.duration == 0).assertTrue(); + if (firstObject.duration != 0) { + console.info('MediaLibraryTest :firstObject.duration:' + firstObject.duration); + } + + expect(firstObject.albumId != undefined).assertTrue(); + if (firstObject.albumId == undefined) { + console.info('MediaLibraryTest :firstObject.albumId == undefined'); + } + + expect(firstObject.albumUri != undefined).assertTrue(); + if (firstObject.albumUri == undefined) { + console.info('MediaLibraryTest :firstObject.albumUri:' + firstObject.albumUri); + } + + expect(firstObject.albumName == 'camera').assertTrue(); + if (firstObject.albumName != 'camera') { + console.info('MediaLibraryTest :firstObject.albumName:' + firstObject.albumName); + } + + expect(firstObject.dateAdded != undefined).assertTrue(); + if (firstObject.dateAdded == undefined) { + console.info('MediaLibraryTest :firstObject.dateAdded:' + firstObject.dateAdded); + } + + expect(firstObject.albumName != undefined).assertTrue(); + if (firstObject.albumName == undefined) { + console.info('MediaLibraryTest :firstObject.albumName:' + firstObject.albumName); + } + console.info('MediaLibraryTest : FETCHRESULT getAllObject 009_01 end'); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getAllObject 009_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); +}); \ No newline at end of file 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 index bd53ff35e..0a4861b6c 100644 --- 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 @@ -1,822 +1,683 @@ -/* - * 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 ------------------------- - +/* + * 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.' ], +}; + +let getFileOp = { + selections : fileKeyObj.DISPLAY_NAME + '= ? AND ' + fileKeyObj.RELATIVE_PATH + '= ?', + selectionArgs : [ '01.jpg', 'camera/' ], + order : fileKeyObj.ID + " DESC LIMIT 0,100", + extendArgs : "", +} + +describe('fetchFileResultPromise.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 : FETCHRESULT getCount 001_01 begin'); + let fetchFileResult = await media.getFileAssets(getFileCountOneOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : FETCHRESULT getCount 001_01 count:' + fetchCount); + expect(fetchCount == 1).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getCount 001_01 end'); + await 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 : FETCHRESULT getCount 001_02 begin'); + let fetchFileResult = await media.getFileAssets(getFileCountTwoOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : FETCHRESULT getCount 001_02 count:' + fetchCount); + expect(fetchCount == 2).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getCount 001_02 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 :FETCHRESULT getCount 001_03 begin'); + let fetchFileResult = await media.getFileAssets(getFileCountOneHundredOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : FETCHRESULT getCount 001_03:' + fetchCount); + expect(fetchCount > 0).assertTrue(); + expect(fetchCount <= 100).assertTrue(); + console.info('MediaLibraryTest :FETCHRESULT getCount 001_03 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 : FETCHRESULT getCount 001_04 begin'); + let fetchFileResult = await media.getFileAssets(getFileCountZeroOp); + const fetchCount = await fetchFileResult.getCount(); + console.info('MediaLibraryTest : FETCHRESULT getCount 001_04 count:' + fetchCount); + expect(fetchCount == 0).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getCount 001_04 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 : FETCHRESULT isAfterLast 002 isLast'); + var result = fetchFileResult.isAfterLast(); + console.info('MediaLibraryTest : FETCHRESULT isAfterLast 002 isAfterLast:' + result); + expect(true).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT isAfterLast 002 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 : FETCHRESULT close 003 begin'); + let fetchFileResult = await media.getFileAssets(getFileCountTenOp); + fetchFileResult.close(); + try { + fetchFileResult.getCount(); + console.info('MediaLibraryTest : FETCHRESULT close 003 failed'); + expect(false).assertTrue(); + let fileAsset = await fetchFileResult.getFirstObject(); + expect(false).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT close getFirstObject 003 failed'); + fileAsset = await fetchFileResult.getNextObject(); + expect(false).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT close getNextObject 003 failed'); + fileAsset = await fetchFileResult.getLastObject(); + expect(false).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT close getLastObject 003 failed'); + let targetObject = await fetchFileResult.getPositionObject(0); + expect(false).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT close getPositionObject 003 failed'); + s + done(); + } catch { + console.info('MediaLibraryTest : FETCHRESULT close 003 closed'); + expect(true).assertTrue(); + done(); + } + console.info('MediaLibraryTest : FETCHRESULT close 003 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 : FETCHRESULT getFirstObject begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let firstObject = await fetchFileResult.getFirstObject(); + expect(firstObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getFirstObject 004 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_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 : FETCHRESULT getNextObject 005 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let firstObject = await fetchFileResult.getFirstObject(); + expect(firstObject.relativePath == 'camera/').assertTrue(); + let nextObject = await fetchFileResult.getNextObject(); + expect(nextObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : FETCHRESULT getNextObject 005 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 : getLastObject + * @tc.desc : Get FetchResult, get first object, get next object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETLASTOBJECT_PROMISE_006', 0, async function(done) { + try { + console.info('MediaLibraryTest : FETCHRESULT getLastObject begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let lastObject = await fetchFileResult.getLastObject(); + expect(lastObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + console.info('MediaLibraryTest : FETCHRESULT getLastObject 006 end'); + done(); + } 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 : FETCHRESULT getPositionObject 007_01 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let targetObject = await fetchFileResult.getPositionObject(0); + expect(targetObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_01 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 : FETCHRESULT getPositionObject 007_02 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + let targetObject = await fetchFileResult.getPositionObject(1); + expect(targetObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_02 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 : FETCHRESULT getPositionObject 007_03 begin'); + let fetchFileResult = await media.getFileAssets(getFirstObjectOp); + const count = await fetchFileResult.getCount(); + let targetObject = await fetchFileResult.getPositionObject(count - 1); + expect(targetObject.relativePath == 'camera/').assertTrue(); + fetchFileResult.close(); + done(); + console.info('MediaLibraryTest : FETCHRESULT getPositionObject 007_03 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 : FETCHRESULT getPositionObject 007_04 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 : FETCHRESULT getPositionObject 007_04 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 : FETCHRESULT getAllObject 008_01 begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitOneOp); + var targetObjects = await fetchFileResult.getAllObject(); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_01 targetObjects.length:' + + targetObjects.length); + expect(targetObjects.length <= 1).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_01 end'); + done(); + } 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 : FETCHRESULT getAllObject 008_02 begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitTwoOp); + var targetObjects = await fetchFileResult.getAllObject(); + expect(targetObjects.length <= 2).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_02 targetObjects.length:' + + targetObjects.length); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_02 end'); + done(); + } catch (error) { + 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 : FETCHRESULT getAllObject 008_03 begin'); + let fetchFileResult = await media.getFileAssets(getAllObjectLimitOneHundredOp); + var targetObjects = await fetchFileResult.getAllObject(); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_03 targetObjects.length:' + + targetObjects.length); + expect(targetObjects.length <= 100).assertTrue(); + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_03 end'); + done(); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getAllObject 008_03 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + // ------------------------------ 008 test end ------------------------- + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_PROMISE_009_01 + * @tc.name : getFirstObject + * @tc.desc : Get FetchResult, get first object, check result + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_getFirstObject_PROMISE_009_01', 0, async function(done) { + try { + console.info('MediaLibraryTest : FETCHRESULT getAllObject 009_01 begin'); + let fetchFileResult = await media.getFileAssets(getFileOp); + let firstObject = await fetchFileResult.getFirstObject(); + expect(firstObject.id != undefined).assertTrue(); + if (firstObject.id == undefined) { + console.info('MediaLibraryTest :firstObject.id == undefined'); + } + + expect(firstObject.uri != undefined).assertTrue(); + if (firstObject.uri == undefined) { + console.info('MediaLibraryTest :firstObject.uri === undefined'); + } + + expect(firstObject.mimeType == 'image/*').assertTrue(); + if (firstObject.mimeType != 'image/*') { + console.info('MediaLibraryTest :firstObject.mimeType:' + firstObject.mimeType); + } + + expect(firstObject.mediaType == imageType).assertTrue(); + if (firstObject.mediaType != imageType) { + console.info('MediaLibraryTest :firstObject.mediaType:' + firstObject.mediaType); + } + + expect(firstObject.displayName == '01.jpg').assertTrue(); + if (firstObject.displayName != '01.jpg') { + console.info('MediaLibraryTest :firstObject.mediaType:' + firstObject.mediaType); + } + + expect(firstObject.title == '01').assertTrue(); + if (firstObject.title != '01') { + console.info('MediaLibraryTest :firstObject.title:' + firstObject.title); + } + + expect(firstObject.relativePath == 'camera/').assertTrue(); + if (firstObject.relativePath != 'camera/') { + console.info('MediaLibraryTest :firstObject.relativePath:' + firstObject.relativePath); + } + + expect(firstObject.parent != undefined).assertTrue(); + if (firstObject.parent == undefined) { + console.info('MediaLibraryTest :firstObject.parent == undefined'); + } + + expect(firstObject.size == 348113).assertTrue(); + if (firstObject.size != 348113) { + console.info('MediaLibraryTest :firstObject.size:' + firstObject.size); + } + + expect(firstObject.dateTaken == 0).assertTrue(); + if (firstObject.dateTaken != 0) { + console.info('MediaLibraryTest :firstObject.dateTaken:' + firstObject.dateTaken); + } + + expect(firstObject.artist == '').assertTrue(); + if (firstObject.artist != '') { + console.info('MediaLibraryTest :firstObject.artist:' + firstObject.artist); + } + + expect(firstObject.audioAlbum == '').assertTrue(); + if (firstObject.audioAlbum != '') { + console.info('MediaLibraryTest :firstObject.audioAlbum:' + firstObject.audioAlbum); + } + + expect(firstObject.width == 1279).assertTrue(); + if (firstObject.width != 1279) { + console.info('MediaLibraryTest :firstObject.width:' + firstObject.width); + } + + expect(firstObject.height == 1706).assertTrue(); + if (firstObject.height != 1706) { + console.info('MediaLibraryTest :firstObject.height:' + firstObject.height); + } + + expect(firstObject.orientation == 0).assertTrue(); + if (firstObject.orientation != 0) { + console.info('MediaLibraryTest :firstObject.orientation:' + firstObject.orientation); + } + + expect(firstObject.duration == 0).assertTrue(); + if (firstObject.duration != 0) { + console.info('MediaLibraryTest :firstObject.duration:' + firstObject.duration); + } + + expect(firstObject.albumId != undefined).assertTrue(); + if (firstObject.albumId == undefined) { + console.info('MediaLibraryTest :firstObject.albumId == undefined'); + } + + expect(firstObject.albumUri != undefined).assertTrue(); + if (firstObject.albumUri == undefined) { + console.info('MediaLibraryTest :firstObject.albumUri:' + firstObject.albumUri); + } + + expect(firstObject.albumName == 'camera').assertTrue(); + if (firstObject.albumName != 'camera') { + console.info('MediaLibraryTest :firstObject.albumName:' + firstObject.albumName); + } + + expect(firstObject.dateAdded != undefined).assertTrue(); + if (firstObject.dateAdded == undefined) { + console.info('MediaLibraryTest :firstObject.dateAdded:' + firstObject.dateAdded); + } + + expect(firstObject.albumName != undefined).assertTrue(); + if (firstObject.albumName == undefined) { + console.info('MediaLibraryTest :firstObject.albumName:' + firstObject.albumName); + } + console.info('MediaLibraryTest : FETCHRESULT getAllObject 009_01 end'); + done(); + } catch (error) { + console.info('MediaLibraryTest : FETCHRESULT getAllObject 009_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); }); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetCallBack2.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetCallBack2.test.js new file mode 100644 index 000000000..bbad2b491 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetCallBack2.test.js @@ -0,0 +1,440 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +function printAttr(asset) { + for (const key in asset) { + console.info(`${key}: asset[key]`); + } +} +function checkAttrs(done, asset, tNum) { + let passed = true; + for (const key in asset) { + if (asset[key] == undefined) { + passed = false; + break; + } + } + if (passed) { + console.info(`FileAsset checkAttrs ${tNum} passed`); + expect(true).assertTrue(); + done(); + } else { + console.info(`FileAsset checkAttrs ${tNum} failed`); + expect(false).assertTrue(); + done(); + } +} +describe('fileAssetCallBack2.test.js', async function () { + let fileKeyObj = mediaLibrary.FileKey; + + let imageType = mediaLibrary.MediaType.IMAGE; + let videoType = mediaLibrary.MediaType.VIDEO; + let audioType = mediaLibrary.MediaType.AUDIO; + let imagesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], + }; + + let videosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], + }; + let audiosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], + }; + + let allTypefetchOp = { + selections: '', + selectionArgs: [], + }; + const context = featureAbility.getContext(); + const media = mediaLibrary.getMediaLibrary(context); + beforeAll(function () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_001 + * @tc.name : commitModify + * @tc.desc : Modify displayName + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const newName = 'newName'; + asset.displayName = newName; + const id = asset.id; + asset.commitModify(async ()=>{ + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.displayName == newName) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + }); + + + } catch (error) { + console.info('FileAsset commitModify 001 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_002 + * @tc.name : commitModify + * @tc.desc : Modify title + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const newTitle = 'newTitle'; + asset.title = newTitle; + const id = asset.id; + asset.commitModify(async () => { + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.title == newTitle) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + }); + } catch (error) { + console.info('FileAsset commitModify 002 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_003 + * @tc.name : commitModify + * @tc.desc : Modify relativePath + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_003', 0, async function (done) { + try { + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + + const path2 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + let relativePath = asset.relativePath; + let newrelativePath = path1; + if (relativePath == path1) { + newrelativePath = path2; + } + + asset.relativePath = newrelativePath; + const id = asset.id; + asset.commitModify(async () => { + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.relativePath == newrelativePath) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + }); + } catch (error) { + console.info('FileAsset commitModify 003 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_004 + * @tc.name : commitModify + * @tc.desc : Modify orientation + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_004', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + let neworientation = 1; + if (asset.orientation == 1) { + neworientation = 0; + } + asset.orientation = neworientation; + const id = asset.id; + asset.commitModify(async () => { + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.orientation == neworientation) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + }); + } catch (error) { + console.info('FileAsset commitModify 004 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_005 + * @tc.name : commitModify + * @tc.desc : Modify uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_005', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const id = asset.id; + const newUri = 'newUri'; + + asset.uri = newUri; + + asset.commitModify(async (err) => { + if(err) { + expect(true).assertTrue(); + done(); + } else { + console.info('FileAsset commitModify 005 failed'); + expect(false).assertTrue(); + done(); + } + }); + + + } catch (error) { + console.info('FileAsset commitModify 005 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_006 + * @tc.name : commitModify + * @tc.desc : Modify mediaType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_callback_006', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const id = asset.id; + const newMediaType = 'newMediaType'; + + asset.mediaType = newMediaType; + + asset.commitModify(async (err) => { + if(err) { + expect(true).assertTrue(); + done(); + } else { + console.info('FileAsset commitModify 006 failed'); + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('FileAsset commitModify 006 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_isDirectory_callback_001 + * @tc.name : isDirectory + * @tc.desc : isDirectory asset + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_isDirectory_callback_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + asset.isDirectory((err, isDir) => { + if(isDir == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(!isDir).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('FileAsset isDirectory 001 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_001 + * @tc.name : attrs + * @tc.desc : imagesfetchOp attrs print and check + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_checkAttr_callback_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + fetchFileResult.getFirstObject((err, asset) => { + if(asset == undefined) { + expect(false).assertTrue(); + done(); + } else { + printAttr(asset); + checkAttrs(done, asset, '001'); + } + }); + } catch (error) { + console.info('FileAsset checkAttr 001 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_002 + * @tc.name : attrs + * @tc.desc : videosfetchOp attrs print and check + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_checkAttr_callback_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(videosfetchOp); + fetchFileResult.getFirstObject((err, asset) => { + if(asset == undefined) { + expect(false).assertTrue(); + done(); + } else { + printAttr(asset); + checkAttrs(done, asset, '002'); + } + }); + } catch (error) { + console.info('FileAsset checkAttr 002 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_003 + * @tc.name : attrs + * @tc.desc : audiosfetchOp attrs print and check + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_checkAttr_callback_003', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(audiosfetchOp); + fetchFileResult.getFirstObject((err, asset)=>{ + if(asset == undefined) { + expect(false).assertTrue(); + done(); + } else { + printAttr(asset); + checkAttrs(done, asset, '003'); + } + }); + } catch (error) { + console.info('FileAsset checkAttr 003 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_004 + * @tc.name : attrs + * @tc.desc : album attrs print and check + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_checkAttr_callback_004', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(allTypefetchOp); + fetchFileResult.getFirstObject((err, asset) => { + if(asset == undefined) { + expect(false).assertTrue(); + done(); + } else { + printAttr(asset); + checkAttrs(done, asset, '004'); + } + }); + + } catch (error) { + console.info('FileAsset checkAttr 003 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetPromise2.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetPromise2.test.js new file mode 100644 index 000000000..801817635 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetPromise2.test.js @@ -0,0 +1,398 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import mediaLibrary from '@ohos.multimedia.medialibrary'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +function printAttr(asset) { + for (const key in asset) { + console.info(`${key}: asset[key]`); + } +} +function checkAttrs(done, asset, tNum) { + let passed = true; + for (const key in asset) { + if (asset[key] == undefined) { + passed = false; + break; + } + } + if (passed) { + console.info(`FileAsset checkAttrs ${tNum} passed`); + expect(true).assertTrue(); + done(); + } else { + console.info(`FileAsset checkAttrs ${tNum} failed`); + expect(false).assertTrue(); + done(); + } +} +describe('fileAssetPromise2.test.js', async function () { + let fileKeyObj = mediaLibrary.FileKey; + + let imageType = mediaLibrary.MediaType.IMAGE; + let videoType = mediaLibrary.MediaType.VIDEO; + let audioType = mediaLibrary.MediaType.AUDIO; + let imagesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], + }; + + let videosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], + }; + let audiosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], + }; + + let allTypefetchOp = { + selections: '', + selectionArgs: [], + }; + const context = featureAbility.getContext(); + const media = mediaLibrary.getMediaLibrary(context); + beforeAll(function () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_001 + * @tc.name : commitModify + * @tc.desc : Modify displayName + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const newName = 'newName'; + asset.displayName = newName; + const id = asset.id; + await asset.commitModify(); + + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.displayName == newName) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 001 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_002 + * @tc.name : commitModify + * @tc.desc : Modify title + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const newTitle = 'newTitle'; + asset.title = newTitle; + const id = asset.id; + await asset.commitModify(); + + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.title == newTitle) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 002 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_003 + * @tc.name : commitModify + * @tc.desc : Modify relativePath + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_003', 0, async function (done) { + try { + const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + + const path2 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + let relativePath = asset.relativePath; + let newrelativePath = path1; + if (relativePath == path1) { + newrelativePath = path2; + } + + asset.relativePath = newrelativePath; + const id = asset.id; + await asset.commitModify(); + + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.relativePath == newrelativePath) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 003 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_004 + * @tc.name : commitModify + * @tc.desc : Modify orientation + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_004', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + let neworientation = 1; + if (asset.orientation == 1) { + neworientation = 0; + } + asset.orientation = neworientation; + const id = asset.id; + await asset.commitModify(); + + const fetchFileResult2 = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult2.getAllObject(); + let passed = false; + for (let i = 0; i < dataList.length; i++) { + const asset = dataList[i]; + if (asset.id == id && asset.orientation == neworientation) { + passed = true; + break; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 004 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_005 + * @tc.name : commitModify + * @tc.desc : Modify uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_005', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const id = asset.id; + const newUri = 'newUri'; + + asset.uri = newUri; + + await asset.commitModify(); + + console.info('FileAsset commitModify 005 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 005 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_006 + * @tc.name : commitModify + * @tc.desc : Modify mediaType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_commitModify_promise_006', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const id = asset.id; + const newMediaType = 'newMediaType'; + + asset.mediaType = newMediaType; + + await asset.commitModify(); + + console.info('FileAsset commitModify 006 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset commitModify 006 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_isDirectory_promise_001 + * @tc.name : isDirectory + * @tc.desc : isDirectory asset + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + const isDir = await asset.isDirectory(); + expect(!isDir).assertTrue(); + done(); + } catch (error) { + console.info('FileAsset isDirectory 001 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_001 + * @tc.name : attrs + * @tc.desc : imagesfetchOp attrs print and check + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_checkAttr_promise_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const asset = await fetchFileResult.getFirstObject(); + + printAttr(asset); + checkAttrs(done, asset, '001'); + } catch (error) { + console.info('FileAsset checkAttr 001 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_002 + * @tc.name : attrs + * @tc.desc : videosfetchOp attrs print and check + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_checkAttr_promise_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(videosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + + printAttr(asset); + checkAttrs(done, asset, '002'); + } catch (error) { + console.info('FileAsset checkAttr 002 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_003 + * @tc.name : attrs + * @tc.desc : audiosfetchOp attrs print and check + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_checkAttr_promise_003', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(audiosfetchOp); + const asset = await fetchFileResult.getFirstObject(); + + printAttr(asset); + checkAttrs(done, asset, '003'); + } catch (error) { + console.info('FileAsset checkAttr 003 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_004 + * @tc.name : attrs + * @tc.desc : album attrs print and check + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_FILEASSET_checkAttr_promise_004', 0, async function (done) { + try { + const albumList = await media.getAlbums(allTypefetchOp); + const album = albumList[0]; + const fetchFileResult = await album.getFileAssets(allTypefetchOp); + const asset = await fetchFileResult.getFirstObject(); + printAttr(asset); + checkAttrs(done, asset, '004'); + } catch (error) { + console.info('FileAsset checkAttr 003 failed, message = ' + error); + expect(false).assertTrue(); + done(); + } + }); +}); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetTestCallback.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetTestCallback.test.js new file mode 100644 index 000000000..30d841c2b --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetTestCallback.test.js @@ -0,0 +1,1143 @@ +/* + * 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('fileAssetTestCallback.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_CALLBACK_005_01 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + 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]; + asset.open('rw', async (error, fd) => { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 fd:' + + fd); + expect(fd > 0).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 res.bytesRead:' + + res.bytesRead); + expect(res.bytesRead > 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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 write:' + + write); + await asset.close(fd); + await asset1.close(fd1); + if (fd > 0 && res.bytesRead > 0 && write > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 success'); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 failed'); + done(); + } + } + }); + + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_01 error' + error); + await asset.close(fd); + await asset1.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 + * @tc.name : open('r') + * @tc.desc : open -r the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02', 0, async function(done) { + let asset; + let fd; + 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]; + asset.open('r', async (error, fd) => { + try { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + expect(fd > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 fd:' + + fd); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 res.bytesRead:' + + res.bytesRead); + let write = await fileio.write(fd, buf); + await asset.close(fd); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 error:' + + error); + expect(true).assertTrue(); + if (fd > 0) { + await asset.close(fd); + } + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_02 error:' + + error); + expect(false).assertTrue(); + if (fd > 0) { + await asset.close(fd); + } + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 + * @tc.name : open('w') + * @tc.desc : open -w the type of FILE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + 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]; + asset.open('w', async (error, fd) => { + try { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + expect(fd > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 fd:' + + fd); + fd1 = await asset1.open('r'); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd1, buf); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 read fd1 success'); + let write = await fileio.write(fd, buf); + expect(write > 0).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 write:' + + write); + let buf1 = new ArrayBuffer(4096); + let res1 = await fileio.read(fd, buf1); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 read fd'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 error:' + + error); + expect(true).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_03 error:' + + error); + expect(false).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + + //======================== FILE END ================================== + + //======================== ALBUM BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_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_CALLBACK_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]; + asset.open('rw', async (error, fd) => { + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_04 error:' + + error); + expect(true).assertTrue(); + if (fd > 0) { + asset.close(fd); + } + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_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_CALLBACK_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]; + asset.open('r', async (error, fd) => { + expect(false).assertTrue(); + done(); + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_05 error:' + + error); + expect(true).assertTrue(); + if (fd > 0) { + asset.close(fd); + } + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_06 + * @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_CALLBACK_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]; + asset.open('w', (error, fd) => { + expect(false).assertTrue(); + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_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_CALLBACK_005_07 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + 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]; + + asset.open('rw', async (error, fd) => { + if (fd == undefined) { + expect(false).assertTrue(); + done(); + } else { + 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_CALLBACK_005_07 success'); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07 failed'); + done(); + } + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_07 error' + error); + await asset.close(fd); + await asset1.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 + * @tc.name : open('r') + * @tc.desc : open -r the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08', 0, async function(done) { + let asset; + let fd; + 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]; + asset.open('r', async (error, fd) => { + try { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + expect(fd > 0).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 res.bytesRead:' + + res.bytesRead); + let write = await fileio.write(fd, buf); + await asset.close(fd); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 error:' + + error); + if (fd > 0) { + expect(true).assertTrue(); + } + await asset.close(fd); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_08 error:' + + error); + expect(false).assertTrue(); + await asset.close(fd); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 + * @tc.name : open('w') + * @tc.desc : open -w the type of IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.IMAGE; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 dataList.length:' + + dataList.length); + asset = dataList[0]; + asset1 = dataList[1]; + + asset.open('w', async (error, fd) => { + try { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + expect(fd > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 fd:' + + fd); + fd1 = await asset1.open('r'); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd1, buf); + let write = await fileio.write(fd, buf); + expect(write > 0).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 write:' + + write); + let buf1 = new ArrayBuffer(4096); + let res1 = await fileio.read(fd, buf1); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 read'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 error:' + + error); + expect(true).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_09 error:' + + error); + expect(false).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + + //======================== IMAGE END ================================== + + //======================== AUDIO BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + 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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 dataList.length:' + + dataList.length); + asset = dataList[0]; + asset.open('rw', async (error, fd) => { + if (fd == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(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_CALLBACK_005_10 success'); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 failed'); + done(); + } + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_10 error' + error); + await asset.close(fd); + await asset1.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 + * @tc.name : open('r') + * @tc.desc : open -r the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11', 0, async function(done) { + let asset; + let fd; + 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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 dataList.length:' + + dataList.length); + asset = dataList[0]; + asset.open('r', async (error, fd) => { + try { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + expect(fd > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 fd:' + + fd); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 res.bytesRead:' + + res.bytesRead); + expect(res.bytesRead > 0).assertTrue(); + let write = await fileio.write(fd, buf); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 write'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 error:' + + error); + expect(true).assertTrue(); + if (fd > 0) { + await asset.close(fd); + } + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_11 error:' + + error); + expect(false).assertTrue(); + if (fd > 0) { + await asset.close(fd); + } + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 + * @tc.name : open('w') + * @tc.desc : open -w the type of AUDIO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + 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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 dataList.length:' + + dataList.length); + asset = dataList[0]; + asset1 = dataList[1]; + + asset.open('w', async (error, fd) => { + try { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 fd:' + + fd); + expect(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); + expect(write > 0).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 write:' + + write); + let buf1 = new ArrayBuffer(4096); + let res1 = await fileio.read(fd, buf1); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 read'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 error:' + + error); + expect(true).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_12 error:' + + error); + expect(false).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + + //======================== AUDIO END ================================== + + //======================== VIDEO BEGIN ================================== + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 + * @tc.name : open('rw') + * @tc.desc : open -rw the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + 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]; + asset.open('rw', async (error, fd) => { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 fd:' + + fd); + expect(fd > 0).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 res.bytesRead :' + + res.bytesRead); + asset1 = dataList[1]; + fd1 = await asset1.open('r'); + let buf2 = new ArrayBuffer(4096); + let res2 = await fileio.read(fd1, buf2); + let write = await fileio.write(fd, buf2); + expect(write > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 write :' + + write); + + if (fd > 0 && res.bytesRead > 0 && write > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 success'); + done(); + } else { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 failed'); + done(); + } + } + }); + + await asset.close(fd); + await asset1.close(fd1); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_13 error' + error); + await asset.close(fd); + await asset1.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 + * @tc.name : open('r') + * @tc.desc : open -r the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14', 0, async function(done) { + let asset; + let fd; + 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]; + + asset.open('r', async (error, fd) => { + try { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + expect(fd > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 fd:' + + fd); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 res.bytesRead:' + + res.bytesRead); + let write = await fileio.write(fd, buf); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 write:' + + write); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 error:' + + error); + expect(true).assertTrue(); + await asset.close(fd); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_14 error:' + + error); + expect(false).assertTrue(); + if (fd > 0) { + await asset.close(fd); + } + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 + * @tc.name : open('w') + * @tc.desc : open -w the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.VIDEO; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 dataList.length:' + + dataList.length); + asset = dataList[0]; + asset1 = dataList[1]; + asset.open('w', async (error, fd) => { + try { + if (fd == undefined) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 fd == undefined'); + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 fd :' + + fd); + expect(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); + expect(write > 0).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 wreite:' + + write); + let buf1 = new ArrayBuffer(4096); + let res1 = await fileio.read(fd, buf1); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 read'); + done(); + } + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 error:' + + error); + expect(true).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_15 error:' + + error); + expect(false).assertTrue(); + await asset.close(fd); + await asset1.close(fd1); + done(); + } + }); + + //======================== VIDEO END ================================== + + //======================== CLOSE BEGIN ================================ + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 + * @tc.name : close + * @tc.desc : asset close the type of file + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31', 0, async function(done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.FILE; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + + asset.close(fd, async (error) => { + fd1 = await asset.open('r'); + await asset.close(fd1); + if (fd > 0 && fd1 > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 false'); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_31 error' + error); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 + * @tc.name : close + * @tc.desc : asset close the type of image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33', 0, async function(done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.IMAGE; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + + console.info('MediaLibraryTest : ==1 fd:' + fd); + asset.close(fd, async (error) => { + fd1 = await asset.open('r'); + console.info('MediaLibraryTest : ==2 fd2:' + fd1); + await asset.close(fd1); + if (fd > 0 && fd1 > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 false'); + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_33 error' + error); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 + * @tc.name : close + * @tc.desc : asset close the type of audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34', 0, async function(done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.AUDIO; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + + asset.close(fd, async (error) => { + fd1 = await asset.open('r'); + await asset.close(fd1); + if (fd > 0 && fd1 > 0) { + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 success'); + expect(true).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 false'); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_34 error' + error); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 + * @tc.name : close + * @tc.desc : asset close the type of video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35', 0, async function(done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.VIDEO; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 dataList.length:' + + dataList.length); + asset = dataList[0]; + fd = await asset.open('r'); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 fd' + fd); + expect(fd > 0).assertTrue(); + asset.close(fd, async (error) => { + try { + fd1 = await asset.open('r'); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 fd1' + + fd1); + expect(fd1 > 0).assertTrue(); + expect(error == undefined).assertTrue(); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 error == undefined'); + await asset.close(fd1); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 close fd1:' + + fd1); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 error' + + error); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK_005_35 error' + error); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + //======================== CLOSE BEGIN ================================ +}); \ 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 7f320b423..946a5e097 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,952 +1,874 @@ -/* - * 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 ================================ -}); +/* + * 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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 dataList.length:' + + dataList.length); + 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('w'); + 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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 dataList.length:' + + dataList.length); + asset = dataList[0]; + fd = await asset.open('rw'); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 fd:' + fd); + expect(fd > 0).assertTrue(); + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + expect(res.bytesRead > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 res.bytesRead:' + + res.bytesRead); + asset1 = dataList[1]; + fd1 = await asset1.open('r'); + let buf2 = new ArrayBuffer(4096); + let res2 = await fileio.read(fd1, buf2); + let write = await fileio.write(fd, buf2); + expect(write > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 write:' + write); + await asset.close(fd); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 close fd:' + fd); + await asset1.close(fd1); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 close fd1:' + + 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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 dataList.length:' + + dataList.length); + asset = dataList[0]; + fd = await asset.open('r'); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 fd:' + fd); + expect(fd > 0).assertTrue(); + + let buf = new ArrayBuffer(4096); + let res = await fileio.read(fd, buf); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 res.bytesRead:' + + res.bytesRead); + expect(res.bytesRead > 0).assertTrue(); + let write = await fileio.write(fd, buf); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 error:' + error); + expect(true).assertTrue(); + await asset.close(fd); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 close fd:' + fd); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 + * @tc.name : open('w') + * @tc.desc : open -w the type of VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15', 0, async function(done) { + let asset; + let asset1; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.VIDEO; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 dataList.length:' + + dataList.length); + asset = dataList[0]; + asset1 = dataList[1]; + + fd = await asset.open('w'); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 fd:' + fd); + expect(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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 dataList.length:' + + dataList.length); + asset = dataList[0]; + fd = await asset.open('r'); + expect(fd > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 fd:' + fd); + await asset.close(fd); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 close fd:' + fd); + fd1 = await asset.open('r'); + expect(fd1 > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 fd1:' + fd1); + await asset.close(fd1); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 close fd1:' + + fd1); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 error' + error); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 + * @tc.name : close + * @tc.desc : asset close the type of image + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33', 0, async function(done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.IMAGE; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 dataList.length:' + + dataList.length); + asset = dataList[0]; + fd = await asset.open('r'); + expect(fd > 0).assertTrue + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 fd:' + fd); + await asset.close(fd); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 clode fd:' + fd); + fd1 = await asset.open('r'); + expect(fd1 > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 fd1:' + fd1); + await asset.close(fd1); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 clode fd1:' + + fd1); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 error' + error); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 + * @tc.name : close + * @tc.desc : asset close the type of audio + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34', 0, async function(done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.AUDIO; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + let fetchFileResult = await media.getFileAssets(fetchOp); + const dataList = await fetchFileResult.getAllObject(); + asset = dataList[0]; + fd = await asset.open('r'); + await asset.close(fd); + fd1 = await asset.open('r'); + await asset.close(fd1); + 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(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 dataList.length:' + + dataList.length); + asset = dataList[0]; + fd = await asset.open('r'); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 fd:' + fd); + expect(fd > 0).assertTrue(); + await asset.close(fd); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 close fd:' + fd); + fd1 = await asset.open('r'); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 fd1:' + fd1); + expect(fd1 > 0).assertTrue(); + await asset.close(fd1); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 close fd1:' + + fd1); + done(); + } catch (error) { + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 error' + error); + await asset.close(fd); + await asset.close(fd1); + expect(false).assertTrue(); + done(); + } + }); + + //======================== CLOSE BEGIN ================================ +}); \ No newline at end of file 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 index 2938d5426..1a17483e0 100644 --- 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 @@ -16,123 +16,76 @@ import mediaLibrary from '@ohos.multimedia.medialibrary'; import featureAbility from '@ohos.ability.featureAbility' import fileio from '@ohos.fileio'; -import { - describe, - it, - expect -} from 'deccjsunit/index'; +import {describe, it, expect} from 'deccjsunit/index'; -describe('fileAsset.callback.test.js', async function () { +describe('fileAssetUriTestCallback.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"; + * @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 + * @tc.name : close + * @tc.desc : asset close the type of video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35', 0, async function(done) { let asset; let fd; let fd1; try { - let type = mediaLibrary.MediaType.VIDEO; + let type = mediaLibrary.MediaType.IMAGE; let fetchOp = { - uri: 'dataability://123456789/media/external/images/media/10', - networkId: '123456789', - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [type.toString()], + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + const fetchFileResult = await media.getFileAssets(fetchOp); + expect(fetchFileResult != undefined).assertTrue(); + let firstObject = await fetchFileResult.getFirstObject(); + const id = firstObject.id; + const uri = firstObject.uri; + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 uri:' + + uri); + const serachUri = 'dataability:///media/image/' + id; + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 serachUri:' + + serachUri); + + let serchfetchOp = { + uri:serachUri.toString(), + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString()], }; - 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); - } + + const result = await media.getFileAssets(serchfetchOp); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 getFileAssets by uri:' + + serachUri + ",result.getCount():" + result.getCount()); + asset = await result.getFirstObject(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 asset.uri:' + + asset.uri); + expect(asset.uri == serachUri).assertTrue(); + fd = await asset.open('r'); + expect(fd > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 fd:' + fd); + asset.close(fd, async (error) => { + fd1 = await asset.open('r'); + expect(fd1 > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 fd1:' + + fd1); + await asset.close(fd1); + done(); }); } catch (error) { - console.info(`MediaLibraryTest : ==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(); - } - }); + console.info( + `MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 error:${error}`); + expect(false).assertTrue(); + done(); } }); - //======================== CLOSE BEGIN ================================ - }); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetUriTestPromiese.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetUriTestPromiese.test.js new file mode 100644 index 000000000..ba4e6fe0e --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/fileAssetUriTestPromiese.test.js @@ -0,0 +1,88 @@ +/* + * 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('fileAssetUriTestPromise.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_URI_PROMISE_005_35 + * @tc.name : close + * @tc.desc : asset close the type of video + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35', 0, async function(done) { + let asset; + let fd; + let fd1; + try { + let type = mediaLibrary.MediaType.IMAGE; + let fetchOp = { + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + const fetchFileResult = await media.getFileAssets(fetchOp); + expect(fetchFileResult != undefined).assertTrue(); + let firstObject = await fetchFileResult.getFirstObject(); + const id = firstObject.id; + const uri = firstObject.uri; + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 uri:' + uri); + const serachUri = 'dataability:///media/image/' + id; + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 serachUri:' + + serachUri); + + let serchfetchOp = { + uri : serachUri.toString(), + selections : fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs : [ type.toString() ], + }; + + const result = await media.getFileAssets(serchfetchOp); + console.info( + 'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 getFileAssets by uri:' + + serachUri + ",result.getCount():" + result.getCount()); + asset = await result.getFirstObject(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 asset.uri:' + + asset.uri); + expect(asset.uri == serachUri).assertTrue(); + fd = await asset.open('r'); + expect(fd > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 fd:' + fd); + await asset.close(fd); + fd1 = await asset.open('r'); + expect(fd1 > 0).assertTrue(); + console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 fd1:' + fd1); + await asset.close(fd1); + done(); + } catch (error) { + console.info( + `MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 error:${error}`); + expect(false).assertTrue(); + done(); + } + }); + //======================== CLOSE BEGIN ================================ +}); \ 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 f47abdd47..67e1c8288 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 @@ -41,64 +41,39 @@ let filesfetchOp = { selectionArgs: [fileType.toString()], }; -function checkAssetAttr(done, attr, test_num, asset, checkType) { +function checkAssetAttr(done, attr, testNum, asset, checkType) { if (checkType && asset[attr] != checkType) { - console.info(`MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed`); + console.info(`ASSET_CALLBACK getFileAssets ${testNum} failed`); expect(false).assertTrue(); done(); } else if (asset[attr] == undefined) { - console.info(`MediaLibraryTest : ASSET_CALLBACK createAsset ${test_num} failed`); + console.info(`ASSET_CALLBACK getFileAssets ${testNum} failed`); expect(false).assertTrue(); done(); } } -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 () { +let path; +let presetAsset; +let displayName; +let id; +let mediaType; +let orientation = 0; +describe('fileTestCallBack.test.js', function () { var context = featureAbility.getContext(); - console.info('MediaLibraryTest : getMediaLibrary IN'); + console.info('getMediaLibrary IN'); var media = mediaLibrary.getMediaLibrary(context); - console.info('MediaLibraryTest : getMediaLibrary OUT'); - beforeAll(function () { }); - beforeEach(function () { }); - afterEach(function () { }); - afterAll(function () { }); - - 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); - } + 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 ---------------------------- @@ -111,432 +86,132 @@ describe('fileTestCallBack.test', function () { * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_01', 0, async function (done) { - const test_num = '001_01'; try { - 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); + path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + presetAsset = asset1; + media.createAsset( + imageType, + `${new Date().getTime()}.jpg`, + path, + async (err, creatAsset1) => { + if(creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + displayName = `${new Date().getTime()}.jpg`; + const asset2 = dataList[1]; + const creatAsset2 = await media.createAsset(imageType, displayName, path); + const fd2 = await asset2.open('r'); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd2, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset2.close(fd2); + id = creatAsset2.id; + mediaType = imageType; + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + } } - }); + ); } catch (error) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK createAsset 001_01 failed, message = ' + error); + expect(false).assertTrue(); + done(); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file displayName and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_02', 0, async function (done) { - const test_num = '001_02'; try { - 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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 001_02 failed, message = ' + error); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file relativePath and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_03', 0, async function (done) { - const test_num = '001_03'; - try { - 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) { - executeAtError(test_num, error, 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 { - 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) { - executeAtError(test_num, error, 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 { - 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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 001_03 failed, message = ' + error); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07 - * @tc.name : createAsset + * @tc.name : commitModify * @tc.desc : Access to the file dateModified and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_07', 0, async function (done) { - const test_num = '001_07'; try { - 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); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(async () => { + const id = asset.id; + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const newAssets = await media.getFileAssets(idOP); + const newdataList = await newAssets.getAllObject(); + const newAsset = newdataList[0]; + + if (asset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified) { + console.info('ASSET_CALLBACK getFileAssets 001_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_CALLBACK getFileAssets 001_07 failed'); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info('ASSET_CALLBACK getFileAssets 001_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_CALLBACK getFileAssets 001_07 failed'); + expect(false).assertTrue(); + done(); } }); } catch (error) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 001_07 failed, message = ' + error); } }); @@ -549,120 +224,14 @@ describe('fileTestCallBack.test', function () { * @tc.level : Level 0 */ 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_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_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_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_CREATEASSET_CALLBACK_001_10', 0, async function (done) { - const test_num = '001_10'; try { - 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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK createAsset 001_08 failed, message = ' + error); } }); @@ -675,157 +244,17 @@ describe('fileTestCallBack.test', function () { * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_001_11', 0, async function (done) { - const test_num = '001_11'; try { - 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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK createAsset 001_11 failed, message = ' + error); } }); - /** - * @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 { - 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) { - executeAtError(test_num, error, done); - } - }); // ------------------------------- image type end ----------------------------- // ------------------------------- video type start ---------------------------- @@ -838,468 +267,133 @@ describe('fileTestCallBack.test', function () { * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_01', 0, async function (done) { - const test_num = '002_01'; try { - 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); + path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + media.createAsset( + videoType, + `${new Date().getTime()}.mp4`, + path, + async (err, creatAsset1) => { + if(creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + displayName = `${new Date().getTime()}.mp4`; + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(videoType, displayName, path); + const fd2 = await asset2.open('r'); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd2, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset2.close(fd2); + id = creatAsset2.id; + mediaType = videoType; + + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + } } - }); + ); } catch (error) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK createAsset 002_01 failed' + error); + expect(false).assertTrue(); + done(); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file displayName and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_02', 0, async function (done) { - const test_num = '002_02'; try { - 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 idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); - 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(asset.displayName == displayName).assertTrue(); + done(); } catch (error) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 002_02 failed, message = ' + error); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file relativePath and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_03', 0, async function (done) { - const test_num = '002_03'; - try { - 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) { - executeAtError(test_num, error, 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 { - 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); + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); - 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(asset.relativePath == path).assertTrue(); + done(); } catch (error) { - executeAtError(test_num, error, 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 { - 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 002_03 failed, message = ' + error); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file dateModified and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_07', 0, async function (done) { - const test_num = '002_07'; try { - 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); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(async () => { + const id = asset.id; + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const newAssets = await media.getFileAssets(idOP); + const newdataList = await newAssets.getAllObject(); + const newAsset = newdataList[0]; + + if (asset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified) { + console.info('ASSET_CALLBACK getFileAssets 002_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_CALLBACK getFileAssets 002_07 failed'); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info('ASSET_CALLBACK getFileAssets 002_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_CALLBACK getFileAssets 002_07 failed'); + expect(false).assertTrue(); + done(); } }); - } catch (error) { - executeAtError(test_num, error, done); + } catch (error) { + console.info('ASSET_CALLBACK getFileAssets 002_07 failed, message = ' + error); } }); @@ -1312,120 +406,14 @@ describe('fileTestCallBack.test', function () { * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_08', 0, async function (done) { - const test_num = '002_08'; try { - 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); - } - }); + 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) { - executeAtError(test_num, error, done); - } - }); - - /** - * @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('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_09', 0, async function (done) { - const test_num = '002_09'; - try { - 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) { - executeAtError(test_num, error, done); - } - }); - - /** - * @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_CREATEASSET_CALLBACK_002_10', 0, async function (done) { - const test_num = '002_10'; - try { - 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK createAsset 002_08 failed, message = ' + error); } }); @@ -1438,205 +426,14 @@ describe('fileTestCallBack.test', function () { * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_002_11', 0, async function (done) { - const test_num = '002_11'; - try { - 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); - } - }); - } catch (error) { - executeAtError(test_num, error, 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.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); - } - }); - } catch (error) { - executeAtError(test_num, error, 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.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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK createAsset 002_11 failed, message = ' + error); } }); // ------------------------------- video type end ----------------------------- @@ -1651,468 +448,127 @@ describe('fileTestCallBack.test', function () { * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_01', 0, async function (done) { - const test_num = '003_01'; try { - 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); - } - }); - } catch (error) { - executeAtError(test_num, error, done); + path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + media.createAsset( + audioType, + `${new Date().getTime()}.mp3`, + path, + async (err, creatAsset1) => { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + displayName = `${new Date().getTime()}.mp3`; + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(audioType, displayName, path); + const fd2 = await asset2.open('r'); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd2, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset2.close(fd2); + id = creatAsset2.id; + mediaType = audioType; + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + } + ); + + } catch (error) { + console.info('ASSET_CALLBACK createAsset 003_01 failed'); + expect(false).assertTrue(); + done(); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file name and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_02', 0, async function (done) { - const test_num = '003_02'; try { - media.getFileAssets(audiosfetchOp, (error, fileAssets) => { - try { - fileAssets.getAllObject((error, dataList) => { - try { - const firstAsset = dataList[0]; - checkAssetAttr(done, 'displayName', test_num, firstAsset); + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const fileAssets = await media.getFileAssets(idOP); + const asset = await fileAssets.getFirstObject(); + expect(asset.displayName == displayName).assertTrue(); - 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); - } - }); + done(); } catch (error) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 003_02 failed, message = ' + error); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file relativePath and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_03', 0, async function (done) { - const test_num = '003_03'; - try { - 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); - } - }); - } catch (error) { - executeAtError(test_num, error, 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.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); - } - }); - - /** - * @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.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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 003_03 failed, message = ' + error); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file dateModified and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_07', 0, async function (done) { - const test_num = '003_07'; try { - 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); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(async () => { + const id = asset.id; + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const newAssets = await media.getFileAssets(idOP); + const newdataList = await newAssets.getAllObject(); + const newAsset = newdataList[0]; + + if (asset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified) { + console.info('ASSET_CALLBACK getFileAssets 003_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_CALLBACK getFileAssets 003_07 failed'); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info('ASSET_CALLBACK getFileAssets 003_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_CALLBACK getFileAssets 003_07 failed'); + expect(false).assertTrue(); + done(); } }); } catch (error) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 003_07 failed, message = ' + error); } }); @@ -2125,290 +581,20 @@ describe('fileTestCallBack.test', function () { * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_003_08', 0, async function (done) { - const test_num = '003_08'; - try { - 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); - } - }); - } catch (error) { - executeAtError(test_num, error, done); - } - }); - - /** - * @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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK createAsset 003_08 failed, message = ' + error); } }); - /** - * @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); - } - }); - - /** - * @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); - } - }); - - /** - * @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 ----------------------------- - // ------------------------------- file type start ---------------------------- + // ------------------------------ file type start ---------------------------- /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_01 * @tc.name : createAsset @@ -2418,467 +604,125 @@ describe('fileTestCallBack.test', 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); + path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + media.createAsset( + fileType, + `${new Date().getTime()}.bat`, + path, + async (err, creatAsset1) => { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + displayName = `${new Date().getTime()}.bat`; + const asset2 = dataList[0]; + const creatAsset2 = await media.createAsset(fileType, displayName, path); + const fd2 = await asset2.open('r'); + const creatAssetFd2 = await creatAsset2.open('rw'); + await copyFile(fd2, creatAssetFd2); + await creatAsset2.close(creatAssetFd2); + await asset2.close(fd2); + id = creatAsset2.id; + mediaType = fileType; + expect(creatAsset1.id != creatAsset2.id).assertTrue(); + done(); + } + ); + } catch (error) { + console.info('ASSET_CALLBACK createAsset 004_01 failed' + error); + expect(false).assertTrue(); + done(); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file name and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_02', 0, async function (done) { - 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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 004_02 failed, message = ' + error); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file relativePath and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_03', 0, async function (done) { - 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); - } - }); + 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) { - executeAtError(test_num, error, 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); - } - }); - - /** - * @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); + console.info('ASSET_CALLBACK getFileAssets 004_03 failed, message = ' + error); } }); /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07 - * @tc.name : createAsset + * @tc.name : getFileAssets * @tc.desc : Access to the file dateModified and validation is not undefined * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_CALLBACK_004_07', 0, async function (done) { - 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); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset = dataList[0]; + asset.title = `title_${new Date().getTime()}`; + asset.commitModify(async ()=> { + const id = asset.id; + const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] }; + const newAssets = await media.getFileAssets(idOP); + const newdataList = await newAssets.getAllObject(); + const newAsset = newdataList[0]; + + if (asset.dateModified != undefined) { + if (newAsset.dateModified != asset.dateModified) { + console.info('ASSET_CALLBACK getFileAssets 004_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_CALLBACK getFileAssets 004_07 failed'); + expect(false).assertTrue(); + done(); + } + } else if (newAsset.dateModified != undefined) { + console.info('ASSET_CALLBACK getFileAssets 004_07 passed'); + expect(true).assertTrue(); + done(); + } else { + console.info('ASSET_CALLBACK getFileAssets 004_07 failed'); + expect(false).assertTrue(); + done(); } }); } catch (error) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK getFileAssets 004_07 failed, message = ' + error); } }); @@ -2891,164 +735,16 @@ describe('fileTestCallBack.test', 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); - } - }); + 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) { - executeAtError(test_num, error, done); + console.info('ASSET_CALLBACK createAsset 004_08 failed, message = ' + error); } }); - /** - * @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 871849292..8a0ce1ceb 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,728 +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/filekeyTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/filekeyTestCallBack.test.js new file mode 100644 index 000000000..5a30d21e2 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/filekeyTestCallBack.test.js @@ -0,0 +1,290 @@ +/* + * 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 { + media.getFileAssets(Op, async(err, fetchFileResult) => { + if (fetchFileResult == undefined) { + expect(false).assertTrue(); + done(); + } else { + try { + const fetchCount = await fetchFileResult.getCount(); + console.log('getFileAssetsBy ' + type + 'fetchCount = ' + fetchCount); + expect(fetchCount > 0).assertTrue(); + done(); + } catch (error) { + console.log('getFileAssetsBy ' + type + ' failed error message = ' + error); + } + } + }); + } catch (error) { + expect(false).assertTrue(); + done(); + } +} +function printAttr (done, asset, tNum) { + +} +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/filekeyTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/filekeyTestPromise.test.js index b4e8b5e52..7311b237c 100644 --- 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 @@ -79,11 +79,7 @@ async function getFileAssetsBy(done, type) { try { let fetchFileResult = await media.getFileAssets(Op); const fetchCount = fetchFileResult.getCount(); - if(type == 'parent') { - expect(fetchCount == 0).assertTrue(); - } else{ - expect(fetchCount > 0).assertTrue(); - } + expect(fetchCount > 0).assertTrue(); done(); } catch (error) { expect(false).assertTrue(); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersDeviceTestCallback.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersDeviceTestCallback.test.js new file mode 100644 index 000000000..47138105b --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersDeviceTestCallback.test.js @@ -0,0 +1,241 @@ +/* + * 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('getAllPeersDeviceTestCallback.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_CALLBACK_001_02 begin'); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer device information TYPE_UNKNOWN + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02', 0, async function(done) { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(allPeerList[1].DeviceType.TYPE_UNKNOWN).assertEqual(0); + done(); + } + }); + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer device information TYPE_LAPTOP + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_01', 0, async function(done) { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(allPeerList[1].DeviceType.TYPE_LAPTOP).assertEqual(1); + done(); + } + }); + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_02 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer device information TYPE_PHONE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_02', 0, async function(done) { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(allPeerList[1].DeviceType.TYPE_PHONE).assertEqual(2); + done(); + } + }); + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_03 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer device information TYPE_TABLET + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_03', 0, async function(done) { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(allPeerList[1].DeviceType.TYPE_TABLET).assertEqual(3); + done(); + } + }); + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_04 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer device information TYPE_WATCH + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_04', 0, async function(done) { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(allPeerList[1].DeviceType.TYPE_WATCH).assertEqual(4); + done(); + } + }); + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_05 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer device information TYPE_CAR + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_05', 0, async function(done) { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(allPeerList[1].DeviceType.TYPE_CAR).assertEqual(5); + done(); + } + }); + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_06 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer device information TYPE_TV + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_CALLBACK_001_02_06', 0, async function(done) { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(allPeerList[1].DeviceType.TYPE_TV).assertEqual(6); + done(); + } + }); + done(); + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_06 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer networkId + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_NETWORKID_CALLBACK_001_02', 0, async function(done) { + try { + done(); + media.getActivePeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + networkId = allPeerList[0].networkId; + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_01 peer.networkId = ' + + networkId); + done(); + } + }); + done(); + } catch (error) { + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_06 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer isOnline + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_NETWORKID_ISONLINE_CALLBACK_001_02', 0, async function(done) { + try { + done(); + media.getActivePeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + isOnline = allPeerList[0].isOnline; + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_01 peer.isOnline = ' + isOnline); + done(); + } + }); + done(); + } catch (error) { + done(); + } + }); +}); \ 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 index 97b9ba37c..bc8fe5380 100644 --- 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 @@ -16,30 +16,20 @@ 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 () { +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'; + +describe('getAllPeersDeviceTestPromise.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 () {}); - + beforeAll(function() {}); + beforeEach(function() {}); + afterEach(function() {}); + afterAll(function() {}); console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02 begin'); - /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02 * @tc.name : getActivePeers @@ -48,7 +38,7 @@ describe('file.promise.test.js', function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02', 0, async function (done) { + 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); @@ -63,7 +53,7 @@ describe('file.promise.test.js', function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_01', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_01', 0, async function(done) { done(); let allPeerList = await media.getAllPeers(); expect(allPeerList[1].DeviceType.TYPE_LAPTOP).assertEqual(1); @@ -78,7 +68,7 @@ describe('file.promise.test.js', function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_02', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_02', 0, async function(done) { done(); let allPeerList = await media.getAllPeers(); expect(allPeerList[1].DeviceType.TYPE_PHONE).assertEqual(2); @@ -94,14 +84,14 @@ describe('file.promise.test.js', function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_03', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_03', 0, async function(done) { done(); let allPeerList = await media.getAllPeers(); expect(allPeerList[1].DeviceType.TYPE_TABLET).assertEqual(3); done(); }); - + /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_04 * @tc.name : getActivePeers @@ -110,14 +100,14 @@ describe('file.promise.test.js', function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_04', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_04', 0, async function(done) { done(); let allPeerList = await media.getAllPeers(); expect(allPeerList[1].DeviceType.TYPE_WATCH).assertEqual(4); done(); }); - + /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_05 * @tc.name : getActivePeers @@ -126,14 +116,14 @@ describe('file.promise.test.js', function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_05', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_05', 0, async function(done) { done(); let allPeerList = await media.getAllPeers(); expect(allPeerList[1].DeviceType.TYPE_CAR).assertEqual(5); done(); }); - + /** * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_06 * @tc.name : getActivePeers @@ -142,13 +132,48 @@ describe('file.promise.test.js', function () { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_06', 0, async function (done) { + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_06', 0, async function(done) { done(); let allPeerList = await media.getAllPeers(); expect(allPeerList[1].DeviceType.TYPE_TV).assertEqual(6); + done(); + }); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_06 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer networkId + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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(); + } + }); - done(); + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_DEVICETYPE_PROMISE_001_02_06 + * @tc.name : getActivePeers + * @tc.desc : Get Active Peer isOnline + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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(); + } }); - }); \ No newline at end of file diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersTestCallback.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersTestCallback.test.js new file mode 100644 index 000000000..be6769596 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersTestCallback.test.js @@ -0,0 +1,307 @@ +/* + * 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('getAllPeersTestCallback.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() {}); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_01 + * @tc.name : getAllPeers + * @tc.desc : getAllPeers device + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_01', 0, async function(done) { + try { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_01 peer.deviceName = ' + + peer.deviceName); + done(); + } + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_01 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_02 + * @tc.name : getAllPeers + * @tc.desc : get the first peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_02', 0, async function(done) { + try { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + peer = allPeerList[0]; + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_02 peer.deviceName = ' + + peer.deviceName); + done(); + } + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_02 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_03 + * @tc.name : getAllPeers + * @tc.desc : get the second peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_03', 0, async function(done) { + try { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + peer = allPeerList[1]; + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_03 peer.deviceName = ' + + peer.deviceName); + done(); + } + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_03 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_04 + * @tc.name : getAllPeers + * @tc.desc : get the third peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_04', 0, async function(done) { + try { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + peer = allPeerList[2]; + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_04 peer.deviceName = ' + + peer.deviceName); + done(); + } + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_04 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_04 + * @tc.name : getAllPeers + * @tc.desc : get the forth peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_05', 0, async function(done) { + try { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + peer = allPeerList[3]; + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_05 peer.deviceName = ' + + peer.deviceName); + done(); + } + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_05 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_04 + * @tc.name : getAllPeers + * @tc.desc : get the fifth peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_CALLBACK_001_06', 0, async function(done) { + try { + done(); + media.getAllPeers((error, allPeerList) => { + if (allPeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + peer = allPeerList[4]; + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_06 peer.deviceName = ' + + peer.deviceName); + done(); + } + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : ALL_PEER_CALLBACK getAllPeers 001_06 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_CALLBACK_001_01 + * @tc.name : getActivePeers + * @tc.desc : get the first peers by getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_CALLBACK_001_01', 0, async function(done) { + try { + done(); + media.getActivePeers((error, activePeerList) => { + if (activePeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + activePeer = activePeerList[0]; + console.info( + 'MediaLibraryTest : ACTIVE_PEER_CALLBACK getActivePeers 001_01 activePeer.deviceName = ' + + activePeer.deviceName); + done(); + } + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : ACTIVE_PEER_CALLBACK getActivePeers 001_01 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_CALLBACK_001_02 + * @tc.name : getActivePeers + * @tc.desc : get the second peers by getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_CALLBACK_001_02', 0, async function(done) { + try { + done(); + media.getActivePeers((error, activePeerList) => { + if (activePeerList == undefined) { + expect(false).assertTrue(); + done(); + } else { + activePeer = activePeerList[1]; + console.info( + 'MediaLibraryTest : ACTIVE_PEER_CALLBACK getActivePeers 001_02 activePeer.deviceName = ' + + activePeer.deviceName); + done(); + } + }); + done(); + } catch (error) { + console.info('MediaLibraryTest : ACTIVE_PEER_CALLBACK getActivePeers 001_02 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_CALLBACK_001_03 + * @tc.name : getActivePeers + * @tc.desc : get the third peers by getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_CALLBACK_001_03', 0, async function(done) { + try { + done(); + let activePeerList = await media.getActivePeers(); + activePeer = activePeerList[2]; + console.info('MediaLibraryTest : ACTIVE_PEER_CALLBACK getActivePeers 001_03 activePeer.deviceName = ' + + activePeer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ACTIVE_PEER_CALLBACK getActivePeers 001_03 fail, message = ' + error); + done(); + } + }); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_CALLBACK_001_04 + * @tc.name : getActivePeers + * @tc.desc : get the forth peers by getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_CALLBACK_001_04', 0, async function(done) { + try { + done(); + let activePeerList = await media.getActivePeers(); + activePeer = activePeerList[3]; + console.info('MediaLibraryTest : ACTIVE_PEER_CALLBACK getActivePeers 001_04 activePeer.deviceName = ' + + activePeer.deviceName); + done(); + } catch (error) { + console.info('MediaLibraryTest : ACTIVE_PEER_CALLBACK 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/getAllPeersTestPromise.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/getAllPeersTestPromise.test.js index a697d7e4d..244adfb25 100644 --- 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 @@ -16,21 +16,27 @@ import mediaLibrary from '@ohos.multimedia.medialibrary'; import featureAbility from '@ohos.ability.featureAbility'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'; -describe('file.promise.test.js', function () { +describe('getAllPeersTestPromise.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) { + beforeAll(function() {}); + beforeEach(function() {}); + afterEach(function() {}); + afterAll(function() {}); + + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_01 + * @tc.name : getAllPeers + * @tc.desc : getAllPeers device + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_01', 0, async function(done) { try { done(); let allPeerList = await media.getAllPeers(); @@ -41,9 +47,16 @@ describe('file.promise.test.js', function () { done(); } }); - - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_02', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_02 + * @tc.name : getAllPeers + * @tc.desc : get the first peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_02', 0, async function(done) { try { done(); let allPeerList = await media.getAllPeers(); @@ -56,7 +69,15 @@ describe('file.promise.test.js', function () { } }); - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_03 + * @tc.name : getAllPeers + * @tc.desc : get the second peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_03', 0, async function(done) { try { done(); let allPeerList = await media.getAllPeers(); @@ -69,7 +90,15 @@ describe('file.promise.test.js', function () { } }); - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_04', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_04 + * @tc.name : getAllPeers + * @tc.desc : get the third peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_04', 0, async function(done) { try { done(); let allPeerList = await media.getAllPeers(); @@ -82,8 +111,15 @@ describe('file.promise.test.js', function () { } }); - - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_05', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_04 + * @tc.name : getAllPeers + * @tc.desc : get the forth peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_05', 0, async function(done) { try { done(); let allPeerList = await media.getAllPeers(); @@ -96,7 +132,15 @@ describe('file.promise.test.js', function () { } }); - it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_06', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_04 + * @tc.name : getAllPeers + * @tc.desc : get the fifth peers by getAllPeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MEDIALIBRARY_ALL_PEER_PROMISE_001_06', 0, async function(done) { try { done(); let allPeerList = await media.getAllPeers(); @@ -109,25 +153,42 @@ describe('file.promise.test.js', function () { } }); - - it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_01', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_01 + * @tc.name : getActivePeers + * @tc.desc : get the first peers by getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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); + 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) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_02 + * @tc.name : getActivePeers + * @tc.desc : get the second peers by getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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); + activePeer = activePeerList[1]; + 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); @@ -135,12 +196,21 @@ describe('file.promise.test.js', function () { } }); - it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_03', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_03 + * @tc.name : getActivePeers + * @tc.desc : get the third peers by getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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); + activePeer = activePeerList[2]; + 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); @@ -148,13 +218,21 @@ describe('file.promise.test.js', function () { } }); - - it('SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_04', 0, async function (done) { + /** + * @tc.number : SUB_MEDIA_MEDIALIBRARY_ACTIVE_PEER_PROMISE_001_04 + * @tc.name : getActivePeers + * @tc.desc : get the forth peers by getActivePeers + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + 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); + activePeer = activePeerList[3]; + 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); diff --git a/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestCallBack.test.js b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestCallBack.test.js new file mode 100644 index 000000000..34b7efd38 --- /dev/null +++ b/multimedia/medialibrary/mediaLibrary_js_standard/src/main/js/test/mediaLibraryTestCallBack.test.js @@ -0,0 +1,938 @@ +/* + * 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 fetchOp = { + selections: fileKeyObj.PATH + ' LIKE ? ', + selectionArgs: ['/data/media/%'], + order: fileKeyObj.PATH, +}; +// let directoryTypeObj = mediaLibrary.DirectoryType; + +let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; +let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; +let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; +let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; +let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; + +let imageType = mediaLibrary.MediaType.IMAGE; +let videoType = mediaLibrary.MediaType.VIDEO; +let audioType = mediaLibrary.MediaType.AUDIO; +let fileType = mediaLibrary.MediaType.FILE; + +let imagesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], +}; +let videosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], +}; +let audiosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], +}; +let filesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], +}; + +let imageAndVideofetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString(), videoType.toString()], +}; +let imageAndVideoAndfilefetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: [imageType.toString(), videoType.toString(), fileType.toString()], +}; +let imageAndVideoAndfileAndAudiofetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: [ + imageType.toString(), + videoType.toString(), + fileType.toString(), + audioType.toString(), + ], +}; + +let allTypefetchOp = { + selections: '', + selectionArgs: [], +}; + +async function copyFile(fd1, fd2) { + let stat = await fileio.fstat(fd1); + let buf = new ArrayBuffer(stat.size); + await fileio.read(fd1, buf); + await fileio.write(fd2, buf); +} + +describe('mediaLibraryTestCallBack.test.js', function () { + const context = featureAbility.getContext(); + const media = mediaLibrary.getMediaLibrary(context); + + beforeAll(function () { }); + beforeEach(function () { }); + afterEach(function () { }); + afterAll(function () { }); + + var timestamp = new Date().getTime(); + var fileName = new Date().getTime() + '.bat'; + + + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_001 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_001', 0, async function (done) { + try { + media.getFileAssets(imagesfetchOp, (err, fetchFileResult) => { + expect(fetchFileResult != undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_002 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_002', 0, async function (done) { + try { + media.getFileAssets(videosfetchOp, (err, fetchFileResult) => { + expect(fetchFileResult != undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 002 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_003 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_003', 0, async function (done) { + try { + media.getFileAssets(audiosfetchOp, (err, fetchFileResult) => { + expect(fetchFileResult != undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_004 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_004', 0, async function (done) { + try { + media.getFileAssets(filesfetchOp, (err, fetchFileResult) => { + expect(fetchFileResult != undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 004 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_005 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_005', 0, async function (done) { + try { + media.getFileAssets(imageAndVideofetchOp, (err, fetchFileResult) => { + expect(fetchFileResult != undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_006 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_006', 0, async function (done) { + try { + media.getFileAssets(imageAndVideoAndfilefetchOp, (err, fetchFileResult) => { + expect(fetchFileResult != undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 006 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_007 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_007', 0, async function (done) { + try { + media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp, (err, fetchFileResult) => { + expect(fetchFileResult != undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 007 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_008 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_008', 0, async function (done) { + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + 'abc= ?', + selectionArgs: ['abc'], + }; + try { + media.getFileAssets(fetchOp, (err, fetchFileResult) => { + expect(fetchFileResult == undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 008 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009', 0, async function (done) { + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['abc', audioType.toString()], + }; + try { + media.getFileAssets(fetchOp, (err, fetchFileResult) => { + expect(fetchFileResult == undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 009 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_009 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_010', 0, async function (done) { + let fetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + 'abc= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: ['abc', videoType.toString(), fileType.toString()], + }; + try { + media.getFileAssets(fetchOp, (err, fetchFileResult) => { + expect(fetchFileResult == undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 010 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_011 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETFILEASSETS_011', 0, async function (done) { + let fetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + 'abc= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()], + }; + try { + media.getFileAssets(fetchOp, (err, fetchFileResult) => { + expect(fetchFileResult == undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 011 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_001 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_CAMERA + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_001', 0, async function (done) { + try { + + let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; + + media.getPublicDirectory(DIR_CAMERA, async (err, dicResult) => { + expect(dicResult == 'Camera/').assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_002 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_002', 0, async function (done) { + try { + let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; + + media.getPublicDirectory(DIR_VIDEO, async (err, dicResult) => { + expect(dicResult == 'Videos/').assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_003 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_003', 0, async function (done) { + try { + let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; + + media.getPublicDirectory(DIR_IMAGE, async (err, dicResult) => { + expect(dicResult == 'Pictures/').assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_004 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_004', 0, async function (done) { + try { + let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; + + media.getPublicDirectory(DIR_AUDIO, async (err, dicResult) => { + expect(dicResult == 'Audios/').assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_005 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_005', 0, async function (done) { + try { + let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; + + media.getPublicDirectory(DIR_DOCUMENTS, async (err, dicResult) => { + expect(dicResult == 'Documents/').assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_006 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory 110 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_GETPUBLICDIRECTORY_006', 0, async function (done) { + try { + media.getPublicDirectory(110, async (err, dicResult) => { + expect(dicResult == undefined).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 006 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_DELETEASSET_001 + * @tc.name : deleteAsset + * @tc.desc : Delete File by Asset uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_DELETEASSET_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset1 = dataList[0]; + const delUri = asset1.uri; + + media.deleteAsset(asset1.uri, async () => { + const fetchFileResult1 = await media.getFileAssets(imagesfetchOp); + const dataList1 = await fetchFileResult1.getAllObject(); + + let passed = true; + for (let i = 0; i < dataList1.length; i++) { + const asset = dataList1[i]; + if (asset.uri == delUri) { + passed = false; + } + } + expect(passed).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : deleteAsset 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_DELETEASSET_002 + * @tc.name : deleteAsset + * @tc.desc : Delete File Asset by aaaa + uri + aaaaa + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_DELETEASSET_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset1 = dataList[0]; + const delUri = asset1.uri; + + await media.deleteAsset('aaaa' + asset1.uri + 'aaaa', async () => { + const fetchFileResult1 = await media.getFileAssets(imagesfetchOp); + const dataList1 = await fetchFileResult1.getAllObject(); + + let passed = false; + for (let i = 0; i < dataList1.length; i++) { + const asset = dataList1[i]; + if (asset.uri == delUri) { + passed = true; + } + } + expect(passed).assertTrue(); + done(); + }); + } catch (error) { + console.info(`MediaLibraryTest : deleteAsset 002 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_009 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_009', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const filePath = path + "image/"; + const fileAssets = await media.getFileAssets(imagesfetchOp); + const asset1 = await fileAssets.getFirstObject(); + const jpgName = new Date().getTime() + '.jpg'; + media.createAsset(imageType, jpgName, filePath, async (err, creatAsset1) => { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + console.info('MediaLibraryTest : createAsset 009 passed'); + expect(true).assertTrue(); + done(); + } + }); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 009 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_001 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_001', 0, async function (done) { + try { + const jpgName = new Date().getTime() + '.jpg'; + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + + const fileAssets = await media.getFileAssets(imagesfetchOp); + + const asset1 = await fileAssets.getFirstObject(); + + media.createAsset(imageType, jpgName, path, async (err, creatAsset1) => { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 001 passed'); + expect(true).assertTrue(); + done(); + } + }); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_002 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_002', 0, async function (done) { + try { + const jpgName = new Date().getTime() + '.jpg'; + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(imagesfetchOp); + const asset1 = await fileAssets.getFirstObject(); + media.createAsset(imageType, jpgName, path, async (err, creatAsset1) => { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + media.createAsset(imageType, jpgName, path, async (err, creatAsset2) => { + expect(creatAsset2 == undefined).assertTrue(); + done(); + }); + } + }); + + } catch (error) { + console.info(`MediaLibraryTest : createAsset 002 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_003 + * @tc.name : createAsset + * @tc.desc : Create File Asset video (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_003', 0, async function (done) { + try { + const videoName = new Date().getTime() + '.mp4'; + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + const fileAssets = await media.getFileAssets(videosfetchOp); + const asset1 = await fileAssets.getFirstObject(); + media.createAsset(videoType, videoName, path, async (err, creatAsset1) => { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + console.info('MediaLibraryTest : createAsset 003 passed'); + expect(true).assertTrue(); + done(); + } + }); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_004 + * @tc.name : createAsset + * @tc.desc : Create File Asset video (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_004', 0, async function (done) { + try { + const videoName = new Date().getTime() + '.mp4'; + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + const fileAssets = await media.getFileAssets(videosfetchOp); + const asset1 = await fileAssets.getFirstObject(); + media.createAsset(videoType, videoName, path, async (err, creatAsset1) => { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + media.createAsset(videoType, videoName, path, async (err, creatAsset2) => { + expect(creatAsset2 == undefined).assertTrue(); + done(); + }); + } + }); + + } catch (error) { + console.info(`MediaLibraryTest : createAsset 004 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_005 + * @tc.name : createAsset + * @tc.desc : Create File Asset audio (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_005', 0, async function (done) { + try { + const audioName = new Date().getTime() + '.mp3'; + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const asset1 = await fileAssets.getFirstObject(); + media.createAsset(audioType, audioName, path, async (err, creatAsset1) => { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 005 passed'); + expect(true).assertTrue(); + done(); + } + }); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_006 + * @tc.name : createAsset + * @tc.desc : Create File Asset audio (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_006', 0, async function (done) { + try { + const audioName = new Date().getTime() + '.mp3'; + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const asset1 = await fileAssets.getFirstObject(); + media.createAsset(audioType, audioName, path, async (err, creatAsset1) => { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + media.createAsset(audioType, audioName, path, async (err, creatAsset2) => { + expect(creatAsset2 == undefined).assertTrue(); + done(); + }); + } + }); + + } catch (error) { + console.info(`MediaLibraryTest : createAsset 006 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_007 + * @tc.name : createAsset + * @tc.desc : Create File Asset file (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_007', 0, async function (done) { + try { + const fileName = new Date().getTime() + '.bat'; + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); + const fileAssets = await media.getFileAssets(filesfetchOp); + const asset1 = await fileAssets.getFirstObject(); + media.createAsset(fileType, fileName, path, async (err, creatAsset1) => { + try { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 007 passed'); + expect(true).assertTrue(); + done(); + } + } catch (error) { + console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_008 + * @tc.name : createAsset + * @tc.desc : Create File Asset file (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_CREATEASSET_008', 0, async function (done) { + try { + const fileName = new Date().getTime() + '.bat'; + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); + const fileAssets = await media.getFileAssets(filesfetchOp); + const asset1 = await fileAssets.getFirstObject(); + media.createAsset(fileType, fileName, path, async (err, creatAsset1) => { + try { + if (creatAsset1 == undefined) { + expect(false).assertTrue(); + done(); + } else { + const fd1 = await asset1.open('r'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + media.createAsset(fileType, fileName, path, async (err, creatAsset2) => { + expect(creatAsset2 == undefined).assertTrue(); + done(); + }); + } + } catch (error) { + console.info(`MediaLibraryTest : createAsset 008 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 008 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + +}); 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 afc5187ad..a808f6e52 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 @@ -1,831 +1,862 @@ -/* - * 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 fetchOp = { - selections: fileKeyObj.PATH + ' LIKE ? ', - selectionArgs: ['/data/media/%'], - order: fileKeyObj.PATH, -}; -// let directoryTypeObj = mediaLibrary.DirectoryType; - -let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; -let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; -let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; -let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; -let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; - -let imageType = mediaLibrary.MediaType.IMAGE; -let videoType = mediaLibrary.MediaType.VIDEO; -let audioType = mediaLibrary.MediaType.AUDIO; -let fileType = mediaLibrary.MediaType.FILE; - -let imagesfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString()], -}; -let videosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [videoType.toString()], -}; -let audiosfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [audioType.toString()], -}; -let filesfetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [fileType.toString()], -}; - -let imageAndVideofetchOp = { - selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: [imageType.toString(), videoType.toString()], -}; -let imageAndVideoAndfilefetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: [imageType.toString(), videoType.toString(), fileType.toString()], -}; -let imageAndVideoAndfileAndAudiofetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: [ - imageType.toString(), - videoType.toString(), - fileType.toString(), - audioType.toString(), - ], -}; - -let allTypefetchOp = { - selections: '', - selectionArgs: [], -}; - -async function copyFile(fd1, fd2) { - let stat = await fileio.fstat(fd1); - let buf = new ArrayBuffer(stat.size); - await fileio.read(fd1, buf); - await fileio.write(fd2, buf); -} - -describe('mediaLibraryTestPromise.test.js', function () { - const context = featureAbility.getContext(); - const media = mediaLibrary.getMediaLibrary(context); - - beforeAll(function () {}); - beforeEach(function () {}); - afterEach(function () {}); - afterAll(function () {}); - - var timestamp = new Date().getTime(); - var jpgName = timestamp + '.jpg'; - var videoName = timestamp + '.mp4'; - var audioName = timestamp + '.mp3'; - var fileName = timestamp + '.mp3'; - - /** - * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001 - * @tc.name : getMediaLibrary - * @tc.desc : Obtains a MediaLibrary instance - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001', 0, async function (done) { - try { - expect(media != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getMediaLibrary 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - expect(fetchFileResult != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(videosfetchOp); - expect(fetchFileResult != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 002 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(audiosfetchOp); - expect(fetchFileResult != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(filesfetchOp); - expect(fetchFileResult != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 004 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideofetchOp); - expect(fetchFileResult != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideoAndfilefetchOp); - expect(fetchFileResult != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 006 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp); - expect(fetchFileResult != undefined).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 007 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008', 0, async function (done) { - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + 'abc= ?', - selectionArgs: ['abc'], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 008 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getFileAssets 008 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009', 0, async function (done) { - let fetchOp = { - selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', - selectionArgs: ['abc', audioType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 009 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 009 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) { - let fetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - 'abc= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: ['abc', videoType.toString(), fileType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 010 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 010 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011 - * @tc.name : getFileAssets - * @tc.desc : query all assets - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) { - let fetchOp = { - selections: - fileKeyObj.MEDIA_TYPE + - 'abc= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ? or ' + - fileKeyObj.MEDIA_TYPE + - '= ?', - selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()], - }; - try { - await media.getFileAssets(fetchOp); - console.info('MediaLibraryTest : getFileAssets 011 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getFileAssets 011 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_CAMERA - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) { - try { - let DIR_CDSA = mediaLibrary.DirectoryType.DIR_CDSA; - - const dicResult = await media.getPublicDirectory(DIR_CDSA); - - expect(dicResult == 'CDSA/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_VIDEO - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002', 0, async function (done) { - try { - let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; - - const dicResult = await media.getPublicDirectory(DIR_VIDEO); - console.log(dicResult); - expect(dicResult == 'Movies/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003', 0, async function (done) { - try { - let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; - - const dicResult = await media.getPublicDirectory(DIR_IMAGE); - - expect(dicResult == 'Pictures/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004', 0, async function (done) { - try { - let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; - - const dicResult = await media.getPublicDirectory(DIR_AUDIO); - - expect(dicResult == 'Music/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory DIR_IMAGE - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005', 0, async function (done) { - try { - let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; - - const dicResult = await media.getPublicDirectory(DIR_DOCUMENTS); - - expect(dicResult == 'Documents/').assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006 - * @tc.name : getPublicDirectory - * @tc.desc : getPublicDirectory 110 - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006', 0, async function (done) { - try { - await media.getPublicDirectory(110); - console.info('MediaLibraryTest : getPublicDirectory 006 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : getPublicDirectory 006 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_001 - * @tc.name : deleteAsset - * @tc.desc : Delete File by Asset uri - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_001', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset1 = dataList[0]; - const delUri = asset1.uri; - - await media.deleteAsset(asset1.uri); - - const fetchFileResult1 = await media.getFileAssets(imagesfetchOp); - const dataList1 = await fetchFileResult1.getAllObject(); - - let passed = true; - for (let i = 0; i < dataList1.length; i++) { - const asset = dataList1[i]; - if (asset.uri == delUri) { - passed = false; - } - } - expect(passed).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : deleteAsset 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_002 - * @tc.name : deleteAsset - * @tc.desc : Delete File Asset by aaaa + uri + aaaaa - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_002', 0, async function (done) { - try { - const fetchFileResult = await media.getFileAssets(imagesfetchOp); - const dataList = await fetchFileResult.getAllObject(); - const asset1 = dataList[0]; - await media.deleteAsset('aaaa' + asset1.uri + 'aaaa'); - console.info('MediaLibraryTest : deleteAsset 002 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info('MediaLibraryTest : deleteAsset 002 passed'); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 - * @tc.name : createAsset - * @tc.desc : Create File Asset image (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - - const creatAsset1 = await media.createAsset(imageType, jpgName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 001 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 001 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002 - * @tc.name : createAsset - * @tc.desc : Create File Asset image (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(imageType, jpgName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 002 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 002 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003 - * @tc.name : createAsset - * @tc.desc : Create File Asset video (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, videoName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 003 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 003 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004 - * @tc.name : createAsset - * @tc.desc : Create File Asset video (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); - const fileAssets = await media.getFileAssets(videosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, videoName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 004 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 004 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005 - * @tc.name : createAsset - * @tc.desc : Create File Asset audio (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(audioType, audioName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 005 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 005 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006 - * @tc.name : createAsset - * @tc.desc : Create File Asset audio (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - const fileAssets = await media.getFileAssets(audiosfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(videoType, audioName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 006 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 006 passed`); - expect(true).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007 - * @tc.name : createAsset - * @tc.desc : Create File Asset file (does not exist) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(fileType, fileName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 007 passed'); - expect(true).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`); - expect(false).assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008 - * @tc.name : createAsset - * @tc.desc : Create File Asset file (existed) - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008', 0, async function (done) { - try { - const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); - const fileAssets = await media.getFileAssets(filesfetchOp); - const dataList = await fileAssets.getAllObject(); - const asset1 = dataList[0]; - const creatAsset1 = await media.createAsset(fileType, fileName, path); - const fd1 = await asset1.open('rw'); - const creatAssetFd1 = await creatAsset1.open('rw'); - await copyFile(fd1, creatAssetFd1); - await creatAsset1.close(creatAssetFd1); - await asset1.close(fd1); - - console.info('MediaLibraryTest : createAsset 008 failed'); - expect(false).assertTrue(); - done(); - } catch (error) { - console.info(`MediaLibraryTest : createAsset 008 passed`); - expect(true).assertTrue(); - done(); - } - }); -}); +/* + * 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 fetchOp = { + selections: fileKeyObj.PATH + ' LIKE ? ', + selectionArgs: ['/data/media/%'], + order: fileKeyObj.PATH, +}; +// let directoryTypeObj = mediaLibrary.DirectoryType; + +let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; +let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; +let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; +let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; +let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; + +let imageType = mediaLibrary.MediaType.IMAGE; +let videoType = mediaLibrary.MediaType.VIDEO; +let audioType = mediaLibrary.MediaType.AUDIO; +let fileType = mediaLibrary.MediaType.FILE; + +let imagesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString()], +}; +let videosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [videoType.toString()], +}; +let audiosfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [audioType.toString()], +}; +let filesfetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [fileType.toString()], +}; + +let imageAndVideofetchOp = { + selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: [imageType.toString(), videoType.toString()], +}; +let imageAndVideoAndfilefetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: [imageType.toString(), videoType.toString(), fileType.toString()], +}; +let imageAndVideoAndfileAndAudiofetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: [ + imageType.toString(), + videoType.toString(), + fileType.toString(), + audioType.toString(), + ], +}; + +let allTypefetchOp = { + selections: '', + selectionArgs: [], +}; + +async function copyFile(fd1, fd2) { + let stat = await fileio.fstat(fd1); + let buf = new ArrayBuffer(stat.size); + await fileio.read(fd1, buf); + await fileio.write(fd2, buf); +} + +describe('mediaLibraryTestPromise.test.js', function () { + const context = featureAbility.getContext(); + const media = mediaLibrary.getMediaLibrary(context); + + beforeAll(function () {}); + beforeEach(function () {}); + afterEach(function () {}); + afterAll(function () {}); + + var timestamp = new Date().getTime(); + var jpgName = timestamp + '.jpg'; + var videoName = timestamp + '.mp4'; + var audioName = timestamp + '.mp3'; + var fileName = timestamp + '.mp3'; + + /** + * @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001 + * @tc.name : getMediaLibrary + * @tc.desc : Obtains a MediaLibrary instance + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001', 0, async function (done) { + try { + expect(media != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getMediaLibrary 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + expect(fetchFileResult != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(videosfetchOp); + expect(fetchFileResult != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 002 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(audiosfetchOp); + expect(fetchFileResult != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(filesfetchOp); + expect(fetchFileResult != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 004 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageAndVideofetchOp); + expect(fetchFileResult != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageAndVideoAndfilefetchOp); + expect(fetchFileResult != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 006 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp); + expect(fetchFileResult != undefined).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 007 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008', 0, async function (done) { + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + 'abc= ?', + selectionArgs: ['abc'], + }; + try { + await media.getFileAssets(fetchOp); + console.info('MediaLibraryTest : getFileAssets 008 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getFileAssets 008 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009', 0, async function (done) { + let fetchOp = { + selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', + selectionArgs: ['abc', audioType.toString()], + }; + try { + await media.getFileAssets(fetchOp); + console.info('MediaLibraryTest : getFileAssets 009 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 009 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) { + let fetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + 'abc= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: ['abc', videoType.toString(), fileType.toString()], + }; + try { + await media.getFileAssets(fetchOp); + console.info('MediaLibraryTest : getFileAssets 010 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 010 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011 + * @tc.name : getFileAssets + * @tc.desc : query all assets + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) { + let fetchOp = { + selections: + fileKeyObj.MEDIA_TYPE + + 'abc= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ? or ' + + fileKeyObj.MEDIA_TYPE + + '= ?', + selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()], + }; + try { + await media.getFileAssets(fetchOp); + console.info('MediaLibraryTest : getFileAssets 011 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getFileAssets 011 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_CAMERA + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) { + try { + let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA; + + const dicResult = await media.getPublicDirectory(DIR_CAMERA); + + expect(dicResult == 'Camera/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_VIDEO + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002', 0, async function (done) { + try { + let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO; + + const dicResult = await media.getPublicDirectory(DIR_VIDEO); + console.log(dicResult); + expect(dicResult == 'Videos/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003', 0, async function (done) { + try { + let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; + + const dicResult = await media.getPublicDirectory(DIR_IMAGE); + + expect(dicResult == 'Pictures/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004', 0, async function (done) { + try { + let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO; + + const dicResult = await media.getPublicDirectory(DIR_AUDIO); + + expect(dicResult == 'Audios/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory DIR_IMAGE + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005', 0, async function (done) { + try { + let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS; + + const dicResult = await media.getPublicDirectory(DIR_DOCUMENTS); + + expect(dicResult == 'Documents/').assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006 + * @tc.name : getPublicDirectory + * @tc.desc : getPublicDirectory 110 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006', 0, async function (done) { + try { + await media.getPublicDirectory(110); + console.info('MediaLibraryTest : getPublicDirectory 006 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : getPublicDirectory 006 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_001 + * @tc.name : deleteAsset + * @tc.desc : Delete File by Asset uri + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_001', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset1 = dataList[0]; + const delUri = asset1.uri; + + await media.deleteAsset(asset1.uri); + + const fetchFileResult1 = await media.getFileAssets(imagesfetchOp); + const dataList1 = await fetchFileResult1.getAllObject(); + + let passed = true; + for (let i = 0; i < dataList1.length; i++) { + const asset = dataList1[i]; + if (asset.uri == delUri) { + passed = false; + } + } + expect(passed).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : deleteAsset 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_002 + * @tc.name : deleteAsset + * @tc.desc : Delete File Asset by aaaa + uri + aaaaa + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_002', 0, async function (done) { + try { + const fetchFileResult = await media.getFileAssets(imagesfetchOp); + const dataList = await fetchFileResult.getAllObject(); + const asset1 = dataList[0]; + await media.deleteAsset('aaaa' + asset1.uri + 'aaaa'); + console.info('MediaLibraryTest : deleteAsset 002 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info('MediaLibraryTest : deleteAsset 002 passed'); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + + const creatAsset1 = await media.createAsset(imageType, jpgName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 001 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 001 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(imageType, jpgName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 002 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 002 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003 + * @tc.name : createAsset + * @tc.desc : Create File Asset video (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(videoType, videoName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 003 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 003 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004 + * @tc.name : createAsset + * @tc.desc : Create File Asset video (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(videoType, videoName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 004 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 004 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005 + * @tc.name : createAsset + * @tc.desc : Create File Asset audio (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(audioType, audioName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 005 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 005 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006 + * @tc.name : createAsset + * @tc.desc : Create File Asset audio (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); + const fileAssets = await media.getFileAssets(audiosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(videoType, audioName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 006 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 006 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007 + * @tc.name : createAsset + * @tc.desc : Create File Asset file (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(fileType, fileName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 007 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008 + * @tc.name : createAsset + * @tc.desc : Create File Asset file (existed) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); + const fileAssets = await media.getFileAssets(filesfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(fileType, fileName, path); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + + console.info('MediaLibraryTest : createAsset 008 failed'); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 008 passed`); + expect(true).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001 + * @tc.name : createAsset + * @tc.desc : Create File Asset image (does not exist) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_009', 0, async function (done) { + try { + const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); + const filePath = path + "image/"; + const fileAssets = await media.getFileAssets(videosfetchOp); + const dataList = await fileAssets.getAllObject(); + const asset1 = dataList[0]; + const creatAsset1 = await media.createAsset(imageType, jpgName, filePath); + const fd1 = await asset1.open('rw'); + const creatAssetFd1 = await creatAsset1.open('rw'); + await copyFile(fd1, creatAssetFd1); + await creatAsset1.close(creatAssetFd1); + await asset1.close(fd1); + console.info('MediaLibraryTest : createAsset 009 passed'); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info(`MediaLibraryTest : createAsset 009 failed, error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); +}); -- GitLab