未验证 提交 20e4ba75 编写于 作者: O openharmony_ci 提交者: Gitee

!5009 XTS Split 0817

Merge pull request !5009 from caochuan/master
......@@ -36,6 +36,7 @@ group("multimedia") {
"media/media_js_standard/recorderProfile:recorder_profile_js_hap",
"media/media_js_standard/videoPlayer:video_player_js_hap",
"medialibrary/mediaLibrary_album:mediaLibrary_album_hap",
"medialibrary/mediaLibrary_base:mediaLibrary_base_hap",
"medialibrary/mediaLibrary_favorite:mediaLibrary_favorite_hap",
"medialibrary/mediaLibrary_file:mediaLibrary_file_hap",
"medialibrary/mediaLibrary_fileAsset:mediaLibrary_fileAsset_hap",
......@@ -43,8 +44,6 @@ group("multimedia") {
"medialibrary/mediaLibrary_fileKey:mediaLibrary_fileKey_hap",
"medialibrary/mediaLibrary_fileResult:mediaLibrary_fileResult_hap",
"medialibrary/mediaLibrary_getThumbnail:mediaLibrary_getThumbnail_hap",
"medialibrary/mediaLibrary_js:mediaLibrary_js_hap",
"medialibrary/mediaLibrary_js_standard:mediaLibrary_js_hap",
]
} else {
deps = [
......
......@@ -17,16 +17,16 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import bundle from '@ohos.bundle';
const presetsCount = {
ActsMediaLibraryAlbum: { assetsCount: 19, albumsCount: 7 },
ActsMediaLibraryFavorite: { assetsCount: 32, albumsCount: 6 },
//ActsMediaLibraryAlbumFileResultPro test case create 1 album 5 assets
ActsMediaLibraryAlbumFileResultPro: { assetsCount: 123, albumsCount: 6 },
//ActsMediaLibraryAlbumFileResultCb test case create 1 album 5 assets
ActsMediaLibraryAlbumFileResultCb: { assetsCount: 118, albumsCount: 5 },
ActsMediaLibraryFileKey: { assetsCount: 4, albumsCount: 4 },
ActsMediaLibraryFileAsset: { assetsCount: 4, albumsCount: 4 },
ActsMediaLibraryFile: { assetsCount: 4, albumsCount: 4 },
ActsMediaLibraryGetThumbnail: { assetsCount: 3, albumsCount: 3 },
ActsMediaLibraryAlbum: { albumsCount: 7, assetsCount: 19 },
ActsMediaLibraryFavorite: { albumsCount: 6, assetsCount: 32 },
ActsMediaLibraryAlbumFileResultCb: { albumsCount: 5, assetsCount: 118 },
ActsMediaLibraryFile: { albumsCount: 6, assetsCount: 21 },
ActsMediaLibraryFileAsset: { albumsCount: 27, assetsCount: 72 },
ActsMediaLibraryFileAssetUri: { albumsCount: 3, assetsCount: 6 },
ActsMediaLibraryFileKey: { albumsCount: 2, assetsCount: 2 },
ActsMediaLibraryFileResult: { albumsCount: 4, assetsCount: 13 },
ActsMediaLibraryGetThumbnail: { albumsCount: 3, assetsCount: 3 },
ActsMediaLibraryBase: { albumsCount: 11, assetsCount: 11 },
}
const IMAGE_TYPE = mediaLibrary.MediaType.IMAGE;
......@@ -122,10 +122,9 @@ const checkPresetsAssets = async function (media, hapName) {
let albumsCount = albumList.length;
let fetchFileResult = await media.getFileAssets(allFetchOp());
let assetsCount = await fetchFileResult.getCount();
console.info(`${hapName}:: assetsCount: ${assetsCount}`);
console.info(`${hapName}:: albumsCount: ${albumsCount}`);
console.info(`${hapName}:: presetsassetsCount: ${presetsCount[hapName].assetsCount}`);
console.info(`${hapName}:: presetsalbumsCount: ${presetsCount[hapName].albumsCount}`);
console.info(`${hapName}:: assetsCount: ${assetsCount} albumsCount: ${albumsCount}
presetsassetsCount: ${presetsCount[hapName].assetsCount}
presetsalbumsCount: ${presetsCount[hapName].albumsCount}`);
console.info('checkPresetsAssets end')
}
......
......@@ -13,7 +13,7 @@
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("mediaLibrary_js_hap") {
ohos_js_hap_suite("mediaLibrary_base_hap") {
hap_profile = "entry/src/main/module.json"
deps = [
":mediaLibrary_js_assets",
......@@ -21,7 +21,7 @@ ohos_js_hap_suite("mediaLibrary_js_hap") {
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsMediaLibraryJs"
hap_name = "ActsMediaLibraryBase"
}
ohos_app_scope("medialibrary_app_profile") {
......
......@@ -54,7 +54,7 @@
},
{
"test-file-name": [
"ActsMediaLibraryJs.hap"
"ActsMediaLibraryBase.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -13,10 +13,12 @@
* limitations under the License.
*/
import mediaLibraryTestCallback from './mediaLibraryTestCallback.test.ets'
import mediaLibraryTestPromise from './mediaLibraryTestPromise.test.ets'
import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets'
export default function testsuite(abilityContext) {
mediaLibraryTestCallback(abilityContext)
mediaLibraryTestPromise(abilityContext)
mediaLibraryTestPromiseOnOffTest(abilityContext)
}
......@@ -36,7 +36,7 @@ export default function mediaLibraryTestPromiseTest(abilityContext) {
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail');
await checkPresetsAssets(media, 'ActsMediaLibraryBase');
});
beforeEach(function () {
console.info('beforeEach case');
......
......@@ -35,7 +35,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail');
await checkPresetsAssets(media, 'ActsMediaLibraryBase');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -321,6 +321,43 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
await offTest(done, testNum, type, currentFetchOps)
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005
* @tc.name : off
* @tc.desc : off album
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005', 0, async function (done) {
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005'
try {
let conut = 0;
media.on('albumChange', () => {
conut++;
});
await sleep(300)
media.off('albumChange');
let currentFetchOps = albumFetchOps('Pictures/', 'OffAlbum', IMAGE_TYPE);
const albumList = await media.getAlbums(currentFetchOps);
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, 1);
if (!albumCountPass) return;
const album = albumList[0]
const oldName = album.albumName
album.albumName = album.albumName + 'changename';
await sleep(1000)
await album.commitModify();
await sleep(300)
album.albumName = oldName;
await album.commitModify();
expect(conut).assertEqual(0);
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_006
* @tc.name : off
......
......@@ -13,7 +13,9 @@
* limitations under the License.
*/
import fileTestCallback from './fileTestCallback.test.ets'
import fileTestPromise from './fileTestPromise.test.ets'
export default function testsuite(abilityContext) {
fileTestCallback(abilityContext)
fileTestPromise(abilityContext)
}
......@@ -26,7 +26,6 @@ import {
checkPresetsAssets,
nameFetchOps,
checkAssetsCount,
getPermission,
fetchOps,
FILEKEY,
isNum,
......@@ -37,7 +36,6 @@ export default function fileTestPromiseTest(abilityContext) {
describe('fileTestPromiseTest', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryFile')
});
beforeEach(function () { });
......
......@@ -32,20 +32,20 @@
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/{Static,RW,R,W,openClose}",
"mkdir -pv /storage/media/100/local/files/Videos/{Static,RW,R,W,openClose}",
"mkdir -pv /storage/media/100/local/files/Audios/{Static,RW,R,W,openClose}",
"mkdir -pv /storage/media/100/local/files/Documents/{Static,RW,R,W,openClose}",
"mkdir -pv /storage/media/100/local/files/Pictures/{ModifyCb,ModifyPro,RW,R,W,RW_cb,R_cb,W_cb,openClose}",
"mkdir -pv /storage/media/100/local/files/Videos/{ModifyCb,ModifyPro,RW,R,W,RW_cb,R_cb,W_cb,openClose}",
"mkdir -pv /storage/media/100/local/files/Audios/{ModifyCb,ModifyPro,RW,R,W,RW_cb,R_cb,W_cb,openClose}",
"mkdir -pv /storage/media/100/local/files/Documents/{ModifyCb,ModifyPro,RW,R,W,RW_cb,R_cb,W_cb,openClose}",
"for d in RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"for d in RW_cb R_cb W_cb RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in RW_cb R_cb W_cb RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in RW_cb R_cb W_cb RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in RW_cb R_cb W_cb RW R W openClose; do for i in $$(seq 2); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"for d in Static; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in Static; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"for d in ModifyCb ModifyPro; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in ModifyCb ModifyPro; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in ModifyCb ModifyPro; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in ModifyCb ModifyPro; do for i in $$(seq 5); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"chmod -R 777 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
......
......@@ -13,9 +13,13 @@
* limitations under the License.
*/
import fileAssetCallback2 from './fileAssetCallback2.test.ets'
import fileAssetPromise2 from './fileAssetPromise2.test.ets'
import fileAssetTestCallback from './fileAssetTestCallback.test.ets'
import fileAssetTestPromise from './fileAssetTestPromise.test.ets'
export default function testsuite(abilityContext) {
fileAssetCallback2(abilityContext)
fileAssetPromise2(abilityContext)
fileAssetTestCallback(abilityContext)
fileAssetTestPromise(abilityContext)
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
FILEKEY,
checkPresetsAssets,
checkAssetsCount,
getPermission,
nameFetchOps,
} from '../../../../../../common';
export default function fileAssetCallback2Test(abilityContext) {
describe('fileAssetCallback2Test', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryFileAsset')
});
beforeEach(function () { });
afterEach(async function () {
await sleep()
});
afterAll(function () { });
const checkCommitModify = async function (done, testNum, fetchOp, prop, val) {
try {
console.info(`${testNum} fetchOp : ${JSON.stringify(fetchOp)}`)
const fetchFileResult = await media.getFileAssets(fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const oldVal = asset[prop]
asset[prop] = val;
const id = asset.id;
await asset.commitModify(async (err) => {
if (err) {
console.info(`${testNum} err : ${err}`)
expect.assertFail();
done();
return;
}
let currentfetchOp = {
selections: FILEKEY.ID + '= ?',
selectionArgs: [id + ''],
};
const fetchFileResult2 = await media.getFileAssets(currentfetchOp);
const currentAsset = await fetchFileResult2.getFirstObject();
expect(currentAsset[prop]).assertEqual(val);
asset[prop] = oldVal;
await asset.commitModify();
await fetchFileResult.close();
done();
});
} catch (error) {
console.info(`${testNum} error : ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_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) {
let testNum = 'SUB_MEDIA_FILEASSET_commitModify_callback_001'
let fetchOp = nameFetchOps('Pictures/ModifyCb/', '01', IMAGE_TYPE);
let prop = 'displayName'
let val = new Date().getTime() + '.jpg'
await checkCommitModify(done, testNum, fetchOp, prop, val)
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_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) {
let testNum = 'SUB_MEDIA_FILEASSET_commitModify_callback_002'
let fetchOp = nameFetchOps('Pictures/ModifyCb/', '02', IMAGE_TYPE);
let prop = 'title'
let val = new Date().getTime() + 'newTitle'
await checkCommitModify(done, testNum, fetchOp, prop, val)
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_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) {
let testNum = 'SUB_MEDIA_FILEASSET_commitModify_callback_003'
let fetchOp = nameFetchOps('Pictures/ModifyCb/', '03', IMAGE_TYPE);
let prop = 'relativePath'
let val = 'Pictures/Temp/'
await checkCommitModify(done, testNum, fetchOp, prop, val)
});
/**
* @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) {
let testNum = 'SUB_MEDIA_FILEASSET_commitModify_callback_004'
let fetchOp = nameFetchOps('Pictures/ModifyCb/', '04', IMAGE_TYPE);
let prop = 'orientation'
let val = 1
await checkCommitModify(done, testNum, fetchOp, prop, val)
});
/**
* @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 {
let fetchOp = nameFetchOps('Pictures/ModifyCb/', '05', IMAGE_TYPE);
const fetchFileResult = await media.getFileAssets(fetchOp);
const asset = await fetchFileResult.getFirstObject();
const isDir = await asset.isDirectory();
expect(!isDir).assertTrue();
done();
} catch (error) {
console.info('FileAsset isDirectory 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
});
}
......@@ -20,12 +20,9 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {
sleep,
IMAGE_TYPE,
AUDIO_TYPE,
FILEKEY,
checkPresetsAssets,
checkAssetsCount,
getPermission,
fetchOps,
nameFetchOps,
} from '../../../../../../common';
......@@ -33,8 +30,7 @@ export default function fileAssetPromise2Test(abilityContext) {
describe('fileAssetPromise2Test', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryFileKey')
await checkPresetsAssets(media, 'ActsMediaLibraryFileAsset')
});
beforeEach(function () { });
afterEach(async function () {
......@@ -82,7 +78,7 @@ export default function fileAssetPromise2Test(abilityContext) {
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_001', 0, async function (done) {
let testNum = 'SUB_MEDIA_FILEASSET_commitModify_promise_001'
let fetchOp = nameFetchOps('Pictures/Static/', '01', IMAGE_TYPE);
let fetchOp = nameFetchOps('Pictures/ModifyPro/', '01', IMAGE_TYPE);
let prop = 'displayName'
let val = new Date().getTime() + '.jpg'
await checkCommitModify(done, testNum, fetchOp, prop, val)
......@@ -98,7 +94,7 @@ export default function fileAssetPromise2Test(abilityContext) {
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_002', 0, async function (done) {
let testNum = 'SUB_MEDIA_FILEASSET_commitModify_promise_002'
let fetchOp = nameFetchOps('Pictures/Static/', '02', IMAGE_TYPE);
let fetchOp = nameFetchOps('Pictures/ModifyPro/', '02', IMAGE_TYPE);
let prop = 'title'
let val = new Date().getTime() + 'newTitle'
await checkCommitModify(done, testNum, fetchOp, prop, val)
......@@ -114,7 +110,7 @@ export default function fileAssetPromise2Test(abilityContext) {
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_003', 0, async function (done) {
let testNum = 'SUB_MEDIA_FILEASSET_commitModify_promise_003'
let fetchOp = nameFetchOps('Pictures/Static/', '03', IMAGE_TYPE);
let fetchOp = nameFetchOps('Pictures/ModifyPro/', '03', IMAGE_TYPE);
let prop = 'relativePath'
let val = 'Pictures/Temp/'
await checkCommitModify(done, testNum, fetchOp, prop, val)
......@@ -131,7 +127,7 @@ export default function fileAssetPromise2Test(abilityContext) {
it('SUB_MEDIA_FILEASSET_commitModify_promise_004', 0, async function (done) {
let testNum = 'SUB_MEDIA_FILEASSET_commitModify_promise_004'
let fetchOp = nameFetchOps('Pictures/Static/', '04', IMAGE_TYPE);
let fetchOp = nameFetchOps('Pictures/ModifyPro/', '04', IMAGE_TYPE);
let prop = 'orientation'
let val = 1
await checkCommitModify(done, testNum, fetchOp, prop, val)
......@@ -147,7 +143,7 @@ export default function fileAssetPromise2Test(abilityContext) {
*/
it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) {
try {
let fetchOp = nameFetchOps('Pictures/Static/', '05', IMAGE_TYPE);
let fetchOp = nameFetchOps('Pictures/ModifyPro/', '05', IMAGE_TYPE);
const fetchFileResult = await media.getFileAssets(fetchOp);
const asset = await fetchFileResult.getFirstObject();
const isDir = await asset.isDirectory();
......
......@@ -22,19 +22,15 @@ import {
VIDEO_TYPE,
AUDIO_TYPE,
FILE_TYPE,
FILEKEY,
checkPresetsAssets,
checkAssetsCount,
getPermission,
fetchOps,
nameFetchOps,
} from '../../../../../../common';
export default function fileAssetTestPromiseTest(abilityContext) {
describe('fileAssetTestPromiseTest', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
await checkPresetsAssets(media, 'ActsMediaLibraryFileKey')
await checkPresetsAssets(media, 'ActsMediaLibraryFileAsset')
});
beforeEach(function () { });
afterEach(async function () {
......
......@@ -32,7 +32,7 @@ export default function fetchFileResultCallbackTest(abilityContext) {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryAlbumFileResultCb');
await checkPresetsAssets(media, 'ActsMediaLibraryFileResult');
});
beforeEach(function () { });
afterEach(async function () {
......
......@@ -33,7 +33,7 @@ export default function fetchFileResultPromiseTest(abilityContext) {
describe('fetchFileResultPromiseTest', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
await checkPresetsAssets(media, 'ActsMediaLibraryAlbumFileResultPro');
await checkPresetsAssets(media, 'ActsMediaLibraryFileResult');
});
beforeEach(function () { });
afterEach(async function () {
......
......@@ -13,15 +13,7 @@
* limitations under the License.
*/
import getPermissionTest from './getPermission.test.ets'
import fileAssetCallBack2Test from './fileAssetCallBack2.test.ets'
import fileAssetTestCallbackTest from './fileAssetTestCallback.test.ets'
import fileTestCallBackTest from './fileTestCallBack.test.ets'
import mediaLibraryTestCallBackTest from './mediaLibraryTestCallBack.test.ets'
export default function testsuite(abilityContext) {
getPermissionTest()
fileAssetCallBack2Test(abilityContext)
fileAssetTestCallbackTest(abilityContext)
fileTestCallBackTest(abilityContext)
mediaLibraryTestCallBackTest(abilityContext)
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import featureAbility from '@ohos.ability.featureAbility';
import {
sleep,
} from '../../../../../../common';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
function printAttr(asset) {
for (const key in asset) {
console.info(`${key}: asset[key]`);
}
}
function checkAttrs(done, asset, tNum) {
let passed = true;
for (const key in asset) {
if (asset[key] == undefined) {
passed = false;
break;
}
}
if (passed) {
console.info(`FileAsset checkAttrs ${tNum} passed`);
expect(true).assertTrue();
done();
} else {
console.info(`FileAsset checkAttrs ${tNum} failed`);
expect(false).assertTrue();
done();
}
}
export default function fileAssetCallBack2Test(abilityContext){
describe('fileAssetCallBack2Test', function () {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let imagesfetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Pictures/Dynamic/', imageType.toString()],
};
let videosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
};
let audiosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
};
let allTypefetchOp = {
selections: '',
selectionArgs: [],
};
const context = featureAbility.getContext();
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(function () { });
beforeEach(function () { });
afterEach(async function () { await sleep(200)});
afterAll(function () { });
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_001
* @tc.name : commitModify
* @tc.desc : Modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_callback_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const newName = 'newName' + new Date().getTime() + '.jpg';
asset.displayName = newName;
const id = asset.id;
asset.commitModify(async () => {
let currentfetchOp = {
selections: fileKeyObj.ID + '= ?',
selectionArgs: [id + ''],
};
const fetchFileResult2 = await media.getFileAssets(currentfetchOp);
const currentAsset = await fetchFileResult2.getFirstObject();
expect(currentAsset.displayName == newName).assertTrue();
done();
});
} catch (error) {
console.info('FileAsset commitModify 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_002
* @tc.name : commitModify
* @tc.desc : Modify title
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_callback_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const newTitle = 'newTitle' + new Date().getTime();
asset.title = newTitle;
const id = asset.id;
asset.commitModify(async () => {
let currentfetchOp = {
selections: fileKeyObj.ID + '= ?',
selectionArgs: [id + ''],
};
const fetchFileResult2 = await media.getFileAssets(currentfetchOp);
const currentAsset = await fetchFileResult2.getFirstObject();
expect(currentAsset.title == newTitle).assertTrue();
done();
});
} catch (error) {
console.info('FileAsset commitModify 002 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_003
* @tc.name : commitModify
* @tc.desc : Modify relativePath
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_callback_003', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
let newrelativePath = 'Pictures/Temp/';
asset.relativePath = newrelativePath;
const id = asset.id;
asset.commitModify(async () => {
let currentfetchOp = {
selections: fileKeyObj.ID + '= ?',
selectionArgs: [id + ''],
};
const fetchFileResult2 = await media.getFileAssets(currentfetchOp);
const currentAsset = await fetchFileResult2.getFirstObject();
expect(currentAsset.relativePath == newrelativePath).assertTrue();
done();
});
} catch (error) {
console.info('FileAsset commitModify 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_callback_004
* @tc.name : commitModify
* @tc.desc : Modify orientation
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_callback_004', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
let neworientation = 1;
if (asset.orientation == 1) {
neworientation = 0;
}
asset.orientation = neworientation;
const id = asset.id;
asset.commitModify(async () => {
let currentfetchOp = {
selections: fileKeyObj.ID + '= ?',
selectionArgs: [id + ''],
};
const fetchFileResult2 = await media.getFileAssets(currentfetchOp);
const currentAsset = await fetchFileResult2.getFirstObject();
expect(currentAsset.orientation == neworientation).assertTrue();
done();
});
} catch (error) {
console.info('FileAsset commitModify 004 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_isDirectory_callback_001
* @tc.name : isDirectory
* @tc.desc : isDirectory asset
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_isDirectory_callback_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.isDirectory((err, isDir) => {
if (isDir == undefined) {
expect(false).assertTrue();
done();
} else {
expect(!isDir).assertTrue();
done();
}
});
} catch (error) {
console.info('FileAsset isDirectory 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_001
* @tc.name : attrs
* @tc.desc : imagesfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_callback_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
fetchFileResult.getFirstObject((err, asset) => {
if (asset == undefined) {
expect(false).assertTrue();
done();
} else {
printAttr(asset);
checkAttrs(done, asset, '001');
}
});
} catch (error) {
console.info('FileAsset checkAttr 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_002
* @tc.name : attrs
* @tc.desc : videosfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_callback_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(videosfetchOp);
fetchFileResult.getFirstObject((err, asset) => {
if (asset == undefined) {
expect(false).assertTrue();
done();
} else {
printAttr(asset);
checkAttrs(done, asset, '002');
}
});
} catch (error) {
console.info('FileAsset checkAttr 002 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_003
* @tc.name : attrs
* @tc.desc : audiosfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_callback_003', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(audiosfetchOp);
fetchFileResult.getFirstObject((err, asset) => {
if (asset == undefined) {
expect(false).assertTrue();
done();
} else {
printAttr(asset);
checkAttrs(done, asset, '003');
}
});
} catch (error) {
console.info('FileAsset checkAttr 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_callback_004
* @tc.name : attrs
* @tc.desc : album attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_callback_004', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
fetchFileResult.getFirstObject((err, asset) => {
if (asset == undefined) {
expect(false).assertTrue();
done();
} else {
printAttr(asset);
checkAttrs(done, asset, '004');
}
});
} catch (error) {
console.info('FileAsset checkAttr 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册