提交 3930ac91 编写于 作者: C caochuan

fix default param

Signed-off-by: Ncaochuan <caochuan@huawei.com>
上级 2c06949b
...@@ -36,11 +36,18 @@ const FILE_TYPE = mediaLibrary.MediaType.FILE; ...@@ -36,11 +36,18 @@ const FILE_TYPE = mediaLibrary.MediaType.FILE;
const FILEKEY = mediaLibrary.FileKey; const FILEKEY = mediaLibrary.FileKey;
const { RELATIVE_PATH, ALBUM_NAME, MEDIA_TYPE } = FILEKEY const { RELATIVE_PATH, ALBUM_NAME, MEDIA_TYPE } = FILEKEY
const sleep = async function sleep(times = 10) {
await new Promise(res => setTimeout(res, times));
}
const allFetchOp = function (others = {}) { const sleep = async function sleep(times) {
if (!times) {
times = 10;
}
await new Promise((res) => setTimeout(res, times));
};
const allFetchOp = function (others) {
if (!others) {
others = {};
}
return { return {
selections: '', selections: '',
selectionArgs: [], selectionArgs: [],
...@@ -48,7 +55,10 @@ const allFetchOp = function (others = {}) { ...@@ -48,7 +55,10 @@ const allFetchOp = function (others = {}) {
}; };
} }
const fetchOps = function (testNum, path, type, others = {}) { const fetchOps = function (testNum, path, type, others) {
if (!others) {
others = {};
}
let ops = { let ops = {
selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?', selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?',
selectionArgs: [path, type.toString()], selectionArgs: [path, type.toString()],
...@@ -84,8 +94,10 @@ const fileIdFetchOps = function (testNum, id) { ...@@ -84,8 +94,10 @@ const fileIdFetchOps = function (testNum, id) {
return ops; return ops;
}; };
const albumFetchOps = function (testNum, path, albumName, type, const albumFetchOps = function (testNum, path, albumName, type, others) {
others = { order: FILEKEY.DATE_ADDED + " DESC", }) { if (!others) {
others = { order: FILEKEY.DATE_ADDED + " DESC", };
}
let ops = { let ops = {
selections: RELATIVE_PATH + '= ? AND ' + ALBUM_NAME + '= ? AND ' + MEDIA_TYPE + '= ?', selections: RELATIVE_PATH + '= ? AND ' + ALBUM_NAME + '= ? AND ' + MEDIA_TYPE + '= ?',
selectionArgs: [path, albumName, type.toString()], selectionArgs: [path, albumName, type.toString()],
...@@ -96,8 +108,10 @@ const albumFetchOps = function (testNum, path, albumName, type, ...@@ -96,8 +108,10 @@ const albumFetchOps = function (testNum, path, albumName, type,
} }
// albums of two resource types // albums of two resource types
const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, others) {
others = { order: FILEKEY.DATE_ADDED + " DESC", }) { if (!others) {
others = { order: FILEKEY.DATE_ADDED + " DESC" };
}
try { try {
let ops = { let ops = {
selections: '(' + RELATIVE_PATH + '= ? or ' + selections: '(' + RELATIVE_PATH + '= ? or ' +
...@@ -116,7 +130,10 @@ const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, ...@@ -116,7 +130,10 @@ const albumTwoTypesFetchOps = function (testNum, paths, albumName, types,
} }
// albums of three resource types // albums of three resource types
const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, others = { order: FILEKEY.DATE_ADDED, }) { const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, others) {
if (!others) {
others = { order: FILEKEY.DATE_ADDED + " DESC" };
}
try { try {
let ops = { let ops = {
selections: '(' + RELATIVE_PATH + '= ? or ' + selections: '(' + RELATIVE_PATH + '= ? or ' +
...@@ -181,9 +198,12 @@ const checkAlbumsCount = function (done, testNum, albumList, expectCount) { ...@@ -181,9 +198,12 @@ const checkAlbumsCount = function (done, testNum, albumList, expectCount) {
return albumsCount == expectCount; return albumsCount == expectCount;
} }
const getPermission = async function (name = 'ohos.acts.multimedia.mediaLibrary') { const getPermission = async function (name) {
if (!name) {
name = "ohos.acts.multimedia.mediaLibrary";
}
console.info('getPermission start', name) console.info('getPermission start', name)
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.mediaLibrary', 0, 100); let appInfo = await bundle.getApplicationInfo(name, 0, 100);
let tokenID = appInfo.accessTokenId; let tokenID = appInfo.accessTokenId;
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1); let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1);
......
...@@ -77,6 +77,7 @@ export default function fileAssetTestCallbackTest(abilityContext) { ...@@ -77,6 +77,7 @@ export default function fileAssetTestCallbackTest(abilityContext) {
console.info(`fd1:${fd1},fd:${fd}`) console.info(`fd1:${fd1},fd:${fd}`)
await asset.close(fd); await asset.close(fd);
await asset1.close(fd1); await asset1.close(fd1);
await sleep(50);
let newFetchFileResult = await media.getFileAssets(fileIdFetchOps(testNum, asset.id)); let newFetchFileResult = await media.getFileAssets(fileIdFetchOps(testNum, asset.id));
let checkAssetCountPass = await checkAssetsCount(done, testNum, newFetchFileResult, 1); let checkAssetCountPass = await checkAssetsCount(done, testNum, newFetchFileResult, 1);
if (!checkAssetCountPass) return; if (!checkAssetCountPass) return;
......
...@@ -71,6 +71,7 @@ export default function fileAssetTestPromiseTest(abilityContext) { ...@@ -71,6 +71,7 @@ export default function fileAssetTestPromiseTest(abilityContext) {
console.info(`fd1:${fd1},fd:${fd}`) console.info(`fd1:${fd1},fd:${fd}`)
await asset.close(fd); await asset.close(fd);
await asset1.close(fd1); await asset1.close(fd1);
await sleep(50);
let newFetchFileResult = await media.getFileAssets(fileIdFetchOps(testNum, asset.id)); let newFetchFileResult = await media.getFileAssets(fileIdFetchOps(testNum, asset.id));
checkAssetCountPass = await checkAssetsCount(done, testNum, newFetchFileResult, 1); checkAssetCountPass = await checkAssetsCount(done, testNum, newFetchFileResult, 1);
if (!checkAssetCountPass) return; if (!checkAssetCountPass) return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册