提交 f88666e9 编写于 作者: P panqiangbiao

fix code issue

Signed-off-by: Npanqiangbiao <panqiangbiao@huawei.com>
上级 f89b2bfe
...@@ -43,21 +43,27 @@ let filesfetchOp = { ...@@ -43,21 +43,27 @@ let filesfetchOp = {
function checkAssetAttr(done, attr, testNum, asset, checkType) { function checkAssetAttr(done, attr, testNum, asset, checkType) {
if (checkType && asset[attr] != checkType) { if (checkType && asset[attr] != checkType) {
console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${testNum} failed`); console.info(`ASSET_PROMISE getFileAssets ${testNum} failed`);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} else if (asset[attr] == undefined) { } else if (asset[attr] == undefined) {
console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${testNum} failed`); console.info(`ASSET_PROMISE getFileAssets ${testNum} failed`);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
} }
describe('file.promise.test.js', function () { let path;
let presetAsset;
let displayName;
let id;
let mediaType;
let orientation = 0;
describe('fileTestPromise.test.js', function () {
var context = featureAbility.getContext(); var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN'); console.info('getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context); var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT'); console.info('getMediaLibrary OUT');
beforeAll(function () {}); beforeAll(function () {});
beforeEach(function () {}); beforeEach(function () {});
afterEach(function () {}); afterEach(function () {});
...@@ -81,36 +87,35 @@ describe('file.promise.test.js', function () { ...@@ -81,36 +87,35 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_01', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_01', 0, async function (done) {
try { try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE); path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const fileAssets = await media.getFileAssets(imagesfetchOp); const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject(); const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0]; const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, 'image03.jpg', path); presetAsset = asset1;
const creatAsset1 = await media.createAsset(
imageType,
`${new Date().getTime()}.jpg`,
path
);
const fd1 = await asset1.open('rw'); const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw'); const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1); await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1); await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1); await asset1.close(fd1);
displayName = `${new Date().getTime()}.jpg`;
const asset2 = dataList[1]; const asset2 = dataList[1];
const creatAsset2 = await media.createAsset(imageType, 'image04.jpg', path); const creatAsset2 = await media.createAsset(imageType, displayName, path);
const fd2 = await asset2.open('rw'); const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw'); const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2); await copyFile(fd2, creatAssetFd2);
await creatAsset2.close(creatAssetFd2); await creatAsset2.close(creatAssetFd2);
await asset2.close(fd2); await asset2.close(fd2);
id = creatAsset2.id;
if (creatAsset1.id != creatAsset2.id) { mediaType = imageType;
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_01 passed'); expect(creatAsset1.id != creatAsset2.id).assertTrue();
expect(true).assertTrue(); done();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_01 failed');
expect(false).assertTrue();
done();
}
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_01 failed, message = ' + error); console.info('ASSET_PROMISE createAsset 001_01 failed, message = ' + error);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
...@@ -126,23 +131,14 @@ describe('file.promise.test.js', function () { ...@@ -126,23 +131,14 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(imagesfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'displayName', '001_02', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'displayName', '001_02', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'displayName', '001_02', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_02 passed'); expect(asset.displayName == displayName).assertTrue();
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_02 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 001_02 failed, message = ' + error);
} }
}); });
...@@ -156,83 +152,13 @@ describe('file.promise.test.js', function () { ...@@ -156,83 +152,13 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_03', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_03', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(imagesfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.relativePath == path).assertTrue();
checkAssetAttr(done, 'relativePath', '001_03', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'relativePath', '001_03', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'relativePath', '001_03', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_03 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_03 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_04
* @tc.name : getFileAssets
* @tc.desc : Access to the file size and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_04', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'size', '001_04', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'size', '001_04', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'size', '001_04', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_04 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_04 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_05
* @tc.name : getFileAssets
* @tc.desc : Access to the file dateAdded and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_05', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'dateAdded', '001_05', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'dateAdded', '001_05', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'dateAdded', '001_05', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_05 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_05 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 001_03 failed, message = ' + error);
} }
}); });
...@@ -259,27 +185,25 @@ describe('file.promise.test.js', function () { ...@@ -259,27 +185,25 @@ describe('file.promise.test.js', function () {
if (asset.dateModified != undefined) { if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) { if (newAsset.dateModified != asset.dateModified) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 passed'); console.info('ASSET_PROMISE getFileAssets 001_07 passed');
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
} else { } else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed'); console.info('ASSET_PROMISE getFileAssets 001_07 failed');
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
} else if (newAsset.dateModified != undefined) {
console.info('ASSET_PROMISE getFileAssets 001_07 passed');
expect(true).assertTrue();
done();
} else { } else {
if (newAsset.dateModified != undefined) { console.info('ASSET_PROMISE getFileAssets 001_07 failed');
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 passed'); expect(false).assertTrue();
expect(true).assertTrue(); done();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed');
expect(false).assertTrue();
done();
}
} }
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error);
} }
}); });
...@@ -293,83 +217,13 @@ describe('file.promise.test.js', function () { ...@@ -293,83 +217,13 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_08', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_08', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(imagesfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.mediaType == mediaType).assertTrue();
checkAssetAttr(done, 'mediaType', '001_08', firstAsset, imageType);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'mediaType', '001_08', midAsset, imageType);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'mediaType', '001_08', lastAsset, imageType);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_08 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_08 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_09
* @tc.name : getFileAssets
* @tc.desc : Get the width attribute
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_09', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'width', '001_09', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'width', '001_09', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'width', '001_09', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_09 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_09 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_10
* @tc.name : createAsset
* @tc.desc : Get the height attribute
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_10', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'height', '001_10', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'height', '001_10', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'height', '001_10', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_10 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_10 failed, message = ' + error); console.info('ASSET_PROMISE createAsset 001_08 failed, message = ' + error);
} }
}); });
...@@ -383,61 +237,16 @@ describe('file.promise.test.js', function () { ...@@ -383,61 +237,16 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_11', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_11', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(imagesfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.orientation == orientation).assertTrue();
checkAssetAttr(done, 'orientation', '001_11', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'orientation', '001_11', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'orientation', '001_11', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_11 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_11 failed, message = ' + error); console.info('ASSET_PROMISE createAsset 001_11 failed, message = ' + error);
} }
}); });
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_12
* @tc.name : createAsset
* @tc.desc : Insert a picture record and get the property as picture
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_12', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, 'image3.jpg', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
if (creatAsset1.mediaType == imageType) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_12 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_12 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_12 failed ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------- image type end ----------------------------- // ------------------------------- image type end -----------------------------
// ------------------------------- video type start ---------------------------- // ------------------------------- video type start ----------------------------
...@@ -451,35 +260,35 @@ describe('file.promise.test.js', function () { ...@@ -451,35 +260,35 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_01', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_01', 0, async function (done) {
try { try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
const fileAssets = await media.getFileAssets(videosfetchOp); const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject(); const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0]; const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(videoType, 'video03.mp4', path); const creatAsset1 = await media.createAsset(
videoType,
`${new Date().getTime()}.mp4`,
path
);
const fd1 = await asset1.open('rw'); const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw'); const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1); await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1); await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1); await asset1.close(fd1);
displayName = `${new Date().getTime()}.mp4`;
const asset2 = dataList[0]; const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(videoType, 'video04.mp4', path); const creatAsset2 = await media.createAsset(videoType, displayName, path);
const fd2 = await asset2.open('rw'); const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw'); const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2); await copyFile(fd2, creatAssetFd2);
await creatAsset2.close(creatAssetFd2); await creatAsset2.close(creatAssetFd2);
await asset2.close(fd2); await asset2.close(fd2);
if (creatAsset1.id != creatAsset2.id) { id = creatAsset2.id;
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 passed'); mediaType = videoType;
expect(true).assertTrue();
done(); expect(creatAsset1.id != creatAsset2.id).assertTrue();
} else { done();
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 failed');
expect(false).assertTrue();
done();
}
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 failed' + error); console.info('ASSET_PROMISE createAsset 002_01 failed' + error);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
...@@ -495,23 +304,14 @@ describe('file.promise.test.js', function () { ...@@ -495,23 +304,14 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_02', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_02', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(videosfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'displayName', '002_02', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'displayName', '002_02', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'displayName', '002_02', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_02 passed'); expect(asset.displayName == displayName).assertTrue();
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_02 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 002_02 failed, message = ' + error);
} }
}); });
...@@ -525,83 +325,14 @@ describe('file.promise.test.js', function () { ...@@ -525,83 +325,14 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_03', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_03', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(videosfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'relativePath', '002_04', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'relativePath', '002_04', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'relativePath', '002_04', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_03 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_03 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_04
* @tc.name : getFileAssets
* @tc.desc : Access to the file size and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_04', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'size', '002_04', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'size', '002_04', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'size', '002_04', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_04 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_04 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_05
* @tc.name : getFileAssets
* @tc.desc : Access to the file dateAdded and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_05', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'dateAdded', '002_05', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'dateAdded', '002_05', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'dateAdded', '002_05', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_05 passed'); expect(asset.relativePath == path).assertTrue();
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_05 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 002_03 failed, message = ' + error);
} }
}); });
...@@ -628,27 +359,25 @@ describe('file.promise.test.js', function () { ...@@ -628,27 +359,25 @@ describe('file.promise.test.js', function () {
if (asset.dateModified != undefined) { if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) { if (newAsset.dateModified != asset.dateModified) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 passed'); console.info('ASSET_PROMISE getFileAssets 002_07 passed');
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
} else { } else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed'); console.info('ASSET_PROMISE getFileAssets 002_07 failed');
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
} else if (newAsset.dateModified != undefined) {
console.info('ASSET_PROMISE getFileAssets 002_07 passed');
expect(true).assertTrue();
done();
} else { } else {
if (newAsset.dateModified != undefined) { console.info('ASSET_PROMISE getFileAssets 002_07 failed');
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 passed'); expect(false).assertTrue();
expect(true).assertTrue(); done();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed');
expect(false).assertTrue();
done();
}
} }
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error);
} }
}); });
...@@ -662,226 +391,78 @@ describe('file.promise.test.js', function () { ...@@ -662,226 +391,78 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_08', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_08', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(videosfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.mediaType == mediaType).assertTrue();
checkAssetAttr(done, 'mediaType', '002_08', firstAsset, videoType);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'mediaType', '002_08', midAsset, videoType);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'mediaType', '002_08', lastAsset, videoType);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_08 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_08 failed, message = ' + error); console.info('ASSET_PROMISE createAsset 002_08 failed, message = ' + error);
} }
}); });
/** /**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_09 * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11
* @tc.name : getFileAssets * @tc.name : createAsset
* @tc.desc : Get the width attribute * @tc.desc : Get the orientaion attribute
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_09', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(videosfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.orientation == orientation).assertTrue();
checkAssetAttr(done, 'width', '002_09', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'width', '002_09', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'width', '002_09', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_09 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_09 failed, message = ' + error); console.info('ASSET_PROMISE createAsset 002_11 failed, message = ' + error);
} }
}); });
// ------------------------------- video type end -----------------------------
// ------------------------------- audio type start ----------------------------
/** /**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_10 * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01
* @tc.name : createAsset * @tc.name : createAsset
* @tc.desc : Get the height attribute * @tc.desc : Insert two database records, read a unique identifier, expectations are not equal
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_10', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(videosfetchOp); path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO);
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject(); const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const firstAsset = dataList[0]; const creatAsset1 = await media.createAsset(
checkAssetAttr(done, 'height', '002_10', firstAsset); audioType,
`${new Date().getTime()}.mp3`,
const midAsset = dataList[Math.floor(dataList.length / 2)]; path
checkAssetAttr(done, 'height', '002_10', midAsset); );
const fd1 = await asset1.open('rw');
const lastAsset = dataList[dataList.length - 1]; const creatAssetFd1 = await creatAsset1.open('rw');
checkAssetAttr(done, 'height', '002_10', lastAsset); await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_10 passed'); await asset1.close(fd1);
expect(true).assertTrue(); displayName = `${new Date().getTime()}.mp3`;
const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(audioType, displayName, path);
const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2);
await creatAsset2.close(creatAssetFd2);
await asset2.close(fd2);
id = creatAsset2.id;
mediaType = audioType;
expect(creatAsset1.id != creatAsset2.id).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_10 failed, message = ' + error); console.info('ASSET_PROMISE createAsset 003_01 failed');
} expect(false).assertTrue();
}); done();
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11
* @tc.name : createAsset
* @tc.desc : Get the orientaion attribute
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'orientation', '002_11', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'orientation', '002_11', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'orientation', '002_11', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_11 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_11 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_12
* @tc.name : createAsset
* @tc.desc : Get the duration attribute
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_12', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'duration', '002_12', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'duration', '002_12', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'duration', '002_12', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_12 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_12 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_13
* @tc.name : createAsset
* @tc.desc : Insert a picture record and get the property as picture
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_13', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(videoType, 'video3.mp4', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
if (creatAsset1.mediaType == videoType) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_13 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_13 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_13 failed');
expect(false).assertTrue();
done();
}
});
// ------------------------------- video type end -----------------------------
// ------------------------------- audio type start ----------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01
* @tc.name : createAsset
* @tc.desc : Insert two database records, read a unique identifier, expectations are not equal
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO);
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(audioType, 'audio03.mp3', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(audioType, 'audio04.mp3', path);
const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2);
await creatAsset2.close(creatAssetFd2);
await asset2.close(fd2);
if (creatAsset1.id != creatAsset2.id) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_01 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_01 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_01 failed');
expect(false).assertTrue();
done();
} }
}); });
...@@ -895,23 +476,14 @@ describe('file.promise.test.js', function () { ...@@ -895,23 +476,14 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(audiosfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.displayName == displayName).assertTrue();
checkAssetAttr(done, 'displayName', '003_02', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'displayName', '003_02', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'displayName', '003_02', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_02 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_02 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 003_02 failed, message = ' + error);
} }
}); });
...@@ -925,83 +497,13 @@ describe('file.promise.test.js', function () { ...@@ -925,83 +497,13 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(audiosfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.relativePath == path).assertTrue();
checkAssetAttr(done, 'relativePath', '003_03', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'relativePath', '003_03', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'relativePath', '003_03', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_03 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_03 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_04
* @tc.name : getFileAssets
* @tc.desc : Access to the file size and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_04', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'size', '003_04', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'size', '003_04', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'size', '003_04', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_04 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_04 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_05
* @tc.name : getFileAssets
* @tc.desc : Access to the file dateAdded and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_05', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'dateAdded', '003_05', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'dateAdded', '003_05', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'dateAdded', '003_05', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_05 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_05 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 003_03 failed, message = ' + error);
} }
}); });
...@@ -1029,27 +531,25 @@ describe('file.promise.test.js', function () { ...@@ -1029,27 +531,25 @@ describe('file.promise.test.js', function () {
if (asset.dateModified != undefined) { if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) { if (newAsset.dateModified != asset.dateModified) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 passed'); console.info('ASSET_PROMISE getFileAssets 003_07 passed');
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
} else { } else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed'); console.info('ASSET_PROMISE getFileAssets 003_07 failed');
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
} else if (newAsset.dateModified != undefined) {
console.info('ASSET_PROMISE getFileAssets 003_07 passed');
expect(true).assertTrue();
done();
} else { } else {
if (newAsset.dateModified != undefined) { console.info('ASSET_PROMISE getFileAssets 003_07 failed');
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 passed'); expect(false).assertTrue();
expect(true).assertTrue(); done();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed');
expect(false).assertTrue();
done();
}
} }
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 003_07 failed, message = ' + error);
} }
}); });
...@@ -1063,154 +563,19 @@ describe('file.promise.test.js', function () { ...@@ -1063,154 +563,19 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_08', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_08', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(audiosfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.mediaType == mediaType).assertTrue();
checkAssetAttr(done, 'mediaType', '003_08', firstAsset, audioType);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'mediaType', '003_08', midAsset, audioType);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'mediaType', '003_08', lastAsset, audioType);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_08 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_08 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_09
* @tc.name : getFileAssets
* @tc.desc : Get the artist attribute
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_09', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'width', '003_09', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'width', '003_09', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'width', '003_09', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_09 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_09 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_10
* @tc.name : createAsset
* @tc.desc : Get the album attribute
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_10', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'albumName', '003_10', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'albumName', '003_10', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'albumName', '003_10', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_10 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_10 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_11
* @tc.name : createAsset
* @tc.desc : Get the duration attribute
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_11', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'duration', '003_11', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'duration', '003_11', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'duration', '003_11', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_11 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_11 failed, message = ' + error); console.info('ASSET_PROMISE createAsset 003_08 failed, message = ' + error);
} }
}); });
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_12
* @tc.name : createAsset
* @tc.desc : Insert a picture record and get the property as picture
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_12', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO);
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(audioType, 'audio3.mp3', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
if (creatAsset1.mediaType == audioType) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_12 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_12 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_12 failed');
expect(false).assertTrue();
done();
}
});
// ------------------------------- audio type end ----------------------------- // ------------------------------- audio type end -----------------------------
// ------------------------------- file type start ---------------------------- // ------------------------------ file type start ----------------------------
/** /**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01 * @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01
* @tc.name : createAsset * @tc.name : createAsset
...@@ -1221,36 +586,34 @@ describe('file.promise.test.js', function () { ...@@ -1221,36 +586,34 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01', 0, async function (done) {
try { try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD); path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD);
const fileAssets = await media.getFileAssets(filesfetchOp); const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject(); const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0]; const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(fileType, 'file03.txt', path); const creatAsset1 = await media.createAsset(
fileType,
`${new Date().getTime()}.bat`,
path
);
const fd1 = await asset1.open('rw'); const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw'); const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1); await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1); await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1); await asset1.close(fd1);
displayName = `${new Date().getTime()}.bat`;
const asset2 = dataList[0]; const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(fileType, 'file04.txt', path); const creatAsset2 = await media.createAsset(fileType, displayName, path);
const fd2 = await asset2.open('rw'); const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw'); const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2); await copyFile(fd2, creatAssetFd2);
await creatAsset2.close(creatAssetFd2); await creatAsset2.close(creatAssetFd2);
await asset2.close(fd2); await asset2.close(fd2);
id = creatAsset2.id;
if (creatAsset1.id != creatAsset2.id) { mediaType = fileType;
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 passed'); expect(creatAsset1.id != creatAsset2.id).assertTrue();
expect(true).assertTrue(); done();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 failed');
expect(false).assertTrue();
done();
}
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 failed' + error); console.info('ASSET_PROMISE createAsset 004_01 failed' + error);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
...@@ -1266,23 +629,13 @@ describe('file.promise.test.js', function () { ...@@ -1266,23 +629,13 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_02', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_02', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(filesfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.displayName == displayName).assertTrue();
checkAssetAttr(done, 'displayName', '004_02', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'displayName', '004_02', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'displayName', '004_02', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_02 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_02 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 004_02 failed, message = ' + error);
} }
}); });
...@@ -1296,83 +649,13 @@ describe('file.promise.test.js', function () { ...@@ -1296,83 +649,13 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_03', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_03', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(filesfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.relativePath == path).assertTrue();
checkAssetAttr(done, 'relativePath', '004_03', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'relativePath', '004_03', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'relativePath', '004_03', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_03 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_03 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_04
* @tc.name : getFileAssets
* @tc.desc : Access to the file size and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_04', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'size', '004_04', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'size', '004_04', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'size', '004_04', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_04 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_04 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_05
* @tc.name : getFileAssets
* @tc.desc : Access to the file dateAdded and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_05', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
checkAssetAttr(done, 'dateAdded', '004_05', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'dateAdded', '004_05', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'dateAdded', '004_05', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_05 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_05 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 004_03 failed, message = ' + error);
} }
}); });
...@@ -1399,27 +682,25 @@ describe('file.promise.test.js', function () { ...@@ -1399,27 +682,25 @@ describe('file.promise.test.js', function () {
if (asset.dateModified != undefined) { if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) { if (newAsset.dateModified != asset.dateModified) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 passed'); console.info('ASSET_PROMISE getFileAssets 004_07 passed');
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
} else { } else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed'); console.info('ASSET_PROMISE getFileAssets 004_07 failed');
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} }
} else if (newAsset.dateModified != undefined) {
console.info('ASSET_PROMISE getFileAssets 004_07 passed');
expect(true).assertTrue();
done();
} else { } else {
if (newAsset.dateModified != undefined) { console.info('ASSET_PROMISE getFileAssets 004_07 failed');
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 passed'); expect(false).assertTrue();
expect(true).assertTrue(); done();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed');
expect(false).assertTrue();
done();
}
} }
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error); console.info('ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error);
} }
}); });
...@@ -1433,61 +714,16 @@ describe('file.promise.test.js', function () { ...@@ -1433,61 +714,16 @@ describe('file.promise.test.js', function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_08', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_08', 0, async function (done) {
try { try {
const fileAssets = await media.getFileAssets(filesfetchOp); const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const dataList = await fileAssets.getAllObject(); const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const firstAsset = dataList[0]; expect(asset.mediaType == mediaType).assertTrue();
checkAssetAttr(done, 'mediaType', '004_08', firstAsset, fileType);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'mediaType', '004_08', midAsset, fileType);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'mediaType', '004_08', lastAsset, fileType);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_08 passed');
expect(true).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_08 failed, message = ' + error); console.info('ASSET_PROMISE createAsset 004_08 failed, message = ' + error);
} }
}); });
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_09
* @tc.name : createAsset
* @tc.desc : Insert two database records, read a unique identifier, expectations are not equal
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_09', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD);
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(fileType, 'file3.txt', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
if (creatAsset1.mediaType == fileType) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_09 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_09 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_09 failed');
expect(false).assertTrue();
done();
}
});
// ------------------------------- file type end ----------------------------- // ------------------------------- file type end -----------------------------
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册