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

!2165 add more xts

Merge pull request !2165 from 潘强标/master
......@@ -2,9 +2,9 @@
"description": "Configuration for mediaLibrary Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "120000",
"test-timeout": "600000",
"package": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "120000"
"shell-timeout": "600000"
},
"kits": [
{
......
......@@ -13,5 +13,11 @@
* limitations under the License.
*/
require('./favoriteTestCallBack.test.js')
require('./favoriteTestPromise.test.js')
require('./fileTestPromise.test.js')
require('./favoriteTestPromise.test.js')
require('./fileAsset2.test.js')
require('./fileAssetTestPromise.test.js')
require('./mediaLibraryTestPromise.test.js')
require('./albumGetFileAssetsPromise.test.js')
require('./albumTestPromise.test.js')
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
describe('fileAssetTestPromise.test.js', async function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
afterAll(function () {});
const fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
const count = 3;
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01
* @tc.name : getFileAssets
* @tc.desc : more file type all
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function (done) {
try {
let allTypefetchOp = {
selections: '',
selectionArgs: [],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02
* @tc.name : getFileAssets
* @tc.desc : more file type image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function (done) {
try {
let imageAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03
* @tc.name : getFileAssets
* @tc.desc : more file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function (done) {
try {
let audioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(audioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(audioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04
* @tc.name : getFileAssets
* @tc.desc : more file type video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function (done) {
try {
let videoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(videoAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(videoAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05
* @tc.name : getFileAssets
* @tc.desc : more file type image and video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function (done) {
try {
let imageAndVideoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAndVideoAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06
* @tc.name : getFileAssets
* @tc.desc : more file type image and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function (done) {
try {
let imageAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/** order: 'date_added DESC LIMIT 0,500'
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07
* @tc.name : getFileAssets
* @tc.desc : more file type video and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function (done) {
try {
let videoAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(videoAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08
* @tc.name : getFileAssets
* @tc.desc : more file type image video and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08', 0, async function (done) {
try {
let imgAndVideoAndAudioAlbumfetchOp = {
selections:
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: [imageType.toString(), videoType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imgAndVideoAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imgAndVideoAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09
* @tc.name : getFileAssets
* @tc.desc : one file tpe image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10
* @tc.name : getFileAssets
* @tc.desc : one file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11
* @tc.name : getFileAssets
* @tc.desc : one file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12
* @tc.name : getFileAssets
* @tc.desc : no file type image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13
* @tc.name : getFileAssets
* @tc.desc : no file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14
* @tc.name : getFileAssets
* @tc.desc : no file type video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
let fileKeyObj = mediaLibrary.FileKey;
let mediaType = mediaLibrary.MediaType.IMAGE;
let mediaType2 = mediaLibrary.MediaType.VIDEO;
let AlbumNoArgsfetchOp = {
selections: '',
selectionArgs: [],
};
let AlbumHasArgsfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [mediaType.toString()],
};
let fileHasArgsfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [mediaType.toString()],
};
let fileNoArgsfetchOp = {
selections: '',
selectionArgs: [],
};
describe('album.promise.test.js', async function () {
let path = 'Pictures/';
console.info('MediaLibraryTest : Delete begin');
let fetchFileResult = await media.getFileAssets(fileNoArgsfetchOp);
let assetList = await fetchFileResult.getAllObject();
assetList.forEach(getAllObjectInfoDelete);
console.info('MediaLibraryTest : Delete end');
await media.createAsset(mediaType, 'imageAlbum0003.jpg', path);
await media.createAsset(mediaType2, 'imageAlbum0004.avi', path);
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function () {
console.info('Album Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
});
beforeEach(function () {
console.info('Album Promise MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.');
});
afterEach(function () {
console.info('Album Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
});
afterAll(function () {
console.info('Album Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01
* @tc.name : media.getAlbums
* @tc.desc : Get Album by AlbumNoArgsfetchOp
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 album.albumName = ' + album.albumName);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 album.count = ' + album.count);
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02
* @tc.name : media.getAlbums
* @tc.desc : Get Album by null
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) {
try {
const albumList = await media.getAlbums();
const album = albumList[0];
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_02 album.albumName = ' + album.albumName);
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_02 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01
* @tc.name : media.getAlbums
* @tc.desc : Get Album by AlbumHasArgsfetchOp
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumHasArgsfetchOp);
const album = albumList[0];
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_01 albumHas.albumName = ' + album.albumName);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 002_01 album.count = ' + album.count);
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_01 fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02
* @tc.name : media.getAlbums
* @tc.desc : Get Album by 666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02', 0, async function (done) {
try {
await media.getAlbums(666);
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_02 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03
* @tc.name : media.getAlbums
* @tc.desc : Get Album by '666'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03', 0, async function (done) {
try {
await media.getAlbums('666');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_03 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04
* @tc.name : media.getAlbums
* @tc.desc : Get Album by 0.666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04', 0, async function (done) {
try {
await media.getAlbums(0.666);
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_04 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05
* @tc.name : media.getAlbums
* @tc.desc : Get Album by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05', 0, async function (done) {
try {
await media.getAlbums(true);
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_05 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01
* @tc.name : album.commitModify
* @tc.desc : Modify Album name 'hello'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName);
album.albumName = 'hello';
await album.commitModify();
expect(true).assertTrue();
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 album.albumName(new) = ' + album.albumName);
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 fail, message = ' + error);
expect(false).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02
* @tc.name : album.commitModify
* @tc.desc : Modify Album name ''
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
album.albumName = '';
await album.commitModify();
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_02 album.albumName = ' + album.albumName);
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_02 fail, message = ' + error);
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003
* @tc.name : album.commitModify
* @tc.desc : Modify Album name '?*hello'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_03', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
album.albumName = '?*hello';
await album.commitModify();
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_03 album.albumName = ' + album.albumName);
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_03 fail, message = ' + error);
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04
* @tc.name : album.commitModify
* @tc.desc : Modify Album name 'i123456...119'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
var name = 'i';
for (var i = 0; i < 120; i++) {
title += 'i';
}
album.albumName = name;
await album.commitModify();
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_04 album.albumName = ' + album.albumName);
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_04 fail, message = ' + error);
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004_01
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileNoArgsfetchOp
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
let albumFetchFileResult = await album.getFileAssets(fileNoArgsfetchOp);
let albumAssetList = await albumFetchFileResult.getAllObject();
albumAssetList.forEach(getAllObjectInfo);
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 004_01 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 004_01 fail, message = ' + error);
expect(false).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004_02
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by null
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_004_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
let albumFetchFileResult = await album.getFileAssets();
let albumAssetList = await albumFetchFileResult.getAllObject();
albumAssetList.forEach(getAllObjectInfo);
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 004_02 success');
expect(true).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 004_02 fail, message = ' + error);
expect(false).assertTrue();
done();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_01
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
let albumFetchFileResult = await album.getFileAssets(fileHasArgsfetchOp);
let albumAssetList = await albumFetchFileResult.getAllObject();
albumAssetList.forEach(getAllObjectInfo);
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_01 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_01 fail, message = ' + error);
expect(false).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_02
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp2
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_02', 0, async function (done) {
let type2 = mediaLibrary.MediaType.VIDEO;
let fileHasArgsfetchOp2 = {
selections: fileKeyObj.MEDIA_TYPE + ' = ?',
selectionArgs: [type2.toString()],
};
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
await album.getFileAssets(fileHasArgsfetchOp2);
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_02 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_02 fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_03
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp3
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_03', 0, async function (done) {
let fileHasArgsfetchOp3 = {
selections: fileKeyObj.MEDIA_TYPE + ' = ?',
selectionArgs: ['666'],
};
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
await album.getFileAssets(fileHasArgsfetchOp3);
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_03 success');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_03 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_04
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp4
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_04', 0, async function (done) {
let type4 = mediaLibrary.MediaType.VIDEO;
let fileHasArgsfetchOp4 = {
selections: '666' + '= ?',
selectionArgs: [type4.toString()],
};
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
await album.getFileAssets(fileHasArgsfetchOp4);
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_04 success');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_04 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_05
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp5
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_005_05', 0, async function (done) {
let fileHasArgsfetchOp5 = {
selections: '666' + '= ?',
selectionArgs: ['666'],
};
try {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
await album.getFileAssets(fileHasArgsfetchOp5);
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_05 success');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 005_05 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
function getAllObjectInfo(data) {
if (data != undefined) {
console.info('MediaLibraryTest : ALBUM_PROMISE id is ' + data.id);
console.info('MediaLibraryTest : ALBUM_PROMISE uri is ' + data.uri);
console.info('MediaLibraryTest : ALBUM_PROMISE displayName is ' + data.displayName);
console.info('MediaLibraryTest : ALBUM_PROMISE mediaType is ' + data.title);
console.info('MediaLibraryTest : ALBUM_PROMISE relativePath is ' + data.relativePath);
} else {
console.info('MediaLibraryTest : ALBUM_PROMISE getAllObjectInfo no album');
}
}
function getAllObjectInfoDelete(data3) {
console.info('MediaLibraryTest : id is ' + data3.id);
console.info('MediaLibraryTest : uri is ' + data3.uri);
console.info('MediaLibraryTest : displayName is ' + data3.displayName);
console.info('MediaLibraryTest : mediaType is ' + data3.mediaType);
media.deleteAsset(data3.uri, (err4, data4) => {
if (data4 == 0) {
console.info('MediaLibraryTest : Delete Album Successfull ' + data4);
console.info('MediaLibraryTest : Delete Asset : PASS');
} else {
console.info('MediaLibraryTest : Album is not modified ' + err4.message);
console.info('MediaLibraryTest : Modify Asset : FAIL');
}
});
}
});
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let allTypefetchOp = {
selections: '',
selectionArgs: [],
};
let imageAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
let videoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
};
let audioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
};
let imageAndVideoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString()],
};
let imageAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), audioType.toString()],
};
let videoAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString(), audioType.toString()],
};
function printAlbumMessage(testNum, album) {
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumId: ${album.albumId}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumName: ${album.albumName}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumUri: ${album.albumUri}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.dateModified: ${album.dateModified}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.count: ${album.count}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.relativePath: ${album.relativePath}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.coverUri: ${album.coverUri}`);
}
function checkAlbumAttr(done, album) {
if (
album.albumId == undefined ||
album.albumName == undefined ||
album.albumUri == undefined ||
album.count == undefined ||
album.relativePath == undefined ||
album.coverUri == undefined
) {
console.info('ALBUM_PROMISE getAlbum 001_01 failed');
expect(false).assertTrue();
done();
}
}
describe('album.promise.test.js', async function () {
var context = featureAbility.getContext();
var media = mediaLibrary.getMediaLibrary(context);
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
afterAll(function () {});
// ------------------------------ 001 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01
* @tc.name : getAlbums
* @tc.desc : Get Album by AllTypefetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
printAlbumMessage('001_01', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_01 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_02', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_02 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_02 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03
* @tc.name : getAlbums
* @tc.desc : Get Album by videoAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03', 0, async function (done) {
try {
const albumList = await media.getAlbums(videoAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_03', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_03 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_03 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04
* @tc.name : getAlbums
* @tc.desc : Get Album by audioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04', 0, async function (done) {
try {
const albumList = await media.getAlbums(audioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_04', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_04 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_04 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAndVideoAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_05', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_05 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_05 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAndAudioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_06', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_06 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_06 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07
* @tc.name : getAlbums
* @tc.desc : Get Album by videoAndAudioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07', 0, async function (done) {
try {
const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_07', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_07 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_07 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 001 test end -------------------------
// ------------------------------ 002 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01
* @tc.name : getAlbums
* @tc.desc : Get Album by 666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01', 0, async function (done) {
try {
await media.getAlbums(666);
expect(false).assertTrue();
console.info('ALBUM_PROMISE getalbum 002_01 failed');
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_01 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02
* @tc.name : getAlbums
* @tc.desc : Get Album by '666'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02', 0, async function (done) {
try {
await media.getAlbums('666');
console.info('ALBUM_PROMISE getalbum 002_02 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_02 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03
* @tc.name : getAlbums
* @tc.desc : Get Album by 0
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03', 0, async function (done) {
try {
await media.getAlbums(0);
console.info('ALBUM_PROMISE getalbum 002_03 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_03 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04
* @tc.name : getAlbums
* @tc.desc : Get Album by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04', 0, async function (done) {
try {
await media.getAlbums(true);
console.info('ALBUM_PROMISE getalbum 002_04 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_04 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05
* @tc.name : getAlbums
* @tc.desc : Get Album by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05', 0, async function (done) {
try {
await media.getAlbums(false);
console.info('ALBUM_PROMISE getalbum 002_05 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_05 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp3
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06', 0, async function (done) {
let fileHasArgsfetchOp3 = {
selections: fileKeyObj.MEDIA_TYPE + ' = ?',
selectionArgs: ['666'],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp3);
console.info(
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getFileAssets 002_06 passed');
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp4
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07', 0, async function (done) {
let fileHasArgsfetchOp4 = {
selections: '666' + '= ?',
selectionArgs: [videoType.toString()],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp4);
console.info(
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getFileAssets 002_07 passed');
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp5
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08', 0, async function (done) {
let fileHasArgsfetchOp5 = {
selections: '666' + '= ?',
selectionArgs: ['666'],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp5);
console.info(
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getFileAssets 002_08 passed');
expect(false).assertTrue();
done();
}
});
// ------------------------------ 002 test end -------------------------
// ------------------------------ 003 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01
* @tc.name : commitModify
* @tc.desc : Modify Album name to 'hello'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName);
const newName = 'newhello';
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let passed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_01 passed');
expect(true).assertTrue();
done();
passed = true;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_01 failed, message = ' + error);
expect(false).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02
* @tc.name : commitModify
* @tc.desc : Modify Album name ''
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_02 album.albumName(old) = ' + album.albumName);
const newName = '';
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_02 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_02 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04
* @tc.name : commitModify
* @tc.desc : Modify Album name 'i123456...119'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_04 album.albumName(old) = ' + album.albumName);
let newName = true;
for (var i = 0; i < 1200; i++) {
newName += 'i';
}
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_04 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_04 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05
* @tc.name : commitModify
* @tc.desc : Modify Album name true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_05 album.albumName(old) = ' + album.albumName);
const newName = true;
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_05 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_05 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06
* @tc.name : commitModify
* @tc.desc : Modify Album name false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_06 album.albumName(old) = ' + album.albumName);
const newName = false;
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_06 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_06 passed');
expect(true).assertTrue();
}
done();
});
// ------------------------------ 003 test end -------------------------
// ------------------------------ 004 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01
* @tc.name : album.coverUri
* @tc.desc : check album.coverUri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
const asset = await fetchFileResult.getFirstObject();
expect(asset.uri == album.coverUri).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 004_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 004 test end -------------------------
// ------------------------------ 006 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01
* @tc.name : commitModify
* @tc.desc : Modify Album albumUri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
album.albumUri = 'testalbumUri';
await album.commitModify();
console.info('ALBUM_PROMISE Modify 006_01 failed');
expect(false).assertTrue();
} catch (error) {
console.info('ALBUM_PROMISE Modify 006_01 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02
* @tc.name : commitModify
* @tc.desc : Modify Album name false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
album.coverUri = 'testcoverUri';
await album.commitModify();
console.info('ALBUM_PROMISE Modify 006_02 failed');
expect(false).assertTrue();
} catch (error) {
console.info('ALBUM_PROMISE Modify 006_02 passed');
expect(true).assertTrue();
}
done();
});
// ------------------------------ 006 test end -------------------------
// ------------------------------ 005 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01
* @tc.name : deleteAsset
* @tc.desc : delete album
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
let fetchFileResult = await album.getFileAssets(allTypefetchOp);
let datas = await fetchFileResult.getAllObject();
for (let j = 0; j < datas.length; j++) {
const asset = datas[j];
await media.deleteAsset(asset.uri);
}
const albumId = album.albumId;
const newAlbumList = await media.getAlbums(allTypefetchOp);
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId) {
console.info('ALBUM_PROMISE getAlbum 005_01 failed');
expect(false).assertTrue();
done();
}
}
console.info('ALBUM_PROMISE getAlbum 005_01 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 005_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 005 test end -------------------------
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
function printAttr(asset) {
for (const key in asset) {
console.info(`${key}: asset[key]`);
}
}
function checkAttrs(done, asset, tNum) {
let passed = true;
for (const key in asset) {
if (asset[key] == undefined) {
passed = false;
break;
}
}
if (passed) {
console.info(`FileAsset checkAttrs ${tNum} passed`);
expect(true).assertTrue();
done();
} else {
console.info(`FileAsset checkAttrs ${tNum} failed`);
expect(false).assertTrue();
done();
}
}
describe('fileAsset2.test.js', async function () {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let imagesfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
let videosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
};
let audiosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
};
let allTypefetchOp = {
selections: '',
selectionArgs: [],
};
const context = featureAbility.getContext();
const media = mediaLibrary.getMediaLibrary(context);
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
afterAll(function () {});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_001
* @tc.name : commitModify
* @tc.desc : Modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const newName = 'newName';
asset.displayName = newName;
const id = asset.id;
await asset.commitModify();
const fetchFileResult2 = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult2.getAllObject();
let passed = false;
for (let i = 0; i < dataList.length; i++) {
const asset = dataList[i];
if (asset.id == id && asset.displayName == newName) {
passed = true;
break;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAsset commitModify 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_002
* @tc.name : commitModify
* @tc.desc : Modify title
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const newTitle = 'newTitle';
asset.title = newTitle;
const id = asset.id;
await asset.commitModify();
const fetchFileResult2 = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult2.getAllObject();
let passed = false;
for (let i = 0; i < dataList.length; i++) {
const asset = dataList[i];
if (asset.id == id && asset.title == newTitle) {
passed = true;
break;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAsset commitModify 002 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_003
* @tc.name : commitModify
* @tc.desc : Modify relativePath
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_003', 0, async function (done) {
try {
const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const path2 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
let relativePath = asset.relativePath;
let newrelativePath = path1;
if (relativePath == path1) {
newrelativePath = path2;
}
asset.relativePath = newrelativePath;
const id = asset.id;
await asset.commitModify();
const fetchFileResult2 = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult2.getAllObject();
let passed = false;
for (let i = 0; i < dataList.length; i++) {
const asset = dataList[i];
if (asset.id == id && asset.relativePath == newrelativePath) {
passed = true;
break;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAsset commitModify 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_004
* @tc.name : commitModify
* @tc.desc : Modify orientation
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_004', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
let neworientation = 1;
if (asset.orientation == 1) {
neworientation = 0;
}
asset.orientation = neworientation;
const id = asset.id;
await asset.commitModify();
const fetchFileResult2 = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult2.getAllObject();
let passed = false;
for (let i = 0; i < dataList.length; i++) {
const asset = dataList[i];
if (asset.id == id && asset.orientation == neworientation) {
passed = true;
break;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAsset commitModify 004 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_005
* @tc.name : commitModify
* @tc.desc : Modify uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_005', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const id = asset.id;
const newUri = 'newUri';
asset.uri = newUri;
await asset.commitModify();
console.info('FileAsset commitModify 005 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('FileAsset commitModify 005 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_006
* @tc.name : commitModify
* @tc.desc : Modify mediaType
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_006', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const id = asset.id;
const newMediaType = 'newMediaType';
asset.mediaType = newMediaType;
await asset.commitModify();
console.info('FileAsset commitModify 006 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('FileAsset commitModify 006 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_isDirectory_promise_001
* @tc.name : isDirectory
* @tc.desc : isDirectory asset
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const isDir = await asset.isDirectory();
expect(!isDir).assertTrue();
done();
} catch (error) {
console.info('FileAsset isDirectory 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_001
* @tc.name : attrs
* @tc.desc : imagesfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_promise_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done, asset, '001');
} catch (error) {
console.info('FileAsset checkAttr 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_002
* @tc.name : attrs
* @tc.desc : videosfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_promise_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(videosfetchOp);
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done, asset, '002');
} catch (error) {
console.info('FileAsset checkAttr 002 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_003
* @tc.name : attrs
* @tc.desc : audiosfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_promise_003', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(audiosfetchOp);
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done, asset, '003');
} catch (error) {
console.info('FileAsset checkAttr 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_004
* @tc.name : attrs
* @tc.desc : album attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_promise_004', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done, asset, '004');
} catch (error) {
console.info('FileAsset checkAttr 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility'
import fileio from '@ohos.fileio';
import {
describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it,
expect
} from 'deccjsunit/index';
describe('fileAsset.test.js', async function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
const fileKeyObj = mediaLibrary.FileKey;
//======================== FILE BEGIN ==================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01
* @tc.name : open('rw')
* @tc.desc : open -rw the type of FILE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01', 0, async function (done) {
let asset;
let asset1;
let fd;
let fd1;
try {
let fileType = mediaLibrary.MediaType.FILE;
let fileFetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
let fetchFileResult = await media.getFileAssets(fileFetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('rw');
expect(fd > 0).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead > 0).assertTrue();
asset1 = dataList[1];
fd1 = await asset1.open('r');
let buf2 = new ArrayBuffer(4096);
let res2 = await fileio.read(fd1, buf2);
let write = await fileio.write(fd, buf2);
expect(write > 0).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
if (fd > 0 && res.bytesRead > 0 && write > 0) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 success');
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 failed');
done();
}
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_01 error' + error);
await asset.close(fd);
await asset1.close(fd1);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02
* @tc.name : open('r')
* @tc.desc : open -r the type of FILE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02', 0, async function (done) {
let asset;
let fd;
try {
let type = mediaLibrary.MediaType.FILE;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
expect(fd > 0).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead > 0).assertTrue();
let write = await fileio.write(fd, buf);
await asset.close(fd);
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_02 error:' + error);
if (fd > 0) {
expect(true).assertTrue();
}
await asset.close(fd);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03
* @tc.name : open('w')
* @tc.desc : open -w the type of FILE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03', 0, async function (done) {
let asset;
let asset1;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.FILE;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
asset1 = dataList[1];
fd = await asset.open('w');
expect(fd > 0).assertTrue();
fd1 = await asset1.open('r');
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd1, buf);
let write = await fileio.write(fd, buf);
let buf1 = new ArrayBuffer(4096);
let res1 = await fileio.read(fd, buf1);
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 error:' + error);
expect(true).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
done();
}
});
//======================== FILE END ==================================
//======================== ALBUM BEGIN ==================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_04
* @tc.name : open('rw')
* @tc.desc : open -rw the type of ALBUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_04', 0, async function (done) {
let asset;
let fd;
try {
let type = mediaLibrary.MediaType.ALBUM;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('rw');
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_03 error:' + error);
expect(true).assertTrue();
if (fd > 0) {
asset.close(fd);
}
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05
* @tc.name : open('r')
* @tc.desc : open -r the type of ALBUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05', 0, async function (done) {
let asset;
let fd;
try {
let type = mediaLibrary.MediaType.ALBUM;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05 error:' + error);
expect(true).assertTrue();
if (fd > 0) {
asset.close(fd);
}
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_05
* @tc.name : open('w')
* @tc.desc : open -w the type of ALBUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_06', 0, async function (done) {
let asset;
let fd;
try {
let type = mediaLibrary.MediaType.ALBUM;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_06 error:' + error);
expect(true).assertTrue();
if (fd > 0) {
asset.close(fd);
}
done();
}
});
//======================== ALBUM END ==================================
//======================== IMAGE BEGIN ==================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07
* @tc.name : open('rw')
* @tc.desc : open -rw the type of IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07', 0, async function (done) {
let asset;
let asset1;
let fd;
let fd1;
try {
let fileType = mediaLibrary.MediaType.IMAGE;
let fileFetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
let fetchFileResult = await media.getFileAssets(fileFetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('rw');
expect(fd > 0).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead > 0).assertTrue();
asset1 = dataList[1];
fd1 = await asset1.open('r');
let buf2 = new ArrayBuffer(4096);
let res2 = await fileio.read(fd1, buf2);
let write = await fileio.write(fd, buf2);
expect(write > 0).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
if (fd > 0 && res.bytesRead > 0 && write > 0) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 success');
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 failed');
done();
}
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_07 error' + error);
await asset.close(fd);
await asset1.close(fd1);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08
* @tc.name : open('r')
* @tc.desc : open -r the type of IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08', 0, async function (done) {
let asset;
let fd;
try {
let type = mediaLibrary.MediaType.IMAGE;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
expect(fd > 0).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead > 0).assertTrue();
let write = await fileio.write(fd, buf);
await asset.close(fd);
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_08 error:' + error);
if (fd > 0) {
expect(true).assertTrue();
}
await asset.close(fd);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09
* @tc.name : open('w')
* @tc.desc : open -w the type of IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09', 0, async function (done) {
let asset;
let asset1;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.IMAGE;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
asset1 = dataList[1];
fd = await asset.open('w');
expect(fd > 0).assertTrue();
fd1 = await asset1.open('r');
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd1, buf);
let write = await fileio.write(fd, buf);
let buf1 = new ArrayBuffer(4096);
let res1 = await fileio.read(fd, buf1);
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_09 error:' + error);
expect(true).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
done();
}
});
//======================== IMAGE END ==================================
//======================== AUDIO BEGIN ==================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10
* @tc.name : open('rw')
* @tc.desc : open -rw the type of AUDIO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10', 0, async function (done) {
let asset;
let asset1;
let fd;
let fd1;
try {
let fileType = mediaLibrary.MediaType.AUDIO;
let fileFetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
let fetchFileResult = await media.getFileAssets(fileFetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('rw');
expect(fd > 0).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead > 0).assertTrue();
asset1 = dataList[1];
fd1 = await asset1.open('r');
let buf2 = new ArrayBuffer(4096);
let res2 = await fileio.read(fd1, buf2);
let write = await fileio.write(fd, buf2);
expect(write > 0).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
if (fd > 0 && res.bytesRead > 0 && write > 0) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 success');
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 failed');
done();
}
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_10 error' + error);
await asset.close(fd);
await asset1.close(fd1);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11
* @tc.name : open('r')
* @tc.desc : open -r the type of AUDIO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11', 0, async function (done) {
let asset;
let fd;
try {
let type = mediaLibrary.MediaType.AUDIO;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
expect(fd > 0).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead > 0).assertTrue();
let write = await fileio.write(fd, buf);
await asset.close(fd);
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_11 error:' + error);
if (fd > 0) {
expect(true).assertTrue();
}
await asset.close(fd);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12
* @tc.name : open('w')
* @tc.desc : open -w the type of AUDIO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12', 0, async function (done) {
let asset;
let asset1;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.AUDIO;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
asset1 = dataList[1];
fd = await asset.open('w');
expect(fd > 0).assertTrue();
fd1 = await asset1.open('r');
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd1, buf);
let write = await fileio.write(fd, buf);
let buf1 = new ArrayBuffer(4096);
let res1 = await fileio.read(fd, buf1);
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_12 error:' + error);
expect(true).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
done();
}
});
//======================== AUDIO END ==================================
//======================== VIDEO BEGIN ==================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13
* @tc.name : open('rw')
* @tc.desc : open -rw the type of VIDEO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13', 0, async function (done) {
let asset;
let asset1;
let fd;
let fd1;
try {
let fileType = mediaLibrary.MediaType.VIDEO;
let fileFetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
let fetchFileResult = await media.getFileAssets(fileFetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('rw');
expect(fd > 0).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead > 0).assertTrue();
asset1 = dataList[1];
fd1 = await asset1.open('r');
let buf2 = new ArrayBuffer(4096);
let res2 = await fileio.read(fd1, buf2);
let write = await fileio.write(fd, buf2);
expect(write > 0).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
if (fd > 0 && res.bytesRead > 0 && write > 0) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 success');
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 failed');
done();
}
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_13 error' + error);
await asset.close(fd);
await asset1.close(fd1);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14
* @tc.name : open('r')
* @tc.desc : open -r the type of VIDEO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14', 0, async function (done) {
let asset;
let fd;
try {
let type = mediaLibrary.MediaType.VIDEO;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
expect(fd > 0).assertTrue();
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead > 0).assertTrue();
let write = await fileio.write(fd, buf);
await asset.close(fd);
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_14 error:' + error);
if (fd > 0) {
expect(true).assertTrue();
}
await asset.close(fd);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15
* @tc.name : open('w')
* @tc.desc : open -w the type of VIDEO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15', 0, async function (done) {
let asset;
let asset1;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.VIDEO;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
asset1 = dataList[1];
fd = await asset.open('w');
expect(fd > 0).assertTrue();
fd1 = await asset1.open('r');
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd1, buf);
let write = await fileio.write(fd, buf);
let buf1 = new ArrayBuffer(4096);
let res1 = await fileio.read(fd, buf1);
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_15 error:' + error);
expect(true).assertTrue();
await asset.close(fd);
await asset1.close(fd1);
done();
}
});
//======================== VIDEO END ==================================
//======================== CLOSE BEGIN ================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31
* @tc.name : close
* @tc.desc : asset close the type of file
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31', 0, async function (done) {
let asset;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.FILE;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
console.info('MediaLibraryTest : ==1 fd:' + fd);
await asset.close(fd);
fd1 = await asset.open('r');
console.info('MediaLibraryTest : ==2 fd2:' + fd1);
await asset.close(fd1);
if (fd > 0 && fd1 > 0) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 success');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 false');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_31 error' + error);
await asset.close(fd);
await asset.close(fd1);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33
* @tc.name : close
* @tc.desc : asset close the type of image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33', 0, async function (done) {
let asset;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.IMAGE;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
console.info('MediaLibraryTest : ==1 fd:' + fd);
await asset.close(fd);
fd1 = await asset.open('r');
console.info('MediaLibraryTest : ==2 fd2:' + fd1);
await asset.close(fd1);
if (fd > 0 && fd1 > 0) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 success');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 false');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_33 error' + error);
await asset.close(fd);
await asset.close(fd1);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34
* @tc.name : close
* @tc.desc : asset close the type of audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34', 0, async function (done) {
let asset;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.AUDIO;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
await asset.close(fd);
fd1 = await asset.open('r');
await asset.close(fd1);
if (fd > 0 && fd1 > 0) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 success');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 false');
expect(false).assertTrue();
done();
}
done
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_34 error' + error);
await asset.close(fd);
await asset.close(fd1);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35
* @tc.name : close
* @tc.desc : asset close the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35', 0, async function (done) {
let asset;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.VIDEO;
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
let fetchFileResult = await media.getFileAssets(fetchOp);
const dataList = await fetchFileResult.getAllObject();
asset = dataList[0];
fd = await asset.open('r');
await asset.close(fd);
fd1 = await asset.open('r');
await asset.close(fd1);
if (fd > 0 && fd1 > 0) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 success');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 false');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_PROMISE_005_35 error' + error);
await asset.close(fd);
await asset.close(fd1);
expect(false).assertTrue();
done();
}
});
//======================== CLOSE BEGIN ================================
});
\ No newline at end of file
......@@ -43,20 +43,27 @@ let filesfetchOp = {
function checkAssetAttr(done, attr, testNum, asset, checkType) {
if (checkType && asset[attr] != checkType) {
console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${testNum} failed`);
console.info(`ASSET_PROMISE getFileAssets ${testNum} failed`);
expect(false).assertTrue();
done();
} else if (asset[attr] == undefined) {
console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${testNum} failed`);
console.info(`ASSET_PROMISE getFileAssets ${testNum} failed`);
expect(false).assertTrue();
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();
console.info('MediaLibraryTest : getMediaLibrary IN');
console.info('getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
console.info('getMediaLibrary OUT');
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
......@@ -80,36 +87,35 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_01', 0, async function (done) {
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 dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, 'image01.jpg', path);
presetAsset = asset1;
const creatAsset1 = await media.createAsset(
imageType,
`${new Date().getTime()}.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);
displayName = `${new Date().getTime()}.jpg`;
const asset2 = dataList[1];
const creatAsset2 = await media.createAsset(imageType, 'image02.jpg', path);
const creatAsset2 = await media.createAsset(imageType, 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);
if (creatAsset1.id != creatAsset2.id) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_01 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_01 failed');
expect(false).assertTrue();
done();
}
id = creatAsset2.id;
mediaType = imageType;
expect(creatAsset1.id != creatAsset2.id).assertTrue();
done();
} 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();
done();
}
......@@ -125,23 +131,14 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_02', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
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(true).assertTrue();
expect(asset.displayName == displayName).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_02 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 001_02 failed, message = ' + error);
}
});
......@@ -155,83 +152,13 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_03', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.relativePath == path).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_05 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 001_03 failed, message = ' + error);
}
});
......@@ -248,30 +175,35 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset = dataList[0];
asset.displayName = 'hhhhhh';
asset.commitModify();
asset.title = `title_${new Date().getTime()}`;
await asset.commitModify();
const id = asset.id;
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ["" + id] };
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const newAssets = await media.getFileAssets(idOP);
const newdataList = await newAssets.getAllObject();
const newAsset = newdataList[0];
if(newAsset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified ) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 passed');
if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) {
console.info('ASSET_PROMISE getFileAssets 001_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed');
console.info('ASSET_PROMISE getFileAssets 001_07 failed');
expect(false).assertTrue();
done();
}
} else if (newAsset.dateModified != undefined) {
console.info('ASSET_PROMISE getFileAssets 001_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed');
console.info('ASSET_PROMISE getFileAssets 001_07 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error);
}
});
......@@ -285,83 +217,13 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_08', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.mediaType == mediaType).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 001_10 failed, message = ' + error);
console.info('ASSET_PROMISE createAsset 001_08 failed, message = ' + error);
}
});
......@@ -375,61 +237,16 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_001_11', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.orientation == orientation).assertTrue();
done();
} 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 -----------------------------
// ------------------------------- video type start ----------------------------
......@@ -443,35 +260,35 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_01', 0, async function (done) {
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 dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(videoType, 'video01.mp4', path);
const creatAsset1 = await media.createAsset(
videoType,
`${new Date().getTime()}.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);
displayName = `${new Date().getTime()}.mp4`;
const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(videoType, 'video02.mp4', path);
const creatAsset2 = await media.createAsset(videoType, 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);
if (creatAsset1.id != creatAsset2.id) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 failed');
expect(false).assertTrue();
done();
}
id = creatAsset2.id;
mediaType = videoType;
expect(creatAsset1.id != creatAsset2.id).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_01 failed' + error);
console.info('ASSET_PROMISE createAsset 002_01 failed' + error);
expect(false).assertTrue();
done();
}
......@@ -487,23 +304,14 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_02', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
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);
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_02 passed');
expect(true).assertTrue();
expect(asset.displayName == displayName).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_02 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 002_02 failed, message = ' + error);
}
});
......@@ -517,83 +325,14 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_03', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
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 idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'dateAdded', '002_05', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_05 passed');
expect(true).assertTrue();
expect(asset.relativePath == path).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_05 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 002_03 failed, message = ' + error);
}
});
......@@ -610,30 +349,35 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset = dataList[0];
asset.displayName = 'hhhhhh';
asset.commitModify();
asset.title = `title_${new Date().getTime()}`;
await asset.commitModify();
const id = asset.id;
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ["" + id] };
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const newAssets = await media.getFileAssets(idOP);
const newdataList = await newAssets.getAllObject();
const newAsset = newdataList[0];
if(newAsset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified ) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 passed');
if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) {
console.info('ASSET_PROMISE getFileAssets 002_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed');
console.info('ASSET_PROMISE getFileAssets 002_07 failed');
expect(false).assertTrue();
done();
}
} else if (newAsset.dateModified != undefined) {
console.info('ASSET_PROMISE getFileAssets 002_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed');
console.info('ASSET_PROMISE getFileAssets 002_07 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error);
}
});
......@@ -647,346 +391,119 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_08', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.mediaType == mediaType).assertTrue();
done();
} 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.name : getFileAssets
* @tc.desc : Get the width attribute
* @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_09', 0, async function (done) {
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, '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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.orientation == orientation).assertTrue();
done();
} 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.desc : Get the height attribute
* @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_002_10', 0, async function (done) {
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_01', 0, async function (done) {
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 firstAsset = dataList[0];
checkAssetAttr(done, 'height', '002_10', firstAsset);
const midAsset = dataList[Math.floor(dataList.length / 2)];
checkAssetAttr(done, 'height', '002_10', midAsset);
const lastAsset = dataList[dataList.length - 1];
checkAssetAttr(done, 'height', '002_10', lastAsset);
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 002_10 passed');
expect(true).assertTrue();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(
audioType,
`${new Date().getTime()}.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);
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();
} 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.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02
* @tc.name : getFileAssets
* @tc.desc : Access to the file name and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_11', 0, async function (done) {
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.displayName == displayName).assertTrue();
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);
console.info('ASSET_PROMISE getFileAssets 003_02 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_12
* @tc.name : createAsset
* @tc.desc : Get the duration attribute
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03
* @tc.name : getFileAssets
* @tc.desc : Access to the file relativePath and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_002_12', 0, async function (done) {
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03', 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, 'audio01.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, 'audio02.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();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02
* @tc.name : getFileAssets
* @tc.desc : Access to the file name and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_02', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_02 failed, message = ' + error);
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03
* @tc.name : getFileAssets
* @tc.desc : Access to the file relativePath and validation is not undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_03', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.relativePath == path).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();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_05 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 003_03 failed, message = ' + error);
}
});
......@@ -1003,30 +520,36 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset = dataList[0];
asset.displayName = 'hhhhhh';
asset.commitModify();
asset.title = `title_${new Date().getTime()}`;
await asset.commitModify();
const id = asset.id;
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ["" + id] };
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const newAssets = await media.getFileAssets(idOP);
const newdataList = await newAssets.getAllObject();
const newAsset = newdataList[0];
if(newAsset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified ) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 passed');
if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) {
console.info('ASSET_PROMISE getFileAssets 003_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed');
console.info('ASSET_PROMISE getFileAssets 003_07 failed');
expect(false).assertTrue();
done();
}
} else if (newAsset.dateModified != undefined) {
console.info('ASSET_PROMISE getFileAssets 003_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed');
console.info('ASSET_PROMISE getFileAssets 003_07 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 003_07 failed, message = ' + error);
}
});
......@@ -1040,154 +563,19 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_003_08', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.mediaType == mediaType).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_08 failed, message = ' + error);
console.info('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();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 003_11 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 -----------------------------
// ------------------------------- file type start ----------------------------
// ------------------------------ file type start ----------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01
* @tc.name : createAsset
......@@ -1198,36 +586,34 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_01', 0, async function (done) {
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 dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(fileType, 'file01.txt', path);
const creatAsset1 = await media.createAsset(
fileType,
`${new Date().getTime()}.bat`,
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);
displayName = `${new Date().getTime()}.bat`;
const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(fileType, 'file02.txt', path);
const creatAsset2 = await media.createAsset(fileType, 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);
if (creatAsset1.id != creatAsset2.id) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 failed');
expect(false).assertTrue();
done();
}
id = creatAsset2.id;
mediaType = fileType;
expect(creatAsset1.id != creatAsset2.id).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE createAsset 004_01 failed' + error);
console.info('ASSET_PROMISE createAsset 004_01 failed' + error);
expect(false).assertTrue();
done();
}
......@@ -1243,23 +629,13 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_02', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.displayName == displayName).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_02 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 004_02 failed, message = ' + error);
}
});
......@@ -1273,83 +649,13 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_03', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.relativePath == path).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_05 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 004_03 failed, message = ' + error);
}
});
......@@ -1366,30 +672,35 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset = dataList[0];
asset.displayName = 'hhhhhh';
asset.commitModify();
asset.title = `title_${new Date().getTime()}`;
await asset.commitModify();
const id = asset.id;
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ["" + id] };
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const newAssets = await media.getFileAssets(idOP);
const newdataList = await newAssets.getAllObject();
const newAsset = newdataList[0];
if(newAsset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified ) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 passed');
if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) {
console.info('ASSET_PROMISE getFileAssets 004_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed');
console.info('ASSET_PROMISE getFileAssets 004_07 failed');
expect(false).assertTrue();
done();
}
} else if (newAsset.dateModified != undefined) {
console.info('ASSET_PROMISE getFileAssets 004_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed');
console.info('ASSET_PROMISE getFileAssets 004_07 failed');
expect(false).assertTrue();
done();
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error);
console.info('ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error);
}
});
......@@ -1403,62 +714,16 @@ describe('file.promise.test.js', function () {
*/
it('SUB_MEDIA_MEDIALIBRARY_CREATEASSET_PROMISE_004_08', 0, async function (done) {
try {
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const firstAsset = dataList[0];
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();
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const fileAssets = await media.getFileAssets(idOP);
const asset = await fileAssets.getFirstObject();
expect(asset.mediaType == mediaType).assertTrue();
done();
} 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 -----------------------------
});
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
let fileKeyObj = mediaLibrary.FileKey;
let fetchOp = {
selections: fileKeyObj.PATH + ' LIKE ? ',
selectionArgs: ['/data/media/%'],
order: fileKeyObj.PATH,
};
// let directoryTypeObj = mediaLibrary.DirectoryType;
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO;
let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let fileType = mediaLibrary.MediaType.FILE;
let imagesfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
let videosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
};
let audiosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
};
let filesfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
let imageAndAudiofetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ',
selectionArgs: [imageType.toString(), audioType.toString()],
};
let imageAndVideoAndfilefetchOp = {
selections:
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: [imageType.toString(), videoType.toString(), fileType.toString()],
};
let imageAndVideoAndfileAndAudiofetchOp = {
selections:
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: [
imageType.toString(),
videoType.toString(),
fileType.toString(),
audioType.toString(),
],
};
let allTypefetchOp = {
selections: '',
selectionArgs: [],
};
async function copyFile(fd1, fd2) {
let stat = await fileio.fstat(fd1);
let buf = new ArrayBuffer(stat.size);
await fileio.read(fd1, buf);
await fileio.write(fd2, buf);
}
describe('GET_ALBUM.test.js', function () {
const context = featureAbility.getContext();
const media = mediaLibrary.getMediaLibrary(context);
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
afterAll(function () {});
var timestamp = new Date().getTime();
var jpgName = timestamp + '.jpg';
var videoName = timestamp + '.mp4';
var audioName = timestamp + '.mp3';
var fileName = timestamp + '.mp3';
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001
* @tc.name : getMediaLibrary
* @tc.desc : Obtains a MediaLibrary instance
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001', 0, async function (done) {
try {
expect(media != undefined).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getMediaLibrary 001 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
expect(fetchFileResult != undefined).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 001 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(videosfetchOp);
expect(fetchFileResult != undefined).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 002 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(audiosfetchOp);
expect(fetchFileResult != undefined).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 003 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(filesfetchOp);
expect(fetchFileResult != undefined).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 004 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imageAndAudiofetchOp);
expect(fetchFileResult != undefined).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 005 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imageAndVideoAndfilefetchOp);
expect(fetchFileResult != undefined).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 006 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp);
expect(fetchFileResult != undefined).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 007 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008', 0, async function (done) {
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + 'abc= ?',
selectionArgs: ['abc'],
};
try {
await media.getFileAssets(fetchOp);
console.info('MediaLibraryTest : getFileAssets 008 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 008 passed`);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009', 0, async function (done) {
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['abc', audioType.toString()],
};
try {
await media.getFileAssets(fetchOp);
console.info('MediaLibraryTest : getFileAssets 009 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : getFileAssets 009 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) {
let fetchOp = {
selections:
fileKeyObj.MEDIA_TYPE +
'abc= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: ['abc', videoType.toString(), fileType.toString()],
};
try {
await media.getFileAssets(fetchOp);
console.info('MediaLibraryTest : getFileAssets 010 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : getFileAssets 010 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) {
let fetchOp = {
selections:
fileKeyObj.MEDIA_TYPE +
'abc= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()],
};
try {
await media.getFileAssets(fetchOp);
console.info('MediaLibraryTest : getFileAssets 011 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : getFileAssets 011 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_CAMERA
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) {
try {
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
const dicResult = await media.getPublicDirectory(DIR_CAMERA);
expect(dicResult == 'Camera/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_VIDEO
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002', 0, async function (done) {
try {
let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO;
const dicResult = await media.getPublicDirectory(DIR_VIDEO);
console.log(dicResult);
expect(dicResult == 'Videos/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003', 0, async function (done) {
try {
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const dicResult = await media.getPublicDirectory(DIR_IMAGE);
expect(dicResult == 'Pictures/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004', 0, async function (done) {
try {
let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO;
const dicResult = await media.getPublicDirectory(DIR_AUDIO);
expect(dicResult == 'Music/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory DIR_IMAGE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005', 0, async function (done) {
try {
let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS;
const dicResult = await media.getPublicDirectory(DIR_DOCUMENTS);
expect(dicResult == 'Documents/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006
* @tc.name : getPublicDirectory
* @tc.desc : getPublicDirectory 110
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_006', 0, async function (done) {
try {
await media.getPublicDirectory(110);
console.info('MediaLibraryTest : getPublicDirectory 006 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : getPublicDirectory 006 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_001
* @tc.name : deleteAsset
* @tc.desc : Delete File by Asset uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset1 = dataList[0];
const delUri = asset1.uri;
await media.deleteAsset(asset1.uri);
const fetchFileResult1 = await media.getFileAssets(imagesfetchOp);
const dataList1 = await fetchFileResult1.getAllObject();
let passed = true;
for (let i = 0; i < dataList1.length; i++) {
const asset = dataList1[i];
if (asset.uri == delUri) {
passed = false;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : deleteAsset 001 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_002
* @tc.name : deleteAsset
* @tc.desc : Delete File Asset by aaaa + uri + aaaaa
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_DELETEASSET_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset1 = dataList[0];
await media.deleteAsset('aaaa' + asset1.uri + 'aaaa');
console.info('MediaLibraryTest : deleteAsset 002 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : deleteAsset 002 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001
* @tc.name : createAsset
* @tc.desc : Create File Asset image (does not exist)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, jpgName, 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);
console.info('MediaLibraryTest : createAsset 001 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 001 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002
* @tc.name : createAsset
* @tc.desc : Create File Asset image (existed)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, jpgName, 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);
console.info('MediaLibraryTest : createAsset 002 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 002 passed`);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003
* @tc.name : createAsset
* @tc.desc : Create File Asset video (does not exist)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003', 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, videoName, 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);
console.info('MediaLibraryTest : createAsset 003 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 003 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004
* @tc.name : createAsset
* @tc.desc : Create File Asset video (existed)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004', 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, videoName, 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);
console.info('MediaLibraryTest : createAsset 004 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 004 passed`);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005
* @tc.name : createAsset
* @tc.desc : Create File Asset audio (does not exist)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005', 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, audioName, 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);
console.info('MediaLibraryTest : createAsset 005 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 005 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006
* @tc.name : createAsset
* @tc.desc : Create File Asset audio (existed)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006', 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(videoType, audioName, 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);
console.info('MediaLibraryTest : createAsset 006 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 006 passed`);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007
* @tc.name : createAsset
* @tc.desc : Create File Asset file (does not exist)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007', 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, fileName, 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);
console.info('MediaLibraryTest : createAsset 007 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008
* @tc.name : createAsset
* @tc.desc : Create File Asset file (existed)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008', 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, fileName, 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);
console.info('MediaLibraryTest : createAsset 008 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 008 passed`);
expect(true).assertTrue();
done();
}
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册