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

!4027 add media library xts cases

Merge pull request !4027 from jiahaoluo/xts
......@@ -71,6 +71,53 @@ export default function fetchFileResultCallBackTest(abilityContext) {
afterAll(function () {
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_003
* @tc.name : getFirstObject
* @tc.desc : Get FetchResult, get first object, check result
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_003', 0, async function (done) {
try {
console.info('MediaLibraryTest : FETCHRESULT getFirstObject 003 begin');
let mediaType = mediaLibrary.MediaType.IMAGE;
let dir = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(dir);
let fileAsset = await media.createAsset(mediaType, 'forUri.jpg', path + 'myPicture/');
if (fileAsset == undefined) {
console.info('MediaLibraryTest : FETCHRESULT createAsset fail');
expect(false).assertTrue();
done();
return;
}
let fetchOption = {
selections: '',
selectionArgs: [],
uri: fileAsset.uri,
networkId: ''
}
let fetchFileResult = await media.getFileAssets(fetchOption);
fetchFileResult.getFirstObject(async (error, firstObject) => {
if (firstObject == undefined) {
expect(false).assertTrue();
console.info('MediaLibraryTest : FETCHRESULT getFirstObject 003 fail');
done();
} else {
expect(firstObject.displayName == 'forUri.jpg').assertTrue();
fetchFileResult.close();
console.info('MediaLibraryTest : FETCHRESULT getFirstObject 003 end');
done();
}
});
} catch (error) {
console.info('MediaLibraryTest : FETCHRESULT getFirstObject 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 004 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004
......@@ -82,7 +129,7 @@ export default function fetchFileResultCallBackTest(abilityContext) {
*/
it('SUB_MEDIA_MEDIALIBRARY_FETCHRESULT_GETFIRSTOBJECT_CALLBACK_004', 0, async function (done) {
try {
console.info('MediaLibraryTest : FETCHRESULT getFirstObject begin');
console.info('MediaLibraryTest : FETCHRESULT getFirstObject 004 begin');
let fetchFileResult = await media.getFileAssets(getFirstObjectOp);
fetchFileResult.getFirstObject(async (error, firstObject) => {
if (firstObject == undefined) {
......
......@@ -323,6 +323,73 @@ export default function filekeyTestCallBackTest(abilityContext){
it('test_fileKey_0015', 0, async function (done) {
getFileAssetsBy(done, 'audioAlbum');
});
/**
* @tc.number : test_fileKey_0016
* @tc.name : getFileAssets
* @tc.desc : filekey relative_path
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('test_fileKey_0016', 0, async function (done) {
try {
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
let fileAsset = await media.createAsset(mediaType, 'forRelative.jpg', path);
if (fileAsset == undefined) {
console.info('MediaLibraryTest : FETCHRESULT createAsset fail');
expect(false).assertTrue();
done();
return;
}
let fetchOption = {
selections: fileKeyObj.RELATIVE_PATH + '= ?',
selectionArgs: [path]
}
let fetchFileResult = await media.getFileAssets(fetchOption);
let firstObject = await fetchFileResult.getFirstObject();
expect(firstObject.relativePath == path).assertTrue();
done();
} catch (error) {
console.info('ASSET_CALLBACK test_fileKey_0016 failed, message = ' + error);
}
});
/**
* @tc.number : test_fileKey_0017
* @tc.name : getFileAssets
* @tc.desc : filekey display_name
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('test_fileKey_0017', 0, async function (done) {
try {
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
let name = 'forDisplay.jpg'
let fileAsset = await media.createAsset(mediaType, name, path);
if (fileAsset == undefined) {
console.info('MediaLibraryTest : FETCHRESULT createAsset fail');
expect(false).assertTrue();
done();
return;
}
let fetchOption = {
selections: fileKeyObj.DISPLAY_NAME + '= ?',
selectionArgs: [name]
}
let fetchFileResult = await media.getFileAssets(fetchOption);
let firstObject = await fetchFileResult.getFirstObject();
expect(firstObject.displayName == name).assertTrue();
done();
} catch (error) {
console.info('ASSET_CALLBACK test_fileKey_0017 failed, message = ' + error);
}
});
});
}
......@@ -980,7 +980,31 @@ export default function mediaLibraryTestCallBackTest(abilityContext){
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_CALLBACK_RELEASE_001
* @tc.name : release
* @tc.desc : Release MediaLibrary instance
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_CALLBACK_RELEASE_001', 0, async function (done) {
try {
console.info('MediaLibraryTest : release 001 begin');
media.release((err, data) => {
if (err == undefined) {
expect(true).assertTrue();
done();
} else {
expect(false).assertTrue();
done();
}});
} catch (error) {
console.info('MediaLibraryTest : release 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册