未验证 提交 290eb0be 编写于 作者: O openharmony_ci 提交者: Gitee

!5732 【userfile_manager】update xts

Merge pull request !5732 from yangbo/0927_xts
......@@ -16,17 +16,21 @@
import userfile_manager from '@ohos.filemanagement.userfile_manager';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import bundle from '@ohos.bundle';
import dataSharePredicates from '@ohos.data.dataSharePredicates';
const presetsCount = {
ActsUserFileMgrAlbumJsTest: { albumsCount: 9, assetsCount: 9 },
ActsUserFileMgrBaseJsTest: { albumsCount: 42, assetsCount: 84 },
ActsUserFileMgrAlbumJsTest: { albumsCount: 3, assetsCount: 3 },
ActsUserFileMgrBaseJsTest: { albumsCount: 9, assetsCount: 18 },
ActsUserFileMgrFileAssetJsTest: { albumsCount: 45, assetsCount: 87 },
}
const IMAGE_TYPE = userfile_manager.MediaType.IMAGE;
const VIDEO_TYPE = userfile_manager.MediaType.VIDEO;
const AUDIO_TYPE = userfile_manager.MediaType.AUDIO;
const FILEKEY = userfile_manager.FileKey;
const AUDIOKEY = userfile_manager.AudioKey;
const IMAGEVIDEOKEY = userfile_manager.ImageVideoKey;
const ALBUMKEY = userfile_manager.AlbumKey;
const sleep = async function sleep(times) {
if (times == undefined) {
times = 10
......@@ -35,59 +39,86 @@ const sleep = async function sleep(times) {
}
const allFetchOp = function () {
let predicates = new dataSharePredicates.DataSharePredicates();
return {
selections: '',
selectionArgs: [],
predicates: predicates
};
}
const fetchOps = function (testNum, path) {
const audioFetchOps = function (testNum, path) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(AUDIOKEY.RELATIVE_PATH, path);
let ops = {
selections: 'relative_path' + '= ?',
selectionArgs: [path],
predicates: predicates
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
console.info(`${testNum} queryOps: relative_path = ${path}`);
return ops
}
const nameFetchOps = function (testNum, path, displayName) {
const imageVideoFetchOps = function (testNum, path) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(IMAGEVIDEOKEY.RELATIVE_PATH, path);
let ops = {
predicates: predicates
};
console.info(`${testNum} queryOps: relative_path = ${path}`);
return ops
}
const audioNameFetchOps = function (testNum, path, displayName) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(AUDIOKEY.RELATIVE_PATH, path)
.equalTo(AUDIOKEY.DISPLAY_NAME, displayName);
let ops = {
selections: 'relative_path' + '= ? AND ' + FILEKEY.DISPLAY_NAME + '= ?',
selectionArgs: [path, displayName],
predicates: predicates
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
console.info(`${testNum} queryOps: relative_path = ${path} AND display_name = ${displayName}`);
return ops
}
const imageVideoNameFetchOps = function (testNum, path, displayName) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(IMAGEVIDEOKEY.RELATIVE_PATH, path)
.equalTo(IMAGEVIDEOKEY.DISPLAY_NAME, displayName);
let ops = {
predicates: predicates
};
console.info(`${testNum} queryOps: relative_path = ${path} AND display_name = ${displayName}`);
return ops
}
const albumFetchOps = function (testNum, path, albumName) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(ALBUMKEY.RELATIVE_PATH, path)
.equalTo("bucket_display_name", albumName);
let ops = {
selections: 'relative_path' + '= ? AND ' + 'bucket_display_name' + '= ?',
selectionArgs: [path, albumName],
predicates: predicates
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
console.info(`${testNum} queryOps: relative_path = ${path} AND bucket_display_name = ${albumName}`);
return ops
}
const checkPresetsAssets = async function (userfilemgr, hapName) {
console.info('checkPresetsAssets start')
let albumList = await userfilemgr.getAlbums([IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE], allFetchOp());
let albumsCount = albumList.length;
let fetchFileResult = await userfilemgr.getFileAssets([IMAGE_TYPE, VIDEO_TYPE, AUDIO_TYPE],
allFetchOp());
let assetsCount = await fetchFileResult.getCount();
let fetchAlbumResult = await userfilemgr.getPhotoAlbums(allFetchOp());
let albumsCount = fetchAlbumResult.getCount();
let fetchPhotoResult = await userfilemgr.getPhotoAssets(allFetchOp());
let fetchAudioResult = await userfilemgr.getAudioAssets(allFetchOp());
let assetsCount = fetchPhotoResult.getCount() + fetchAudioResult.getCount();
console.info(`${hapName}:: assetsCount: ${assetsCount} albumsCount: ${albumsCount},
presetsassetsCount: ${presetsCount[hapName].assetsCount}
presetsalbumsCount: ${presetsCount[hapName].albumsCount}`);
console.info('checkPresetsAssets end')
}
const checkAssetsCount = async function (done, testNum, fetchFileResult, expectCount) {
if (!fetchFileResult) {
console.info(`${testNum}:: fetchFileResult error:`);
const checkAssetsCount = async function (done, testNum, fetchAssetResult, expectCount) {
if (!fetchAssetResult) {
console.info(`${testNum}:: fetchAssetResult is undefined`);
expect(false).assertTrue();
done();
return false
}
let count = await fetchFileResult.getCount();
let count = await fetchAssetResult.getCount();
if (count != expectCount) {
console.info(`${testNum}:: count:expectCount - ${count} : ${expectCount}`);
expect(count).assertEqual(expectCount);
......@@ -96,22 +127,6 @@ const checkAssetsCount = async function (done, testNum, fetchFileResult, expectC
return count == expectCount;
}
const checkAlbumsCount = function (done, testNum, albumList, expectCount) {
if (!Array.isArray(albumList)) {
console.info(`${testNum}:: albumList error:`);
expect(false).assertTrue();
done();
return false
}
let albumsCount = albumList.length;
if (albumsCount != expectCount) {
console.info(`${testNum}:: albumsCount: expectCount - ${albumsCount} : ${expectCount}`);
expect(albumsCount).assertEqual(expectCount);
done();
}
return albumsCount == expectCount;
}
const getPermission = async function (name = 'ohos.acts.multimedia.userfilemgr') {
console.info('getPermission start', name)
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.userfilemgr', 0, 100);
......@@ -148,14 +163,14 @@ export {
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILEKEY,
sleep,
allFetchOp,
fetchOps,
nameFetchOps,
audioFetchOps,
imageVideoFetchOps,
audioNameFetchOps,
imageVideoNameFetchOps,
albumFetchOps,
checkPresetsAssets,
checkAssetsCount,
checkAlbumsCount,
isNum,
};
\ No newline at end of file
......@@ -15,7 +15,7 @@
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
"mkdir -p /storage/media/100/local/temp"
]
},
{
......@@ -23,9 +23,9 @@
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
"./resource/medialibrary/01.jpg ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp3 ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp4 ->/storage/media/100/local/temp"
]
},
{
......@@ -35,9 +35,9 @@
"mkdir -pv /storage/media/100/local/files/Audios/{Static,DynamicCb,DynamicPro}",
"mkdir -pv /storage/media/100/local/files/Videos/{Static,DynamicCb,DynamicPro}",
"for d in Static DynamicCb DynamicPro; do for i in $$(seq 1); 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 DynamicCb DynamicPro; do for i in $$(seq 1); 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 DynamicCb DynamicPro; do for i in $$(seq 1); 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 DynamicCb DynamicPro; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static DynamicCb DynamicPro; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static DynamicCb DynamicPro; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"chmod -R 777 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
......
......@@ -18,23 +18,20 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
checkAssetsCount,
getPermission,
} from '../../../../../../common';
export default function albumCommitModifyCallback(abilityContext) {
describe('albumCommitModifyCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbumJsTest');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrAlbumJsTest');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -47,19 +44,19 @@ export default function albumCommitModifyCallback(abilityContext) {
console.info('afterAll case');
});
const albumCommitModify = async function (done, testNum, media_type, fetchOp, expectAlbumCount) {
const albumCommitModify = async function (done, testNum, fetchOp, expectAlbumCount = 1) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
const fetchAlbumResult = await userfilemgr.getPhotoAlbums(fetchOp);
const albumCountPass = await checkAssetsCount(done, testNum, fetchAlbumResult, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
const newName = 'albumName' + media_type.toString();
const album = await fetchAlbumResult.getFirstObject();
const newName = 'newAlbumNameCallback';
fetchAlbumResult.close();
album.albumName = newName;
album.commitModify(async () => {
expect(true).assertTrue();
done();
});
} catch (error) {
console.info(`${testNum}, failed error: ${error}`)
expect(false).assertTrue();
......@@ -77,42 +74,8 @@ export default function albumCommitModifyCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'DynamicCb');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_02
* @tc.name : commitModify
* @tc.desc : image album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_02', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'DynamicCb');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_03
* @tc.name : commitModify
* @tc.desc : image album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_03', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'DynamicCb');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
await albumCommitModify(done, testNum, currentFetchOp);
});
});
}
......
......@@ -18,23 +18,20 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
checkAssetsCount,
getPermission,
} from '../../../../../../common';
export default function albumCommitModifyPromise(abilityContext) {
describe('albumCommitModifyPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbumJsTest');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrAlbumJsTest');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -47,13 +44,14 @@ export default function albumCommitModifyPromise(abilityContext) {
console.info('afterAll case');
});
const albumCommitModify = async function (done, testNum, media_type, fetchOp, expectAlbumCount) {
const albumCommitModify = async function (done, testNum, fetchOp, expectAlbumCount = 1) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
const fetchAlbumResult = await userfilemgr.getPhotoAlbums(fetchOp);
const albumCountPass = await checkAssetsCount(done, testNum, fetchAlbumResult, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
const newName = 'albumName' + media_type.toString();
const album = await fetchAlbumResult.getFirstObject();
const newName = 'newAlbumNamePromise';
fetchAlbumResult.close();
album.albumName = newName;
await album.commitModify();
expect(true).assertTrue();
......@@ -68,49 +66,15 @@ export default function albumCommitModifyPromise(abilityContext) {
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01
* @tc.name : commitModify
* @tc.desc : image album modify albumname
* @tc.desc : album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'DynamicPro');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_02
* @tc.name : commitModify
* @tc.desc : audio album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_02', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'DynamicPro');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_03
* @tc.name : commitModify
* @tc.desc : video album modify albumname
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_03', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'DynamicPro');
let expectAlbumCount = 1;
await albumCommitModify(done, testNum, media_type, currentFetchOp, expectAlbumCount);
await albumCommitModify(done, testNum, currentFetchOp);
});
});
}
......
......@@ -17,22 +17,18 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILEKEY,
allFetchOp,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
checkAssetsCount,
} from '../../../../../../common';
export default function albumGetFileAssetsCallback(abilityContext) {
describe('albumGetFileAssetsCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbumJsTest');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrAlbumJsTest');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -45,23 +41,24 @@ export default function albumGetFileAssetsCallback(abilityContext) {
console.info('afterAll case');
});
const checkAlbumAssetsCount = async function (done, testNum, media_type, fetchOp, expectAssetsCount, expectAlbumCount = 1) {
const checkAlbumAssetsCount = async function (done, testNum, fetchOp, expectAlbumCount = 1, expectAssetsCount = 1) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
// check album length
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
const fetchAlbumResult = await userfilemgr.getPhotoAlbums(fetchOp);
const albumCountPass = await checkAssetsCount(done, testNum, fetchAlbumResult, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
album.getFileAssets(media_type, allFetchOp(), (error, fetchFileResult) => {
const album = await fetchAlbumResult.getFirstObject();
fetchAlbumResult.close();
album.getPhotoAssets(allFetchOp(), (error, fetchAssetResult) => {
if (error != undefined) {
console.info(`${testNum} fetchFileResult error: ${error}`);
console.info(`${testNum} getPhotoAssets error: ${error}`);
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}
console.info(`${testNum}, getCount: ${fetchAssetResult.getCount()}
expectAssetsCount: ${expectAssetsCount}`);
expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount);
expect(fetchAssetResult.getCount()).assertEqual(expectAssetsCount);
fetchAssetResult.close();
done();
});
} catch (error) {
......@@ -72,51 +69,17 @@ export default function albumGetFileAssetsCallback(abilityContext) {
}
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_01
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in IMAGE_TYPE
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETPHOTOASSETS_CALLBACK_01
* @tc.name : getPhotoAssets
* @tc.desc : Album getPhotoAssets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_01';
let media_type = [IMAGE_TYPE];
it('SUB_USERFILE_MGR_ALBUM_GETPHOTOASSETS_CALLBACK_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETPHOTOASSETS_CALLBACK_01';
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_02
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in AUDIO_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_02', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_03
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in VIDEO_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_03', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
await checkAlbumAssetsCount(done, testNum, currentFetchOp);
});
});
}
\ No newline at end of file
......@@ -19,22 +19,18 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILEKEY,
allFetchOp,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
checkAssetsCount,
} from '../../../../../../common';
export default function albumGetFileAssetsPromise(abilityContext) {
describe('albumGetFileAssetsPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbumJsTest');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrAlbumJsTest');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -47,30 +43,24 @@ export default function albumGetFileAssetsPromise(abilityContext) {
console.info('afterAll case');
});
// Exception request
const abnormalFetchOp = {
selections: 'date_added < 0',
selectionArgs: [],
order: 'date_added DESC LIMIT 0,1',
}
const checkAlbumAssetsCount = async function (done, testNum, media_type, fetchOp, expectAssetsCount, expectAlbumCount = 1) {
const checkAlbumAssetsCount = async function (done, testNum, fetchOp, expectAlbumCount = 1, expectAssetsCount = 1) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
// check album length
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
const fetchAlbumResult = await userfilemgr.getPhotoAlbums(fetchOp);
const albumCountPass = await checkAssetsCount(done, testNum, fetchAlbumResult, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
const album = await fetchAlbumResult.getFirstObject();
fetchAlbumResult.close();
let op: userfile_manager.MediaFetchOptions = allFetchOp();
let fetchFileResult = await album.getFileAssets(media_type, op);
if (fetchFileResult == undefined) {
let fetchAssetResult = await album.getPhotoAssets(op);
if (fetchAssetResult == undefined) {
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}
console.info(`${testNum}, getCount: ${fetchAssetResult.getCount()}
expectAssetsCount: ${expectAssetsCount}`)
expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount);
expect(fetchAssetResult.getCount()).assertEqual(expectAssetsCount);
fetchAssetResult.close();
done();
} catch (error) {
console.info(`${testNum}, error: ${error}`);
......@@ -80,51 +70,17 @@ export default function albumGetFileAssetsPromise(abilityContext) {
}
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_01
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in IMAGE_TYPE
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETPHOTOASSETS_PROMISE_01
* @tc.name : getPhotoAssets
* @tc.desc : Album getPhotoAssets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_01';
let media_type = [IMAGE_TYPE];
it('SUB_USERFILE_MGR_ALBUM_GETPHOTOASSETS_PROMISE_01', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETPHOTOASSETS_PROMISE_01';
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_02
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in AUDIO_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_02', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_03
* @tc.name : getFileAssets
* @tc.desc : Album getFileAssets in VIDEO_TYPE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_03', 0, async function (done) {
const testNum = 'SUB_USERFILE_MGR_ALBUM_GETFILEASSETS_PROMISE_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'Static');
let assetsCount = 1;
await checkAlbumAssetsCount(done, testNum, media_type, currentFetchOp, assetsCount);
await checkAlbumAssetsCount(done, testNum, currentFetchOp);
});
});
}
\ No newline at end of file
......@@ -15,7 +15,7 @@
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
"mkdir -p /storage/media/100/local/temp"
]
},
{
......@@ -23,21 +23,28 @@
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
"./resource/medialibrary/01.jpg ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp3 ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp4 ->/storage/media/100/local/temp",
"./resource/medialibrary/01.dat ->/storage/media/100/local/temp"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/Static",
"mkdir -pv /storage/media/100/local/files/Videos/Static",
"mkdir -pv /storage/media/100/local/files/Audios/Static",
"mkdir -pv /storage/media/100/local/files/Pictures/{Static,On,Off}",
"mkdir -pv /storage/media/100/local/files/Videos/{Static,On,Off}",
"mkdir -pv /storage/media/100/local/files/Audios/{Static,On,Off}",
"mkdir -pv /storage/media/100/local/files/Documents/{Static,On,Off}",
"for d in Static; do for i in $$(seq 1); 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 1); 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 1); 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 4); do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static; do for i in $$(seq 4); do cp /storage/media/100/local/temp/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static; do for i in $$(seq 4); do cp /storage/media/100/local/temp/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in Static; do for i in $$(seq 4); do cp /storage/media/100/local/temp/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"for d in On Off; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in On Off; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in On Off; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in On Off; do for i in $$(seq 1); do cp /storage/media/100/local/temp/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,15 +13,21 @@
* limitations under the License.
*/
import getAlbumsCallback from './getAlbumsCallback.test.ets'
import getAlbumsPromise from './getAlbumsPromise.test.ets'
import getFileAssetsCallback from './getFileAssetsCallback.test.ets'
import getFileAssetsPromise from './getFileAssetsPromise.test.ets'
import getUserFileMgr from './getUserFileMgr.test.ets'
import getAlbumsCallbackTest from './getAlbumsCallback.test.ets'
import getAlbumsPromiseTest from './getAlbumsPromise.test.ets'
import getFileAssetsCallbackTest from './getFileAssetsCallback.test.ets'
import getFileAssetsPromiseTest from './getFileAssetsPromise.test.ets'
import getPublicDirectoryCallbackTest from './getPublicDirectoryCallback.test.ets'
import getPublicDirectoryPromiseTest from './getPublicDirectoryPromise.test.ets'
import getUserFileMgrTest from './getUserFileMgr.test.ets'
import onOffReleasePromiseTest from './onOffReleasePromise.test.ets'
export default function testsuite(abilityContext) {
getAlbumsCallback(abilityContext)
getAlbumsPromise(abilityContext)
getFileAssetsCallback(abilityContext)
getFileAssetsPromise(abilityContext)
getUserFileMgr(abilityContext)
getAlbumsCallbackTest(abilityContext)
getAlbumsPromiseTest(abilityContext)
getFileAssetsCallbackTest(abilityContext)
getFileAssetsPromiseTest(abilityContext)
getPublicDirectoryCallbackTest(abilityContext)
getPublicDirectoryPromiseTest(abilityContext)
getUserFileMgrTest(abilityContext)
onOffReleasePromiseTest(abilityContext)
}
......@@ -18,24 +18,21 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
allFetchOp,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
checkAssetsCount,
getPermission,
isNum,
} from '../../../../../../common';
export default function getAlbumsCallback(abilityContext) {
describe('getAlbumsCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function getAlbumsCallbackTest(abilityContext) {
describe('getAlbumsCallbackTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbumJsTest');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrAlbumJsTest');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -59,8 +56,8 @@ export default function getAlbumsCallback(abilityContext) {
}
const props = {
albumName: 'Static',
albumUri: 'datashare:///userfile_mgr/album/',
albumName: 'myAlbum',
albumUri: 'datashare:///userfilemgr/album/',
count: 1
}
const checkProps = async function (done, testNum, album, relativePaths) {
......@@ -73,6 +70,7 @@ export default function getAlbumsCallback(abilityContext) {
}
expect(album.albumName).assertEqual(props.albumName);
expect(album.count).assertEqual(props.count);
expect(isNum(album.dateModified)).assertTrue();
if (Array.isArray(relativePaths)) {
let i = relativePaths.indexOf(album.relativePath);
if (i > -1) {
......@@ -85,19 +83,21 @@ export default function getAlbumsCallback(abilityContext) {
expect(album.relativePath).assertEqual(relativePaths);
}
}
const checkAlbumInfo = async function (done, testNum, media_type, fetchOp, relativePaths, expectAlbumCount) {
const checkAlbumInfo = async function (done, testNum, fetchOp, relativePaths) {
try {
userfile_mgr.getAlbums(media_type, fetchOp, async (err, albumList) => {
userfilemgr.getPhotoAlbums(fetchOp, async (err, fetchAlbumResult) => {
if(err) {
console.info(`${testNum}, err: ${err}`)
console.info(`${testNum} getPhotoAlbums err: ${err}`)
expect(false).assertTrue();
done();
return;
}
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
let expectAlbumCount = 1;
const albumCountPass = await checkAssetsCount(done, testNum, fetchAlbumResult, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
const album = await fetchAlbumResult.getFirstObject();
checkProps(done, testNum, album, relativePaths);
fetchAlbumResult.close();
done();
});
} catch (error) {
......@@ -108,84 +108,18 @@ export default function getAlbumsCallback(abilityContext) {
}
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_CALLBACK_01
* @tc.name : getAlbums
* @tc.desc : Image type getAlbums by relativePath && albumName, print all album info
* @tc.number : SUB_USERFILE_MGR_GETPHOTOALBUMS_CALLBACK_01
* @tc.name : getPhotoAlbums
* @tc.desc : getPhotoAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'Static');
it('SUB_USERFILE_MGR_GETPHOTOALBUMS_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPHOTOALBUMS_CALLBACK_01';
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'myAlbum');
let relativePaths = 'Pictures/';
let expectAlbumCount = 1;
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_CALLBACK_02
* @tc.name : getAlbums
* @tc.desc : Audio type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'Static');
let relativePaths = 'Audios/';
let expectAlbumCount = 1;
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_CALLBACK_03
* @tc.name : getAlbums
* @tc.desc : Video type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'Static');
let relativePaths = 'Videos/';
let expectAlbumCount = 1;
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths, expectAlbumCount);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_CALLBACK_04
* @tc.name : getAlbums
* @tc.desc : getAlbums by abnormal
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_CALLBACK_04', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_CALLBACK_04';
try {
let media_type = [-1];
let currentFetchOp = allFetchOp();
userfile_mgr.getAlbums(media_type, currentFetchOp, async (err, albumList) => {
console.info(`${testNum}, err: ${err}`);
if (err != undefined) {
expect(true).assertTrue();
done();
return;
}
expect(false).assertTrue();
done();
});
} catch (error) {
console.info(`${testNum}, error: ${error}`);
expect(true).assertTrue();
done();
}
await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths);
});
});
}
......
......@@ -18,21 +18,17 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
allFetchOp,
albumFetchOps,
checkPresetsAssets,
checkAlbumsCount,
checkAssetsCount,
} from '../../../../../../common';
export default function getAlbumsPromise(abilityContext) {
describe('getAlbumsPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function getAlbumsPromiseTest(abilityContext) {
describe('getAlbumsPromiseTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrAlbumJsTest');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrAlbumJsTest');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -56,8 +52,8 @@ export default function getAlbumsPromise(abilityContext) {
}
const props = {
albumName: 'Static',
albumUri: 'datashare:///userfile_mgr/album/',
albumName: 'myAlbum',
albumUri: 'datashare:///userfilemgr/album/',
count: 1
}
const checkProps = async function (done, testNum, album, relativePaths) {
......@@ -82,13 +78,14 @@ export default function getAlbumsPromise(abilityContext) {
expect(album.relativePath).assertEqual(relativePaths);
}
}
const checkAlbumInfo = async function (done, testNum, media_type, fetchOp, relativePaths, expectAlbumCount = 1) {
const checkAlbumInfo = async function (done, testNum, fetchOp, relativePaths, expectAlbumCount = 1) {
try {
const albumList = await userfile_mgr.getAlbums(media_type, fetchOp);
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
const fetchAlbumResult = await userfilemgr.getPhotoAlbums(fetchOp);
const albumCountPass = await checkAssetsCount(done, testNum, fetchAlbumResult, expectAlbumCount);
if (!albumCountPass) return;
const album = albumList[0];
const album = await fetchAlbumResult.getFirstObject();
checkProps(done, testNum, album, relativePaths);
fetchAlbumResult.close();
done();
} catch (error) {
console.info(`${testNum}, failed: ${error}`);
......@@ -98,80 +95,18 @@ export default function getAlbumsPromise(abilityContext) {
}
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_PROMISE_01
* @tc.name : getAlbums
* @tc.desc : Image type getAlbums by relativePath && albumName, print all album info
* @tc.number : SUB_USERFILE_MGR_GETPHOTOALBUMS_PROMISE_01
* @tc.name : getPhotoAlbums
* @tc.desc : getPhotoAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_PROMISE_01';
let media_type = [IMAGE_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'Static');
it('SUB_USERFILE_MGR_GETPHOTOALBUMS_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPHOTOALBUMS_PROMISE_01';
let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'myAlbum');
let relativePaths = 'Pictures/';
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_PROMISE_02
* @tc.name : getAlbums
* @tc.desc : Image type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_PROMISE_02';
let media_type = [AUDIO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Audios/', 'Static');
let relativePaths = 'Audios/';
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_PROMISE_03
* @tc.name : getAlbums
* @tc.desc : Image type getAlbums by relativePath && albumName, print all album info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_PROMISE_03';
let media_type = [VIDEO_TYPE];
let currentFetchOp = albumFetchOps(testNum, 'Videos/', 'Static');
let relativePaths = 'Videos/';
await checkAlbumInfo(done, testNum, media_type, currentFetchOp, relativePaths);
});
/**
* @tc.number : SUB_USERFILE_MGR_GETALBUMS_PROMISE_04
* @tc.name : getAlbums
* @tc.desc : getAlbums by abnormal
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETALBUMS_PROMISE_04', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETALBUMS_PROMISE_04';
try {
let media_type = [-1];
let currentFetchOp = allFetchOp();
try {
await userfile_mgr.getAlbums(media_type, currentFetchOp);
expect(false).assertTrue();
done();
} catch (error) {
console.info(`${testNum}, error1: ${error}`);
expect(true).assertTrue();
done();
}
} catch (error) {
console.info(`${testNum}, error2: ${error}`);
expect(false).assertTrue();
done();
}
await checkAlbumInfo(done, testNum, currentFetchOp, relativePaths);
});
});
}
......
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
} from '../../../../../../common';
export default function getPublicDirectoryCallbackTest(abilityContext) {
describe('getPublicDirectoryCallbackTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const getPublicDirectoryTest = async (done, testNum, dir, val) => {
try {
userfilemgr.getPublicDirectory(dir, async (err, res) => {
if (err) {
console.info(`${testNum} err : ${err}`)
expect.assertFail();
done();
return;
}
expect(res).assertEqual(val);
done();
});
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_01
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_CAMERA
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_01';
let dir = userfile_manager.DirectoryType.DIR_CAMERA;
let val = 'Camera/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_02
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_VIDEO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_02';
let dir = userfile_manager.DirectoryType.DIR_VIDEO;
let val = 'Videos/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_03
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_03';
let dir = userfile_manager.DirectoryType.DIR_IMAGE;
let val = 'Pictures/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_04
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_AUDIO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_04', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_04';
let dir = userfile_manager.DirectoryType.DIR_AUDIO;
let val = 'Audios/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_05
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_05', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_05';
let dir = userfile_manager.DirectoryType.DIR_DOCUMENTS;
let val = 'Documents/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_06
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_DOWNLOAD
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_06', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_CALLBACK_06';
let dir = userfile_manager.DirectoryType.DIR_DOWNLOAD;
let val = 'Download/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
} from '../../../../../../common';
export default function getPublicDirectoryPromiseTest(abilityContext) {
describe('getPublicDirectoryPromiseTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const getPublicDirectoryTest = async (done, testNum, dir, val) => {
try {
let res = await userfilemgr.getPublicDirectory(dir);
expect(res).assertEqual(val);
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_01
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_CAMERA
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_01';
let dir = userfile_manager.DirectoryType.DIR_CAMERA;
let val = 'Camera/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_02
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_VIDEO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_02';
let dir = userfile_manager.DirectoryType.DIR_VIDEO;
let val = 'Videos/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_03
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_03';
let dir = userfile_manager.DirectoryType.DIR_IMAGE;
let val = 'Pictures/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_04
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_AUDIO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_04', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_04';
let dir = userfile_manager.DirectoryType.DIR_AUDIO;
let val = 'Audios/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_05
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_05', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_05';
let dir = userfile_manager.DirectoryType.DIR_DOCUMENTS;
let val = 'Documents/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
/**
* @tc.number : SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_06
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_DOWNLOAD
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_06', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_GETPUBLICDIRECTORY_PROMISE_06';
let dir = userfile_manager.DirectoryType.DIR_DOWNLOAD;
let val = 'Download/';
await getPublicDirectoryTest(done, testNum, dir, val)
});
});
}
......@@ -17,9 +17,9 @@ import userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import { sleep } from '../../../../../../common';
export default function getUserFileMgr(abilityContext) {
describe('getUserFileMgr', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function getUserFileMgrTest(abilityContext) {
describe('getUserFileMgrTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
});
......@@ -44,7 +44,7 @@ export default function getUserFileMgr(abilityContext) {
*/
it('SUB_USERFILE_MGR_GETUSERFILEMGR_00', 0, async function (done) {
try {
expect(userfile_mgr != undefined).assertTrue();
expect(userfilemgr != undefined).assertTrue();
done();
} catch (error) {
console.info(`SUB_USERFILE_MGR_GETUSERFILEMGR_00 failed, error: ${error}`);
......
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
audioFetchOps,
imageVideoFetchOps,
checkPresetsAssets,
checkAssetsCount,
} from '../../../../../../common';
export default function onOffReleasePromiseTest(abilityContext) {
describe('onOffReleasePromiseTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrAlbumJsTest');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const onTest = async (done, testNum, fetchOp, type, newName, isAudio) => {
try {
let count = 0;
userfilemgr.on(type, () => { count++; });
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchAssetResult.getFirstObject();
fetchAssetResult.close();
asset.displayName = newName;
await asset.commitModify();
await sleep(1000)
expect(count > 0).assertTrue();
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
const offTest = async (done, testNum, fetchOp, type, newName, isAudio) => {
try {
let count = 0;
userfilemgr.on(type, () => {
count++;
});
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchAssetResult.getFirstObject();
fetchAssetResult.close();
asset.displayName = newName;
userfilemgr.off(type);
await asset.commitModify();
await sleep(1000)
expect(count).assertEqual(0);
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_ON_PROMISE_01
* @tc.name : ON
* @tc.desc : ON image ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ON_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_ON_PROMISE_01';
let currentFetchOps = imageVideoFetchOps(testNum, 'Pictures/On/');
let type = 'imageChange';
let newName = 'imageChange.jpg';
let isAudio = false;
await onTest(done, testNum, currentFetchOps, type, newName, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_ON_PROMISE_02
* @tc.name : ON
* @tc.desc : ON audio ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ON_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_ON_PROMISE_02';
let currentFetchOps = audioFetchOps(testNum, 'Audios/On/');
let type = 'audioChange';
let newName = 'audioChange.mp3';
let isAudio = true;
await onTest(done, testNum, currentFetchOps, type, newName, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_ON_PROMISE_03
* @tc.name : ON
* @tc.desc : ON video ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_ON_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_ON_PROMISE_03';
let currentFetchOps = imageVideoFetchOps(testNum, 'Videos/On/');
let type = 'videoChange';
let newName = 'videoChange.mp4';
let isAudio = false;
await onTest(done, testNum, currentFetchOps, type, newName, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_OFF_PROMISE_01
* @tc.name : off
* @tc.desc : off image ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_OFF_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_OFF_PROMISE_01';
let currentFetchOps = imageVideoFetchOps(testNum, 'Pictures/Off/');
let type = 'imageChange';
let newName = 'imageChange.jpg';
let isAudio = false;
await offTest(done, testNum,currentFetchOps, type, newName, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_OFF_PROMISE_02
* @tc.name : off
* @tc.desc : off audio ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_OFF_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_OFF_PROMISE_02';
let currentFetchOps = audioFetchOps(testNum, 'Audios/Off/');
let type = 'audioChange';
let newName = 'audioChange.mp3';
let isAudio = true;
await offTest(done, testNum,currentFetchOps, type, newName, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_OFF_PROMISE_03
* @tc.name : off
* @tc.desc : off video ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_OFF_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_OFF_PROMISE_03';
let currentFetchOps = imageVideoFetchOps(testNum, 'Videos/Off/');
let type = 'videoChange';
let newName = 'videoChange.mp4';
let isAudio = false;
await offTest(done, testNum,currentFetchOps, type, newName, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_PROMISE_PROMISE_01
* @tc.name : release
* @tc.desc : Release MediaLibrary instance
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_PROMISE_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_PROMISE_PROMISE_01';
try {
await userfilemgr.release();
expect(true).assertTrue();
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
});
});
}
......@@ -15,7 +15,7 @@
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
"mkdir -p /storage/media/100/local/temp"
]
},
{
......@@ -23,29 +23,34 @@
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
"./resource/medialibrary/01.jpg ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp3 ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp4 ->/storage/media/100/local/temp",
"./resource/medialibrary/01.dat ->/storage/media/100/local/temp"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"mkdir -pv /storage/media/100/local/files/Videos/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"mkdir -pv /storage/media/100/local/files/Audios/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"mkdir -pv /storage/media/100/local/files/Pictures/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,Static,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"mkdir -pv /storage/media/100/local/files/Videos/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,Static,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"mkdir -pv /storage/media/100/local/files/Audios/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,Static,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"mkdir -pv /storage/media/100/local/files/Documents/{ModifyCb,ModifyPro,FavCb,FavPro,Thumbnail,Static,R_Cb,W_Cb,RW_Cb,R_Pro,W_Pro,RW_Pro,openClose,trashCb,trashPro}",
"for d in FavCb FavPro trashCb trashPro; do for i in $$(seq 3); 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 FavCb FavPro trashCb trashPro; do for i in $$(seq 3); 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 FavCb FavPro trashCb trashPro; do for i in $$(seq 3); 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 FavCb FavPro trashCb trashPro; do for i in $$(seq 3); do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in FavCb FavPro trashCb trashPro; do for i in $$(seq 3); do cp /storage/media/100/local/temp/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in FavCb FavPro trashCb trashPro; do for i in $$(seq 3); do cp /storage/media/100/local/temp/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in FavCb FavPro trashCb trashPro; do for i in $$(seq 3); do cp /storage/media/100/local/temp/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"for d in Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; 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 Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; 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 Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; 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 Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; do for i in $$(seq 2); do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; do for i in $$(seq 2); do cp /storage/media/100/local/temp/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; do for i in $$(seq 2); do cp /storage/media/100/local/temp/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in Thumbnail openClose W_Cb RW_Cb W_Pro RW_Pro; do for i in $$(seq 2); do cp /storage/media/100/local/temp/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"for d in ModifyCb ModifyPro R_Cb R_Pro; do for i in $$(seq 1); 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 R_Cb R_Pro; do for i in $$(seq 1); 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 R_Cb R_Pro; do for i in $$(seq 1); 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 Static R_Cb R_Pro; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in ModifyCb ModifyPro Static R_Cb R_Pro; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in ModifyCb ModifyPro Static R_Cb R_Pro; do for i in $$(seq 1); do cp /storage/media/100/local/temp/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in ModifyCb ModifyPro Static R_Cb R_Pro; do for i in $$(seq 1); do cp /storage/media/100/local/temp/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,21 +13,29 @@
* limitations under the License.
*/
import fileAssetCommitModifyCallback from './fileAssetCommitModifyCallback.test.ets'
import fileAssetCommitModifyPromise from './fileAssetCommitModifyPromise.test.ets'
import fileAssetFavoriteCallback from './fileAssetFavoriteCallback.test.ets'
import fileAssetFavoritePromise from './fileAssetFavoritePromise.test.ets'
import fileAssetGetThumbnailCallback from './fileAssetGetThumbnailCallback.test.ets'
import fileAssetGetThumbnailPromise from './fileAssetGetThumbnailPromise.test.ets'
import fileAssetOpenCallback from './fileAssetOpenCallback.test.ets'
import fileAssetOpenPromise from './fileAssetOpenPromise.test.ets'
import fileAssetCommitModifyCallbackTest from './fileAssetCommitModifyCallback.test.ets'
import fileAssetCommitModifyPromiseTest from './fileAssetCommitModifyPromise.test.ets'
import fileAssetFavoriteCallbackTest from './fileAssetFavoriteCallback.test.ets'
import fileAssetFavoritePromiseTest from './fileAssetFavoritePromise.test.ets'
import fileAssetGetThumbnailCallbackTest from './fileAssetGetThumbnailCallback.test.ets'
import fileAssetGetThumbnailPromiseTest from './fileAssetGetThumbnailPromise.test.ets'
import fileAssetIsDirectoryCallbackTest from './fileAssetIsDirectoryCallback.test.ets'
import fileAssetIsDirectoryPromiseTest from './fileAssetIsDirectoryPromise.test.ets'
import fileAssetOpenCallbackTest from './fileAssetOpenCallback.test.ets'
import fileAssetOpenPromiseTest from './fileAssetOpenPromise.test.ets'
import fileAssetTrashCallbackTest from './fileAssetTrashCallback.test.ets'
import fileAssetTrashPromiseTest from './fileAssetTrashPromise.test.ets'
export default function testsuite(abilityContext) {
fileAssetCommitModifyCallback(abilityContext)
fileAssetCommitModifyPromise(abilityContext)
fileAssetFavoriteCallback(abilityContext)
fileAssetFavoritePromise(abilityContext)
fileAssetGetThumbnailCallback(abilityContext)
fileAssetGetThumbnailPromise(abilityContext)
fileAssetOpenCallback(abilityContext)
fileAssetOpenPromise(abilityContext)
fileAssetCommitModifyCallbackTest(abilityContext)
fileAssetCommitModifyPromiseTest(abilityContext)
fileAssetFavoriteCallbackTest(abilityContext)
fileAssetFavoritePromiseTest(abilityContext)
fileAssetGetThumbnailCallbackTest(abilityContext)
fileAssetGetThumbnailPromiseTest(abilityContext)
fileAssetIsDirectoryCallbackTest(abilityContext)
fileAssetIsDirectoryPromiseTest(abilityContext)
fileAssetOpenCallbackTest(abilityContext)
fileAssetOpenPromiseTest(abilityContext)
fileAssetTrashCallbackTest(abilityContext)
fileAssetTrashPromiseTest(abilityContext)
}
......@@ -21,19 +21,20 @@ import {
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
audioNameFetchOps,
imageVideoNameFetchOps,
checkPresetsAssets,
checkAssetsCount,
getPermission,
nameFetchOps,
} from '../../../../../../common';
export default function fileAssetCommitModifyCallback(abilityContext) {
describe('fileAssetCommitModifyCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function fileAssetCommitModifyCallbackTest(abilityContext) {
describe('fileAssetCommitModifyCallbackTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFileAssetJsTest')
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFileAssetJsTest')
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -46,14 +47,19 @@ export default function fileAssetCommitModifyCallback(abilityContext) {
console.info('afterAll case');
});
const checkCommitModify = async function (done, testNum, media_type, fetchOp, prop, val) {
const checkCommitModify = async function (done, testNum, fetchOp, prop, val, isAudio) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const oldVal = asset[prop]
asset[prop] = val;
const asset = await fetchAssetResult.getFirstObject();
const oldVal = asset.get(prop);
asset.set(prop, val);
await asset.commitModify(async (err) => {
if (err) {
console.info(`${testNum} err : ${err}`)
......@@ -61,9 +67,9 @@ export default function fileAssetCommitModifyCallback(abilityContext) {
done();
return;
}
asset[prop] = oldVal;
asset.set(prop, oldVal.toString());
await asset.commitModify();
await fetchFileResult.close();
fetchAssetResult.close();
done();
});
} catch (error) {
......@@ -83,11 +89,11 @@ export default function fileAssetCommitModifyCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let fetchOp = nameFetchOps(testNum, 'Pictures/ModifyCb/', '01.jpg');
let prop = 'displayName'
let val = IMAGE_TYPE.toString() + '.jpg'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
let fetchOp = imageVideoNameFetchOps(testNum, 'Pictures/ModifyCb/', '01.jpg');
let prop = 'display_name';
let val = IMAGE_TYPE.toString() + '.jpg';
let isAudio = false;
await checkCommitModify(done, testNum, fetchOp, prop, val, isAudio);
});
/**
......@@ -100,11 +106,11 @@ export default function fileAssetCommitModifyCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Audios/ModifyCb/', '01.mp3');
let prop = 'displayName'
let val = AUDIO_TYPE.toString() + '.mp3'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
let fetchOp = audioNameFetchOps(testNum, 'Audios/ModifyCb/', '01.mp3');
let prop = 'display_name';
let val = AUDIO_TYPE.toString() + '.mp3';
let isAudio = true;
await checkCommitModify(done, testNum, fetchOp, prop, val, isAudio);
});
/**
......@@ -117,11 +123,11 @@ export default function fileAssetCommitModifyCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Videos/ModifyCb/', '01.mp4');
let prop = 'displayName'
let val = VIDEO_TYPE.toString() + '.mp4'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
let fetchOp = imageVideoNameFetchOps(testNum, 'Videos/ModifyCb/', '01.mp4');
let prop = 'display_name';
let val = VIDEO_TYPE.toString() + '.mp4';
let isAudio = false;
await checkCommitModify(done, testNum, fetchOp, prop, val, isAudio);
});
});
}
......
......@@ -23,15 +23,16 @@ import {
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
nameFetchOps,
audioNameFetchOps,
imageVideoNameFetchOps,
} from '../../../../../../common';
export default function fileAssetCommitModifyPromise(abilityContext) {
describe('fileAssetCommitModifyPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function fileAssetCommitModifyPromiseTest(abilityContext) {
describe('fileAssetCommitModifyPromiseTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFileAssetJsTest')
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFileAssetJsTest')
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -44,21 +45,26 @@ export default function fileAssetCommitModifyPromise(abilityContext) {
console.info('afterAll case');
});
const checkCommitModify = async function (done, testNum, media_type, fetchOp, prop, val) {
const checkCommitModify = async function (done, testNum, fetchOp, prop, val, isAudio) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const oldVal = asset[prop]
asset[prop] = val;
const asset = await fetchAssetResult.getFirstObject();
const oldVal = asset.get(prop)
asset.set(prop, val);
await asset.commitModify();
asset[prop] = oldVal;
asset.set(prop, oldVal.toString());
await asset.commitModify();
await fetchFileResult.close();
fetchAssetResult.close();
done();
} catch (error) {
console.info(`${testNum} error : ${error}`)
console.info(`${testNum} error : ${error}`);
expect(false).assertTrue();
done();
}
......@@ -74,11 +80,11 @@ export default function fileAssetCommitModifyPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_01';
let media_type = [IMAGE_TYPE];
let fetchOp = nameFetchOps(testNum, 'Pictures/ModifyPro/', '01.jpg');
let prop = 'displayName'
let val = IMAGE_TYPE.toString() + '.jpg'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
let fetchOp = imageVideoNameFetchOps(testNum, 'Pictures/ModifyPro/', '01.jpg');
let prop = 'display_name';
let val = IMAGE_TYPE.toString() + '.jpg';
let isAudio = false;
await checkCommitModify(done, testNum, fetchOp, prop, val, isAudio);
});
/**
......@@ -91,11 +97,11 @@ export default function fileAssetCommitModifyPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_02';
let media_type = [AUDIO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Audios/ModifyPro/', '01.mp3');
let prop = 'displayName'
let val = AUDIO_TYPE.toString() + '.mp3'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
let fetchOp = audioNameFetchOps(testNum, 'Audios/ModifyPro/', '01.mp3');
let prop = 'display_name';
let val = AUDIO_TYPE.toString() + '.mp3';
let isAudio = true;
await checkCommitModify(done, testNum, fetchOp, prop, val, isAudio);
});
/**
......@@ -108,11 +114,11 @@ export default function fileAssetCommitModifyPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_COMMITMODIFY_PROMISE_03';
let media_type = [VIDEO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Videos/ModifyPro/', '01.mp4');
let prop = 'displayName'
let val = VIDEO_TYPE.toString() + '.mp4'
await checkCommitModify(done, testNum, media_type, fetchOp, prop, val)
let fetchOp = imageVideoNameFetchOps(testNum, 'Videos/ModifyPro/', '01.mp4');
let prop = 'display_name';
let val = VIDEO_TYPE.toString() + '.mp4';
let isAudio = false;
await checkCommitModify(done, testNum, fetchOp, prop, val, isAudio);
});
});
}
......
......@@ -17,22 +17,20 @@ import userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
nameFetchOps,
audioNameFetchOps,
imageVideoNameFetchOps,
checkAssetsCount,
getPermission,
} from '../../../../../../common';
export default function fileAssetFavoriteCallback(abilityContext) {
describe('fileAssetFavoriteCallback', function () {
var userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function fileAssetFavoriteCallbackTest(abilityContext) {
describe('fileAssetFavoriteCallbackTest', function () {
var userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFavorite');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFavorite');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -45,75 +43,92 @@ export default function fileAssetFavoriteCallback(abilityContext) {
console.info('afterAll case');
});
const favoriteDefaultState = async function (done, testNum, media_type, fetchOp) {
const favoriteDefaultState = async function (done, testNum, fetchOp, isAudio) {
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
let asset = await fetchAssetResult.getFirstObject();
asset.isFavorite(async (err, isFavorite) => {
if (err) {
expect(false).assertTrue();
await fetchFileResult.close();
await fetchAssetResult.close();
done();
return;
}
expect(isFavorite).assertEqual(false);
await fetchFileResult.close();
fetchAssetResult.close();
done()
});
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
console.info(`${testNum} failed error: ${error}`);
expect(false).assertTrue();
done();
}
}
const favoriteByTrue = async function (done, testNum, media_type, fetchOp) {
const favoriteByTrue = async function (done, testNum, fetchOp, isAudio) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const asset = await fetchAssetResult.getFirstObject();
let isFavorite = await asset.isFavorite();
console.info(`${testNum} isFavorite: ${isFavorite}`);
asset.favorite(true, async (err) => {
if(err) {
console.info(`${testNum} failed err: ${err}`)
console.info(`${testNum} failed err: ${err}`);
expect(false).assertTrue();
done();
return;
}
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(true);
await fetchFileResult.close();
fetchAssetResult.close();
done();
});
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
console.info(`${testNum} failed error: ${error}`);
expect(false).assertTrue();
done();
}
}
const favoriteByFalse = async function (done, testNum, media_type, fetchOp) {
const favoriteByFalse = async function (done, testNum, fetchOp, isAudio) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const asset = await fetchAssetResult.getFirstObject();
await asset.favorite(true);
asset.favorite(false, async (err) => {
if(err) {
console.info(`${testNum} failed err: ${err}`)
console.info(`${testNum} failed err: ${err}`);
expect(false).assertTrue();
done();
return;
}
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(false);
await fetchFileResult.close();
fetchAssetResult.close();
done();
});
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
console.info(`${testNum} failed error: ${error}`);
expect(false).assertTrue();
done();
}
......@@ -128,10 +143,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_001'
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavCb/', '01.jpg')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_001';
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavCb/', '01.jpg');
let isAudio = false;
await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -143,10 +158,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_002'
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavCb/', '02.jpg')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_002';
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavCb/', '02.jpg');
let isAudio = false;
await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -158,10 +173,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_003'
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavCb/', '03.jpg')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_01_003';
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavCb/', '03.jpg');
let isAudio = false;
await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -173,10 +188,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_001'
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavCb/', '01.mp3')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_001';
let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavCb/', '01.mp3');
let isAudio = true;
await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -188,10 +203,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_002'
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavCb/', '02.mp3')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_002';
let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavCb/', '02.mp3');
let isAudio = true;
await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -203,10 +218,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_003'
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavCb/', '03.mp3')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_02_003';
let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavCb/', '03.mp3');
let isAudio = true;
await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -218,10 +233,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_001'
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavCb/', '01.mp4')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_001';
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavCb/', '01.mp4');
let isAudio = false;
await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -233,10 +248,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_002'
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavCb/', '02.mp4')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_002';
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavCb/', '02.mp4');
let isAudio = false;
await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -248,10 +263,10 @@ export default function fileAssetFavoriteCallback(abilityContext) {
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_003'
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavCb/', '03.mp4')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_CALLBACK_03_003';
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavCb/', '03.mp4');
let isAudio = false;
await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
});
});
}
......@@ -17,20 +17,18 @@ import userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
nameFetchOps,
audioNameFetchOps,
imageVideoNameFetchOps,
checkAssetsCount,
} from '../../../../../../common';
export default function fileAssetFavoritePromise(abilityContext) {
describe('fileAssetFavoritePromise', function () {
var userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function fileAssetFavoritePromiseTest(abilityContext) {
describe('fileAssetFavoritePromiseTest', function () {
var userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFavorite');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFavorite');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -43,53 +41,68 @@ export default function fileAssetFavoritePromise(abilityContext) {
console.info('afterAll case');
});
const favoriteDefaultState = async function (done, testNum, media_type, fetchOp) {
const favoriteDefaultState = async function (done, testNum, fetchOp, isAudio) {
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
let asset = await fetchAssetResult.getFirstObject();
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(false);
await fetchFileResult.close();
fetchAssetResult.close();
done()
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
console.info(`${testNum} failed error: ${error}`);
expect(false).assertTrue();
done();
}
}
const favoriteByTrue = async function (done, testNum, media_type, fetchOp) {
const favoriteByTrue = async function (done, testNum, fetchOp, isAudio) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const asset = await fetchAssetResult.getFirstObject();
await asset.favorite(true);
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(true);
await fetchFileResult.close();
fetchAssetResult.close();
done();
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
console.info(`${testNum} failed error: ${error}`);
expect(false).assertTrue();
done();
}
}
const favoriteByFalse = async function (done, testNum, media_type, fetchOp) {
const favoriteByFalse = async function (done, testNum, fetchOp, isAudio) {
try {
const fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const asset = await fetchAssetResult.getFirstObject();
await asset.favorite(true);
await asset.favorite(false);
let isFavorite = await asset.isFavorite();
expect(isFavorite).assertEqual(false);
await fetchFileResult.close();
fetchAssetResult.close();
done();
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
console.info(`${testNum} failed error: ${error}`);
expect(false).assertTrue();
done();
}
......@@ -105,9 +118,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_001';
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavPro/', '01.jpg')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavPro/', '01.jpg');
let isAudio = false;
await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -120,9 +133,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_002';
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavPro/', '02.jpg')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavPro/', '02.jpg');
let isAudio = false;
await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -135,9 +148,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_01_003';
let media_type = [IMAGE_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Pictures/FavPro/', '03.jpg')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/FavPro/', '03.jpg');
let isAudio = false;
await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -150,9 +163,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_001';
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavPro/', '01.mp3')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavPro/', '01.mp3');
let isAudio = true;
await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -165,9 +178,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_02_002';
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavPro/', '02.mp3')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavPro/', '02.mp3');
let isAudio = true;
await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -180,9 +193,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003';
let media_type = [AUDIO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Audios/FavPro/', '03.mp3')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
let currentFetchOp = audioNameFetchOps(testNum, 'Audios/FavPro/', '03.mp3');
let isAudio = true;
await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -195,9 +208,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_001';
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavPro/', '01.mp4')
await favoriteDefaultState(done, testNum, media_type, currentFetchOp)
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavPro/', '01.mp4');
let isAudio = false;
await favoriteDefaultState(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -210,9 +223,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_002';
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavPro/', '02.mp4')
await favoriteByTrue(done, testNum, media_type, currentFetchOp)
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavPro/', '02.mp4');
let isAudio = false;
await favoriteByTrue(done, testNum, currentFetchOp, isAudio);
});
/**
......@@ -225,9 +238,9 @@ export default function fileAssetFavoritePromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_FAVORITE_PROMISE_03_003';
let media_type = [VIDEO_TYPE];
let currentFetchOp = nameFetchOps(testNum, 'Videos/FavPro/', '03.mp4')
await favoriteByFalse(done, testNum, media_type, currentFetchOp)
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/FavPro/', '03.mp4');
let isAudio = false;
await favoriteByFalse(done, testNum, currentFetchOp, isAudio);
});
});
}
......@@ -19,20 +19,18 @@ import image from '@ohos.multimedia.image';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
nameFetchOps,
audioNameFetchOps,
imageVideoNameFetchOps,
} from '../../../../../../common';
export default function fileAssetGetThumbnailCallback(abilityContext) {
describe('fileAssetGetThumbnailCallback', function () {
export default function fileAssetGetThumbnailCallbackTest(abilityContext) {
describe('fileAssetGetThumbnailCallbackTest', function () {
image.createPixelMap(new ArrayBuffer(4096), { size: { height: 1, width: 2 } }).then((pixelmap) => { });
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrGetThumbnailTest');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrGetThumbnailTest');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -45,24 +43,30 @@ export default function fileAssetGetThumbnailCallback(abilityContext) {
console.info('afterAll case');
});
async function testGetThumbnail(done, testNum, media_type, dOp, size) {
async function testGetThumbnail(done, testNum, fetchOp, size, isAudio) {
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, dOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
let asset = await fetchAssetResult.getFirstObject();
fetchAssetResult.close();
if (size == 'default') {
size = { width: 256, height: 256 };
asset.getThumbnail(async (err, pixelmap) => {
console.info(`${testNum}:: err1 :${err}`);
if (err != undefined) {
console.info(`${testNum}:: err1 :${err}`);
expect(false).assertTrue();
done();
return;
}
await pixelmap.getImageInfo((err, info) => {
console.info(`${testNum}:: err2 :${err}`);
if (err != undefined) {
console.info(`${testNum}:: err2 :${err}`);
expect(false).assertTrue();
done();
return;
......@@ -75,15 +79,15 @@ export default function fileAssetGetThumbnailCallback(abilityContext) {
})
} else {
asset.getThumbnail(size, async (err, pixelmap) => {
console.info(`${testNum}:: err1 :${err}`);
if (err != undefined) {
console.info(`${testNum}:: err1 :${err}`);
expect(false).assertTrue();
done();
return;
}
await pixelmap.getImageInfo((err, info) => {
console.info(`${testNum}:: err2 :${err}`);
if (err != undefined) {
console.info(`${testNum}:: err2 :${err}`);
expect(false).assertTrue();
done();
return;
......@@ -112,10 +116,10 @@ export default function fileAssetGetThumbnailCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_001';
let media_type = [IMAGE_TYPE];
let dOp = nameFetchOps(testNum, 'Pictures/Thumbnail/', '01.jpg');
let dOp = imageVideoNameFetchOps(testNum, 'Pictures/Thumbnail/', '01.jpg');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
let isAudio = false;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -128,10 +132,10 @@ export default function fileAssetGetThumbnailCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_01_002';
let media_type = [IMAGE_TYPE];
let dOp = nameFetchOps(testNum, 'Pictures/Thumbnail/', '02.jpg');
let dOp = imageVideoNameFetchOps(testNum, 'Pictures/Thumbnail/', '02.jpg');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
let isAudio = false;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -144,10 +148,10 @@ export default function fileAssetGetThumbnailCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_001';
let media_type = [AUDIO_TYPE];
let dOp = nameFetchOps(testNum, 'Audios/Thumbnail/', '01.mp3');
let dOp = audioNameFetchOps(testNum, 'Audios/Thumbnail/', '01.mp3');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
let isAudio = true;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -160,10 +164,10 @@ export default function fileAssetGetThumbnailCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_02_002';
let media_type = [AUDIO_TYPE];
let dOp = nameFetchOps(testNum, 'Audios/Thumbnail/', '02.mp3');
let dOp = audioNameFetchOps(testNum, 'Audios/Thumbnail/', '02.mp3');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
let isAudio = true;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -176,10 +180,10 @@ export default function fileAssetGetThumbnailCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_001';
let media_type = [VIDEO_TYPE];
let dOp = nameFetchOps(testNum, 'Videos/Thumbnail/', '01.mp4');
let dOp = imageVideoNameFetchOps(testNum, 'Videos/Thumbnail/', '01.mp4');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
let isAudio = false;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -192,10 +196,10 @@ export default function fileAssetGetThumbnailCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_CALLBACK_03_002';
let media_type = [VIDEO_TYPE];
let dOp = nameFetchOps(testNum, 'Videos/Thumbnail/', '02.mp4');
let dOp = imageVideoNameFetchOps(testNum, 'Videos/Thumbnail/', '02.mp4');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
let isAudio = false;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
});
}
......
......@@ -18,21 +18,19 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import image from '@ohos.multimedia.image';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
checkPresetsAssets,
checkAssetsCount,
nameFetchOps,
audioNameFetchOps,
imageVideoNameFetchOps,
} from '../../../../../../common';
export default function fileAssetGetThumbnailPromise(abilityContext) {
describe('fileAssetGetThumbnailPromise', function () {
export default function fileAssetGetThumbnailPromiseTest(abilityContext) {
describe('fileAssetGetThumbnailPromiseTest', function () {
image.createPixelMap(new ArrayBuffer(4096), { size: { height: 1, width: 2 } }).then((pixelmap) => { });
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrGetThumbnailTest');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrGetThumbnailTest');
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -45,12 +43,18 @@ export default function fileAssetGetThumbnailPromise(abilityContext) {
console.info('afterAll case');
});
async function testGetThumbnail(done, testNum, media_type, dOp, size,) {
async function testGetThumbnail(done, testNum, fetchOp, size, isAudio) {
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, dOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
let asset = await fetchAssetResult.getFirstObject();
fetchAssetResult.close();
console.info(`${testNum}:displayName ${asset.displayName}`)
let pixelmap;
if (size == 'default') {
......@@ -81,10 +85,10 @@ export default function fileAssetGetThumbnailPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_001';
let media_type = [IMAGE_TYPE];
let dOp = nameFetchOps(testNum, 'Pictures/Thumbnail/', '01.jpg');
let dOp = imageVideoNameFetchOps(testNum, 'Pictures/Thumbnail/', '01.jpg');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
let isAudio = false;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -97,10 +101,10 @@ export default function fileAssetGetThumbnailPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_01_002';
let media_type = [IMAGE_TYPE];
let dOp = nameFetchOps(testNum, 'Pictures/Thumbnail/', '02.jpg');
let dOp = imageVideoNameFetchOps(testNum, 'Pictures/Thumbnail/', '02.jpg');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
let isAudio = false;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -113,10 +117,10 @@ export default function fileAssetGetThumbnailPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_001';
let media_type = [AUDIO_TYPE];
let dOp = nameFetchOps(testNum, 'Audios/Thumbnail/', '01.mp3');
let dOp = audioNameFetchOps(testNum, 'Audios/Thumbnail/', '01.mp3');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
let isAudio = true;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -129,10 +133,10 @@ export default function fileAssetGetThumbnailPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_02_002';
let media_type = [AUDIO_TYPE];
let dOp = nameFetchOps(testNum, 'Audios/Thumbnail/', '02.mp3');
let dOp = audioNameFetchOps(testNum, 'Audios/Thumbnail/', '02.mp3');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
let isAudio = true;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -145,10 +149,10 @@ export default function fileAssetGetThumbnailPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_001';
let media_type = [VIDEO_TYPE];
let dOp = nameFetchOps(testNum, 'Videos/Thumbnail/', '01.mp4');
let dOp = imageVideoNameFetchOps(testNum, 'Videos/Thumbnail/', '01.mp4');
let size = 'default';
await testGetThumbnail(done, testNum, media_type, dOp, size,);
let isAudio = false;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
/**
......@@ -161,10 +165,10 @@ export default function fileAssetGetThumbnailPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_GETTHUMBNAIL_PROMISE_03_002';
let media_type = [VIDEO_TYPE];
let dOp = nameFetchOps(testNum, 'Videos/Thumbnail/', '02.mp4');
let dOp = imageVideoNameFetchOps(testNum, 'Videos/Thumbnail/', '02.mp4');
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, media_type, dOp, size)
let isAudio = false;
await testGetThumbnail(done, testNum, dOp, size, isAudio);
});
});
}
......
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
checkPresetsAssets,
audioNameFetchOps,
imageVideoNameFetchOps,
} from '../../../../../../common';
export default function fileAssetIsDirectoryCallbackTest(abilityContext) {
describe('fileAssetIsDirectoryCallbackTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFileAssetJsTest')
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const isDirectoryTest = async function (done, testNum, fetchOp, isAudio) {
try {
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
const asset = await fetchAssetResult.getFirstObject();
fetchAssetResult.close();
asset.isDirectory((err, isDir) =>{
if (err) {
console.info(`${testNum} err : ${err}`);
expect.assertFail();
done();
return;
}
expect(isDir).assertEqual(false);
done();
});
} catch (error) {
console.info(`${testNum} error : ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_CALLBACK_01
* @tc.name : isDirectory
* @tc.desc : image asset isDirectory
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILEASSET_ISDIRECTORY_CALLBACK_001';
let fetchOp = imageVideoNameFetchOps(testNum, 'Pictures/Static/', '01.jpg');
let isAudio = false;
await isDirectoryTest(done, testNum, fetchOp, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_CALLBACK_02
* @tc.name : isDirectory
* @tc.desc : audio asset isDirectory
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILEASSET_ISDIRECTORY_CALLBACK_001';
let fetchOp = audioNameFetchOps(testNum, 'Audios/Static/', '01.mp3');
let isAudio = true;
await isDirectoryTest(done, testNum, fetchOp, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_CALLBACK_03
* @tc.name : isDirectory
* @tc.desc : video asset isDirectory
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_FILEASSET_ISDIRECTORY_CALLBACK_001';
let fetchOp = imageVideoNameFetchOps(testNum, 'Videos/Static/', '01.mp4');
let isAudio = false;
await isDirectoryTest(done, testNum, fetchOp, isAudio);
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
audioNameFetchOps,
imageVideoNameFetchOps,
checkPresetsAssets,
} from '../../../../../../common';
export default function fileAssetIsDirectoryPromiseTest(abilityContext) {
describe('fileAssetIsDirectoryPromiseTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFileAssetJsTest')
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const isDirectoryTest = async function (done, testNum, fetchOp, isAudio) {
try {
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
const asset = await fetchAssetResult.getFirstObject();
fetchAssetResult.close();
const isDir = await asset.isDirectory();
expect(isDir).assertEqual(false);
done();
} catch (error) {
console.info(`${testNum} error : ${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_01
* @tc.name : isDirectory
* @tc.desc : image asset isDirectory
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_01';
let fetchOp = imageVideoNameFetchOps(testNum, 'Pictures/Static/', '01.jpg');
let isAudio = false;
await isDirectoryTest(done, testNum, fetchOp, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_02
* @tc.name : isDirectory
* @tc.desc : audio asset isDirectory
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_02';
let fetchOp = audioNameFetchOps(testNum, 'Audios/Static/', '01.mp3');
let isAudio = true;
await isDirectoryTest(done, testNum, fetchOp, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_03
* @tc.name : isDirectory
* @tc.desc : video asset isDirectory
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_ISDIRECTORY_PROMISE_03';
let fetchOp = imageVideoNameFetchOps(testNum, 'Videos/Static/', '01.mp4');
let isAudio = false;
await isDirectoryTest(done, testNum, fetchOp, isAudio);
});
});
}
......@@ -17,21 +17,20 @@ import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
audioFetchOps,
imageVideoFetchOps,
audioNameFetchOps,
imageVideoNameFetchOps,
isNum,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
nameFetchOps,
isNum,
} from '../../../../../../common';
export default function fileAssetOpenCallback(abilityContext) {
describe('fileAssetOpenCallback', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function fileAssetOpenCallbackTest(abilityContext) {
describe('fileAssetOpenCallbackTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFileAssetJsTest')
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFileAssetJsTest')
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -44,14 +43,20 @@ export default function fileAssetOpenCallback(abilityContext) {
console.info('afterAll case');
});
const rOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
const rOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount, isAudio) {
let asset;
let fd;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset = await fetchAssetResult.getFirstObject();
fetchAssetResult.close();
asset.open('r', async (err, fd) => {
if (err) {
console.info(`${testNum} :: err: ${err}`);
......@@ -81,16 +86,21 @@ export default function fileAssetOpenCallback(abilityContext) {
}
}
const wOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
const wOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount, isAudio) {
let asset, asset1;
let fd, fd1;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset1 = await fetchFileResult.getNextObject();
asset = await fetchAssetResult.getFirstObject();
asset1 = await fetchAssetResult.getNextObject();
fetchAssetResult.close();
asset.open('w', async (err, fd) => {
if (err) {
console.info(`${testNum} :: err: ${err}`);
......@@ -123,14 +133,19 @@ export default function fileAssetOpenCallback(abilityContext) {
}
}
const rwOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
const rwOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount, isAudio) {
let asset, asset1;
let fd, fd1;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset = await fetchAssetResult.getFirstObject();
asset.open('rw', async (err, fd) => {
if (err) {
console.info(`${testNum} :: err: ${err}`);
......@@ -142,7 +157,7 @@ export default function fileAssetOpenCallback(abilityContext) {
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead).assertEqual(assetProps.bytesRead);
asset1 = await fetchFileResult.getNextObject();
asset1 = await fetchAssetResult.getNextObject();
fd1 = await asset1.open('r');
expect(isNum(fd1)).assertTrue();
let buf1 = new ArrayBuffer(4096);
......@@ -153,6 +168,7 @@ export default function fileAssetOpenCallback(abilityContext) {
console.info(`fd1:${fd1},fd:${fd}`)
await asset.close(fd);
await asset1.close(fd1);
fetchAssetResult.close();
done();
});
} catch (error) {
......@@ -164,14 +180,19 @@ export default function fileAssetOpenCallback(abilityContext) {
}
}
const closeTest = async function (done, testNum, media_type, fetchOp) {
const closeTest = async function (done, testNum, fetchOp, isAudio) {
let asset;
let fd;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const asset = await fetchAssetResult.getFirstObject();
fd = await asset.open('r');
expect(isNum(fd)).assertTrue();
asset.close(fd, async (err) => {
......@@ -215,13 +236,13 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_001';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/R_Cb/');
let fetchOp = imageVideoFetchOps(testNum, 'Pictures/R_Cb/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await rOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -234,13 +255,13 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_002';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/W_Cb/');
let fetchOp = imageVideoFetchOps(testNum, 'Pictures/W_Cb/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await wOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -253,14 +274,14 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_01_003';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/RW_Cb/');
let fetchOp = imageVideoFetchOps(testNum, 'Pictures/RW_Cb/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -273,13 +294,13 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_001';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/R_Cb/');
let fetchOp = audioFetchOps(testNum, 'Audios/R_Cb/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = true;
await rOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -292,13 +313,13 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_002';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/W_Cb/');
let fetchOp = audioFetchOps(testNum, 'Audios/W_Cb/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = true;
await wOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -311,14 +332,14 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_02_003';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/RW_Cb/');
let fetchOp = audioFetchOps(testNum, 'Audios/RW_Cb/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = true;
await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -331,13 +352,13 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_001';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/R_Cb/');
let fetchOp = imageVideoFetchOps(testNum, 'Videos/R_Cb/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await rOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -350,13 +371,13 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_002';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/W_Cb/');
let fetchOp = imageVideoFetchOps(testNum, 'Videos/W_Cb/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await wOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -369,14 +390,14 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_CALLBACK_03_003';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/RW_Cb/');
let fetchOp = imageVideoFetchOps(testNum, 'Videos/RW_Cb/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
//------------------------------------------------------------------------------------
......@@ -391,9 +412,9 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_01';
let media_type = [IMAGE_TYPE];
let fetchOp = nameFetchOps(testNum, 'Pictures/openClose/', '01.jpg');
await closeTest(done, testNum, media_type, fetchOp)
let fetchOp = imageVideoNameFetchOps(testNum, 'Pictures/openClose/', '01.jpg');
let isAudio = false;
await closeTest(done, testNum, fetchOp, isAudio);
});
/**
......@@ -406,9 +427,9 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_02';
let media_type = [AUDIO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Audios/openClose/', '01.mp3');
await closeTest(done, testNum, media_type, fetchOp)
let fetchOp = audioNameFetchOps(testNum, 'Audios/openClose/', '01.mp3');
let isAudio = true;
await closeTest(done, testNum, fetchOp, isAudio);
});
/**
......@@ -421,9 +442,9 @@ export default function fileAssetOpenCallback(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_CALLBACK_03';
let media_type = [VIDEO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Videos/openClose/', '01.mp4');
await closeTest(done, testNum, media_type, fetchOp)
let fetchOp = imageVideoNameFetchOps(testNum, 'Videos/openClose/', '01.mp4');
let isAudio = false;
await closeTest(done, testNum, fetchOp, isAudio);
});
});
}
......@@ -21,18 +21,20 @@ import {
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
audioFetchOps,
imageVideoFetchOps,
audioNameFetchOps,
imageVideoNameFetchOps,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
nameFetchOps,
isNum,
} from '../../../../../../common';
export default function fileAssetOpenPromise(abilityContext) {
describe('fileAssetOpenPromise', function () {
const userfile_mgr = userfile_manager.getUserFileMgr(abilityContext);
export default function fileAssetOpenPromiseTest(abilityContext) {
describe('fileAssetOpenPromiseTest', function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(userfile_mgr, 'ActsUserFileMgrFileAssetJsTest')
await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrFileAssetJsTest')
});
beforeEach(function () {
console.info('beforeEach case');
......@@ -45,14 +47,20 @@ export default function fileAssetOpenPromise(abilityContext) {
console.info('afterAll case');
});
const rOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
const rOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount, isAudio) {
let asset;
let fd;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset = await fetchAssetResult.getFirstObject();
fetchAssetResult.close();
fd = await asset.open('r');
expect(isNum(fd)).assertTrue();
let buf = new ArrayBuffer(4096);
......@@ -75,16 +83,21 @@ export default function fileAssetOpenPromise(abilityContext) {
}
}
const wOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
const wOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount, isAudio) {
let asset, asset1;
let fd, fd1;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset1 = await fetchFileResult.getNextObject();
asset = await fetchAssetResult.getFirstObject();
asset1 = await fetchAssetResult.getNextObject();
fetchAssetResult.close();
fd = await asset.open('w');
expect(isNum(fd)).assertTrue();
......@@ -113,20 +126,25 @@ export default function fileAssetOpenPromise(abilityContext) {
}
}
const rwOpenTest = async function (done, testNum, media_type, fetchOp, assetProps, expectCount) {
const rwOpenTest = async function (done, testNum, fetchOp, assetProps, expectCount, isAudio) {
let asset, asset1;
let fd, fd1;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, expectCount);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, expectCount);
if (!checkAssetCountPass) return;
asset = await fetchFileResult.getFirstObject();
asset = await fetchAssetResult.getFirstObject();
fd = await asset.open('rw');
expect(isNum(fd)).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead).assertEqual(assetProps.bytesRead);
asset1 = await fetchFileResult.getNextObject();
asset1 = await fetchAssetResult.getNextObject();
fd1 = await asset1.open('r');
expect(isNum(fd1)).assertTrue();
let buf1 = new ArrayBuffer(4096);
......@@ -137,6 +155,7 @@ export default function fileAssetOpenPromise(abilityContext) {
console.info(`fd1:${fd1},fd:${fd}`)
await asset.close(fd);
await asset1.close(fd1);
fetchAssetResult.close();
done();
} catch (error) {
console.info(`${testNum} :: error: ${error}`);
......@@ -147,14 +166,19 @@ export default function fileAssetOpenPromise(abilityContext) {
}
}
const closeTest = async function (done, testNum, media_type, fetchOp) {
const closeTest = async function (done, testNum, fetchOp, isAudio) {
let asset;
let fd;
try {
let fetchFileResult = await userfile_mgr.getFileAssets(media_type, fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
const asset = await fetchAssetResult.getFirstObject();
fd = await asset.open('r');
expect(isNum(fd)).assertTrue();
await asset.close(fd);
......@@ -191,13 +215,13 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_001';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/R_Pro/');
let fetchOp = imageVideoFetchOps(testNum, 'Pictures/R_Pro/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await rOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -210,13 +234,13 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_002';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/W_Pro/');
let fetchOp = imageVideoFetchOps(testNum, 'Pictures/W_Pro/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await wOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -229,14 +253,14 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_01_003';
let media_type = [IMAGE_TYPE];
let fetchOp = fetchOps(testNum, 'Pictures/RW_Pro/');
let fetchOp = imageVideoFetchOps(testNum, 'Pictures/RW_Pro/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -249,13 +273,13 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_001';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/R_Pro/');
let fetchOp = audioFetchOps(testNum, 'Audios/R_Pro/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = true;
await rOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -268,13 +292,13 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_002';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/W_Pro/');
let fetchOp = audioFetchOps(testNum, 'Audios/W_Pro/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = true;
await wOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -287,14 +311,14 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_02_003';
let media_type = [AUDIO_TYPE];
let fetchOp = fetchOps(testNum, 'Audios/RW_Pro/');
let fetchOp = audioFetchOps(testNum, 'Audios/RW_Pro/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = true;
await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -307,13 +331,13 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_001';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/R_Pro/');
let fetchOp = imageVideoFetchOps(testNum, 'Videos/R_Pro/');
let assetProps = {
bytesRead: 4096,
};
let expectCount = 1;
await rOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await rOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -326,13 +350,13 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_002';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/W_Pro/');
let fetchOp = imageVideoFetchOps(testNum, 'Videos/W_Pro/');
let assetProps = {
write: 4096,
};
let expectCount = 2;
await wOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await wOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
/**
......@@ -345,14 +369,14 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_OPEN_PROMISE_03_003';
let media_type = [VIDEO_TYPE];
let fetchOp = fetchOps(testNum, 'Videos/RW_Pro/');
let fetchOp = imageVideoFetchOps(testNum, 'Videos/RW_Pro/');
let assetProps = {
bytesRead: 4096,
write: 4096,
};
let expectCount = 2;
await rwOpenTest(done, testNum, media_type, fetchOp, assetProps, expectCount)
let isAudio = false;
await rwOpenTest(done, testNum, fetchOp, assetProps, expectCount, isAudio);
});
//--------------------------------------------------------------------------------
......@@ -367,9 +391,9 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_01', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_01';
let media_type = [IMAGE_TYPE];
let fetchOp = nameFetchOps(testNum, 'Pictures/openClose/', '02.jpg');
await closeTest(done, testNum, media_type, fetchOp)
let fetchOp = imageVideoNameFetchOps(testNum, 'Pictures/openClose/', '02.jpg');
let isAudio = false;
await closeTest(done, testNum, fetchOp, isAudio);
});
/**
......@@ -382,9 +406,9 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_02', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_03';
let media_type = [AUDIO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Audios/openClose/', '02.mp3');
await closeTest(done, testNum, media_type, fetchOp)
let fetchOp = audioNameFetchOps(testNum, 'Audios/openClose/', '02.mp3');
let isAudio = true;
await closeTest(done, testNum, fetchOp, isAudio);
});
/**
......@@ -397,9 +421,9 @@ export default function fileAssetOpenPromise(abilityContext) {
*/
it('SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_03', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_CLOSE_PROMISE_03';
let media_type = [VIDEO_TYPE];
let fetchOp = nameFetchOps(testNum, 'Videos/openClose/', '02.mp4');
await closeTest(done, testNum, media_type, fetchOp)
let fetchOp = imageVideoNameFetchOps(testNum, 'Videos/openClose/', '02.mp4');
let isAudio = false;
await closeTest(done, testNum, fetchOp, isAudio);
});
});
}
/*
* 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 userfile_manager from '@ohos.filemanagement.userfile_manager';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index";
import {
sleep,
allFetchOp,
audioNameFetchOps,
imageVideoNameFetchOps,
albumFetchOps,
checkAssetsCount,
} from "../../../../../../common";
export default function fileAssetTrashCallbackTest(abilityContext) {
describe("fileAssetTrashCallbackTest", function () {
const userfilemgr = userfile_manager.getUserFileMgr(abilityContext);
beforeAll(async function () {
console.info("beforeAll case");
});
beforeEach(function () {
console.info("beforeEach case");
});
afterEach(async function () {
console.info("afterEach case");
await sleep;
});
afterAll(async function () {
console.info("afterAll case");
});
const isTrashTest = async function (done, testNum, fetchOp, isAudio) {
try {
let fetchAssetResult;
if (isAudio) {
fetchAssetResult = await userfilemgr.getAudioAssets(fetchOp);
} else {
fetchAssetResult = await userfilemgr.getPhotoAssets(fetchOp);
}
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchAssetResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchAssetResult.getFirstObject();
asset.isTrash(async (err, isTrash) => {
if (err) {
expect(false).assertTrue();
await fetchAssetResult.close();
done();
return;
}
expect(isTrash).assertEqual(false);
fetchAssetResult.close();
done()
});
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
async function setTrash(done, testNum, databasefFetchOps, ablumFetchOps, noAlbum, isAudio) {
let expectAssetNum = 3
try {
// database info
let databaseFetchFileResult;
if (isAudio) {
databaseFetchFileResult = await userfilemgr.getAudioAssets(databasefFetchOps);
} else {
databaseFetchFileResult = await userfilemgr.getPhotoAssets(databasefFetchOps);
}
let count = databaseFetchFileResult.getCount();
//album info
if (!noAlbum) {
let fetchAlbumResult = await userfilemgr.getPhotoAlbums(ablumFetchOps);
let album = await fetchAlbumResult.getFirstObject();
let op: userfile_manager.MediaFetchOptions = allFetchOp();
let albumFetchFileResult = await album.getPhotoAssets(op);
let albumFilesCount = albumFetchFileResult.getCount();
expect(albumFilesCount).assertEqual(expectAssetNum);
fetchAlbumResult.close();
}
// file info
let asset = await databaseFetchFileResult.getFirstObject();
let istrash = await asset.isTrash();
console.info(`${testNum} istrash: ${istrash}`);
// trash operation
asset.trash(true, async (err) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
asset.isTrash(async (err, trashState) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
expect(trashState).assertTrue();
try {
// after trash database info
let databaseFetchFileResult;
if (isAudio) {
databaseFetchFileResult = await userfilemgr.getAudioAssets(databasefFetchOps);
} else {
databaseFetchFileResult = await userfilemgr.getPhotoAssets(databasefFetchOps);
}
let databaseCount = databaseFetchFileResult.getCount();
databaseFetchFileResult.close();
expect(databaseCount).assertEqual(count - 1);
//album info
if (!noAlbum) {
let fetchAlbumResult = await userfilemgr.getPhotoAlbums(ablumFetchOps);
let album = await fetchAlbumResult.getFirstObject();
let op: userfile_manager.MediaFetchOptions = allFetchOp();
let albumFetchFileResult = await album.getPhotoAssets(op);
let albumFilesCount = albumFetchFileResult.getCount();
expect(albumFilesCount).assertEqual(expectAssetNum - 1);
fetchAlbumResult.close();
}
await asset.trash(false);
done();
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
});
});
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
}
async function recovery(done, testNum, databasefFetchOps, ablumFetchOps, noAlbum, isAudio) {
let expectAssetNum = 3;
try {
let databaseFetchFileResult;
if (isAudio) {
databaseFetchFileResult = await userfilemgr.getAudioAssets(databasefFetchOps);
} else {
databaseFetchFileResult = await userfilemgr.getPhotoAssets(databasefFetchOps);
}
let count = databaseFetchFileResult.getCount();
let asset = await databaseFetchFileResult.getFirstObject();
await asset.trash(true);
asset.trash(false, async (err) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
asset.isTrash(async (err, trashState) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
expect(trashState).assertFalse();
try {
let databaseFetchFileResult;
if (isAudio) {
databaseFetchFileResult = await userfilemgr.getAudioAssets(databasefFetchOps);
} else {
databaseFetchFileResult = await userfilemgr.getPhotoAssets(databasefFetchOps);
}
let databaseCount = databaseFetchFileResult.getCount();
databaseFetchFileResult.close();
expect(databaseCount).assertEqual(count);
//album info
if (!noAlbum) {
let fetchAlbumResult = await userfilemgr.getPhotoAlbums(ablumFetchOps);
let album = await fetchAlbumResult.getFirstObject();
let op: userfile_manager.MediaFetchOptions = allFetchOp();
let albumFetchFileResult = await album.getPhotoAssets(op);
let albumFilesCount = albumFetchFileResult.getCount();
expect(albumFilesCount).assertEqual(expectAssetNum);
fetchAlbumResult.close();
}
done();
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
});
});
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_001
* @tc.name : isTrash
* @tc.desc : isTrash(image) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_001'
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Pictures/trashCb/', '01.jpg');
let isAudio = false;
await isTrashTest(done, testNum, currentFetchOp, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_002
* @tc.name : trash
* @tc.desc : trash(image) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_002'
let rOps = imageVideoNameFetchOps(testNum, "Pictures/trashCb/", '02.jpg');
let aOps = albumFetchOps(testNum, "Pictures/", "trashCb");
let noAlbum = false;
let isAudio = false;
await setTrash(done, testNum, rOps, aOps, noAlbum, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_003
* @tc.name : trash
* @tc.desc : trash(image) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_01_003'
let rOps = imageVideoNameFetchOps(testNum, "Pictures/trashCb/", '03.jpg');
let aOps = albumFetchOps(testNum, "Pictures/", "trashCb");
let noAlbum = false;
let isAudio = false;
await recovery(done, testNum, rOps, aOps, noAlbum, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_001
* @tc.name : isTrash
* @tc.desc : isTrash(audio) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_001'
let currentFetchOp = audioNameFetchOps(testNum, 'Audios/trashCb/', '01.mp3');
let isAudio = true;
await isTrashTest(done, testNum, currentFetchOp, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_002
* @tc.name : trash
* @tc.desc : trash(audio) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_002'
let rOps = audioNameFetchOps(testNum, "Audios/trashCb/", '02.mp3');
let aOps = albumFetchOps(testNum, "Audios/", "trashCb");
let noAlbum = true;
let isAudio = true;
await setTrash(done, testNum, rOps, aOps, noAlbum, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_003
* @tc.name : trash
* @tc.desc : trash(audio) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_02_003'
let rOps = audioNameFetchOps(testNum, "Audios/trashCb/", '03.mp3');
let aOps = albumFetchOps(testNum, "Audios/", "trashCb");
let noAlbum = true;
let isAudio = true;
await recovery(done, testNum, rOps, aOps, noAlbum, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_001
* @tc.name : isTrash
* @tc.desc : isTrash(video) result false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_001', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_001'
let currentFetchOp = imageVideoNameFetchOps(testNum, 'Videos/trashCb/', '01.mp4');
let isAudio = false;
await isTrashTest(done, testNum, currentFetchOp, isAudio)
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_002
* @tc.name : trash
* @tc.desc : trash(video) by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_002', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_002'
let rOps = imageVideoNameFetchOps(testNum, "Videos/trashCb/", '02.mp4');
let aOps = albumFetchOps(testNum, "Videos/", "trashCb");
let noAlbum = true;
let isAudio = false;
await setTrash(done, testNum, rOps, aOps, noAlbum, isAudio);
});
/**
* @tc.number : SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_003
* @tc.name : trash
* @tc.desc : trash(video) by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_003', 0, async function (done) {
let testNum = 'SUB_USERFILE_MGR_FILEASSET_TRASH_CALLBACK_03_003'
let rOps = imageVideoNameFetchOps(testNum, "Videos/trashCb/", '03.mp4');
let aOps = albumFetchOps(testNum, "Videos/", "trashCb");
let noAlbum = true;
let isAudio = false;
await recovery(done, testNum, rOps, aOps, noAlbum, isAudio);
});
});
}
\ No newline at end of file
......@@ -63,7 +63,7 @@ export default function userFileMgrNoPermissionCallback(abilityContext) {
const getAlbumsTest = async function (done, testNum, media_type) {
try {
await userfile_mgr.getAlbums(media_type, allFetchOp(), async (err, albumList) => {
await userfile_mgr.getAlbums(media_type, allFetchOp(), async (err, fetchAlbumResult) => {
if (err != undefined) {
console.info(`${testNum}, err: ${err}`);
expect(true).assertTrue();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册