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

!2692 sync medialib xts to release

Merge pull request !2692 from 潘强标/3.1
...@@ -12,13 +12,40 @@ ...@@ -12,13 +12,40 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
require('./getPermission.test.js') require('./getPermission.test.js')
require('./albumGetFileAssetsCallback.test.js')
require('./albumGetFileAssetsPromise.test.js')
require('./distributedCallback.test.js')
require('./distributedPromise.test.js')
require('./favoriteTestCallBack.test.js') require('./favoriteTestCallBack.test.js')
require('./fileTestPromise.test.js')
require('./favoriteTestPromise.test.js') require('./favoriteTestPromise.test.js')
require('./fileAsset2.test.js') require('./fetchFileResultCallBack.test.js')
require('./fetchFileResultPromise.test.js')
require('./fileAssetCallBack2.test.js')
require('./FileAssetGetThumbnailCallBack.test.js')
require('./FileAssetGetThumbnailPromise.test.js')
require('./fileAssetPromise2.test.js')
require('./fileAssetTestCallback.test.js')
require('./fileAssetTestPromise.test.js') require('./fileAssetTestPromise.test.js')
require('./fileAssetUriTestCallBack.test.js')
require('./fileAssetUriTestPromiese.test.js')
require('./filekeyTestCallBack.test.js')
require('./filekeyTestPromise.test.js')
require('./fileTestCallBack.test.js')
require('./fileTestPromise.test.js')
require('./getAllPeersDeviceTestCallback.test.js')
require('./getAllPeersDeviceTestPromise.test.js')
require('./getAllPeersTestCallback.test.js')
require('./getAllPeersTestPromise.test.js')
require('./mediaLibraryTestCallBack.test.js')
require('./mediaLibraryTestPromise.test.js') require('./mediaLibraryTestPromise.test.js')
require('./albumGetFileAssetsPromise.test.js') require('./albumTestCallBack.test.js')
require('./albumTestPromise.test.js') require('./albumTestPromise.test.js')
require('./mediaLibraryTestPromiseOnOff.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('albumGetFileAssetsCallback.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_CALLBACK_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_CALLBACK_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];
album.getFileAssets(allTypefetchOp, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(imageAlbumfetchOp, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(audioAlbumfetchOp, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(videoAlbumfetchOp, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(imageAndVideoAlbumfetchOp, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(imageAndAudioAlbumfetchOp, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
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_CALLBACK_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_CALLBACK_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];
album.getFileAssets(videoAndAudioAlbumfetchOp, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(imgAndVideoAndAudioAlbumfetchOp, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(albumfetchOpOne, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(albumfetchOpOne, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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];
album.getFileAssets(albumfetchOpOne, (error, fetchFileResult) => {
if (fetchFileResult == undefined) {
expect(false).assertTrue();
done();
} else {
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
}
});
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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',
};
media.getAlbums(albumfetchOpNone, (error, albumList) => {
if (albumList == undefined) {
expect(false).assertTrue();
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 albumList == undefined');
done();
} else {
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 albumList.length:'
+ albumList.length);
expect(albumList.length == 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 done');
done();
}
});
} catch (error) {
expect(false).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_12 error:' + error);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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',
};
media.getAlbums(albumfetchOpNone, (error, albumList) => {
if (albumList == undefined) {
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_13 albumList == undefined');
expect(false).assertTrue();
done();
} else {
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_13 albumList.length:'
+ albumList.length);
expect(albumList.length == 0).assertTrue();
done();
}
});
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_13 error:' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_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_CALLBACK_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',
};
media.getAlbums(albumfetchOpNone, (error, albumList) => {
if (albumList == undefined) {
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_14 albumList == undefined');
expect(false).assertTrue();
done();
} else {
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_14 albumList.length:'
+ albumList.length);
expect(albumList.length == 0).assertTrue();
done();
}
});
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_CALLBACK_001_14 error:' + error);
expect(false).assertTrue();
done();
}
});
});
\ No newline at end of file
...@@ -14,17 +14,17 @@ ...@@ -14,17 +14,17 @@
*/ */
import mediaLibrary from '@ohos.multimedia.medialibrary'; import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index';
describe('fileAssetTestPromise.test.js', async function () { describe('albumGetFileAssetsPromise.test.js', async function() {
var context = featureAbility.getContext(); var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN'); console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context); var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT'); console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function () {}); beforeAll(function() {});
beforeEach(function () {}); beforeEach(function() {});
afterEach(function () {}); afterEach(function() {});
afterAll(function () {}); afterAll(function() {});
const fileKeyObj = mediaLibrary.FileKey; const fileKeyObj = mediaLibrary.FileKey;
...@@ -41,12 +41,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -41,12 +41,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function(done) {
try { try {
let allTypefetchOp = { let allTypefetchOp = {
selections: '', selections : '',
selectionArgs: [], selectionArgs : [],
order: 'date_added DESC LIMIT 0,3', order : 'date_added DESC LIMIT 0,3',
}; };
const albumList = await media.getAlbums(allTypefetchOp); const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0]; const album = albumList[0];
...@@ -67,12 +67,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -67,12 +67,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function(done) {
try { try {
let imageAlbumfetchOp = { let imageAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs : [ imageType.toString() ],
order: 'date_added DESC LIMIT 0,3', order : 'date_added DESC LIMIT 0,3',
}; };
const albumList = await media.getAlbums(imageAlbumfetchOp); const albumList = await media.getAlbums(imageAlbumfetchOp);
const album = albumList[0]; const album = albumList[0];
...@@ -93,12 +93,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -93,12 +93,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function(done) {
try { try {
let audioAlbumfetchOp = { let audioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()], selectionArgs : [ audioType.toString() ],
order: 'date_added DESC LIMIT 0,3', order : 'date_added DESC LIMIT 0,3',
}; };
const albumList = await media.getAlbums(audioAlbumfetchOp); const albumList = await media.getAlbums(audioAlbumfetchOp);
const album = albumList[0]; const album = albumList[0];
...@@ -119,12 +119,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -119,12 +119,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function(done) {
try { try {
let videoAlbumfetchOp = { let videoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()], selectionArgs : [ videoType.toString() ],
order: 'date_added DESC LIMIT 0,3', order : 'date_added DESC LIMIT 0,3',
}; };
const albumList = await media.getAlbums(videoAlbumfetchOp); const albumList = await media.getAlbums(videoAlbumfetchOp);
const album = albumList[0]; const album = albumList[0];
...@@ -145,12 +145,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -145,12 +145,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function(done) {
try { try {
let imageAndVideoAlbumfetchOp = { let imageAndVideoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString()], selectionArgs : [ imageType.toString(), videoType.toString() ],
order: 'date_added DESC LIMIT 0,3', order : 'date_added DESC LIMIT 0,3',
}; };
const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp); const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp);
const album = albumList[0]; const album = albumList[0];
...@@ -171,12 +171,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -171,12 +171,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function(done) {
try { try {
let imageAndAudioAlbumfetchOp = { let imageAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), audioType.toString()], selectionArgs : [ imageType.toString(), audioType.toString() ],
order: 'date_added DESC LIMIT 0,3', order : 'date_added DESC LIMIT 0,3',
}; };
const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp); const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp);
const album = albumList[0]; const album = albumList[0];
...@@ -197,12 +197,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -197,12 +197,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function(done) {
try { try {
let videoAndAudioAlbumfetchOp = { let videoAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString(), audioType.toString()], selectionArgs : [ videoType.toString(), audioType.toString() ],
order: 'date_added DESC LIMIT 0,3', order : 'date_added DESC LIMIT 0,3',
}; };
const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp); const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp);
const album = albumList[0]; const album = albumList[0];
...@@ -223,18 +223,13 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -223,18 +223,13 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08', 0, async function(done) {
try { try {
let imgAndVideoAndAudioAlbumfetchOp = { let imgAndVideoAndAudioAlbumfetchOp = {
selections: selections : fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or '
fileKeyObj.MEDIA_TYPE + + fileKeyObj.MEDIA_TYPE + '= ?',
'= ? or ' + selectionArgs : [ imageType.toString(), videoType.toString(), audioType.toString() ],
fileKeyObj.MEDIA_TYPE + order : 'date_added DESC LIMIT 0,3',
'= ? 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 albumList = await media.getAlbums(imgAndVideoAndAudioAlbumfetchOp);
const album = albumList[0]; const album = albumList[0];
...@@ -255,12 +250,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -255,12 +250,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09', 0, async function(done) {
try { try {
let albumfetchOpOne = { let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs : [ imageType.toString() ],
order: 'date_added DESC LIMIT 0,1', order : 'date_added DESC LIMIT 0,1',
}; };
const albumList = await media.getAlbums(albumfetchOpOne); const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0]; const album = albumList[0];
...@@ -281,12 +276,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -281,12 +276,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10', 0, async function(done) {
try { try {
let albumfetchOpOne = { let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()], selectionArgs : [ audioType.toString() ],
order: 'date_added DESC LIMIT 0,1', order : 'date_added DESC LIMIT 0,1',
}; };
const albumList = await media.getAlbums(albumfetchOpOne); const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0]; const album = albumList[0];
...@@ -307,12 +302,12 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -307,12 +302,12 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11', 0, async function(done) {
try { try {
let albumfetchOpOne = { let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()], selectionArgs : [ videoType.toString() ],
order: 'date_added DESC LIMIT 0,1', order : 'date_added DESC LIMIT 0,1',
}; };
const albumList = await media.getAlbums(albumfetchOpOne); const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0]; const album = albumList[0];
...@@ -333,18 +328,22 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -333,18 +328,22 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12', 0, async function(done) {
try { try {
let albumfetchOpNone = { let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [imageType.toString()], selectionArgs : [ imageType.toString() ],
order: 'date_added DESC LIMIT 0,1', order : 'date_added DESC LIMIT 0,1',
}; };
const albumList = await media.getAlbums(albumfetchOpNone); const albumList = await media.getAlbums(albumfetchOpNone);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 albumList.length:'
+ albumList.length);
expect(albumList.length == 0).assertTrue(); expect(albumList.length == 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 done');
done(); done();
} catch (error) { } catch (error) {
expect(false).assertTrue(); expect(false).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 error:' + error);
done(); done();
} }
}); });
...@@ -357,18 +356,22 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -357,18 +356,22 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13', 0, async function(done) {
try { try {
let albumfetchOpNone = { let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [audioType.toString()], selectionArgs : [ audioType.toString() ],
order: 'date_added DESC LIMIT 0,1', order : 'date_added DESC LIMIT 0,1',
}; };
const albumList = await media.getAlbums(albumfetchOpNone); const albumList = await media.getAlbums(albumfetchOpNone);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 albumList.length:'
+ albumList.length);
expect(albumList.length == 0).assertTrue(); expect(albumList.length == 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 done');
done(); done();
} catch (error) { } catch (error) {
expect(false).assertTrue(); expect(false).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 error:' + error);
done(); done();
} }
}); });
...@@ -381,18 +384,22 @@ describe('fileAssetTestPromise.test.js', async function () { ...@@ -381,18 +384,22 @@ describe('fileAssetTestPromise.test.js', async function () {
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14', 0, async function(done) {
try { try {
let albumfetchOpNone = { let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0', selections : fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [videoType.toString()], selectionArgs : [ videoType.toString() ],
order: 'date_added DESC LIMIT 0,1', order : 'date_added DESC LIMIT 0,1',
}; };
const albumList = await media.getAlbums(albumfetchOpNone); const albumList = await media.getAlbums(albumfetchOpNone);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14 albumList.length:'
+ albumList.length);
expect(albumList.length == 0).assertTrue(); expect(albumList.length == 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14 done');
done(); done();
} catch (error) { } catch (error) {
expect(false).assertTrue(); expect(false).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 error:' + error);
done(); done();
} }
}); });
......
...@@ -26,7 +26,10 @@ let allTypefetchOp = { ...@@ -26,7 +26,10 @@ let allTypefetchOp = {
selections: '', selections: '',
selectionArgs: [], selectionArgs: [],
}; };
let albumCoverUrifetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.ALBUM_NAME + '= ?',
selectionArgs: ['pictures/','weixin'],
};
let imageAlbumfetchOp = { let imageAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
...@@ -75,7 +78,7 @@ function checkAlbumAttr(done, album) { ...@@ -75,7 +78,7 @@ function checkAlbumAttr(done, album) {
} }
} }
describe('album.promise.test.js', async function () { describe('albumTestPromise.test.js', async function () {
var context = featureAbility.getContext(); var context = featureAbility.getContext();
var media = mediaLibrary.getMediaLibrary(context); var media = mediaLibrary.getMediaLibrary(context);
beforeAll(function () {}); beforeAll(function () {});
...@@ -392,9 +395,7 @@ describe('album.promise.test.js', async function () { ...@@ -392,9 +395,7 @@ describe('album.promise.test.js', async function () {
}; };
try { try {
const albumList = await media.getAlbums(fileHasArgsfetchOp3); const albumList = await media.getAlbums(fileHasArgsfetchOp3);
console.info( console.info('GETALBUMASSETS_PROMISE_002_06 length:' + albumList.length);
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue(); expect(albumList.length == 0).assertTrue();
done(); done();
} catch (error) { } catch (error) {
...@@ -419,9 +420,7 @@ describe('album.promise.test.js', async function () { ...@@ -419,9 +420,7 @@ describe('album.promise.test.js', async function () {
}; };
try { try {
const albumList = await media.getAlbums(fileHasArgsfetchOp4); const albumList = await media.getAlbums(fileHasArgsfetchOp4);
console.info( console.info('GETALBUMASSETS_PROMISE_002_07 length:' + albumList.length);
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue(); expect(albumList.length == 0).assertTrue();
done(); done();
} catch (error) { } catch (error) {
...@@ -447,9 +446,7 @@ describe('album.promise.test.js', async function () { ...@@ -447,9 +446,7 @@ describe('album.promise.test.js', async function () {
try { try {
const albumList = await media.getAlbums(fileHasArgsfetchOp5); const albumList = await media.getAlbums(fileHasArgsfetchOp5);
console.info( console.info('GETALBUMASSETS_PROMISE_002_08 length:' + albumList.length);
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue(); expect(albumList.length == 0).assertTrue();
done(); done();
} catch (error) { } catch (error) {
...@@ -671,14 +668,28 @@ describe('album.promise.test.js', async function () { ...@@ -671,14 +668,28 @@ describe('album.promise.test.js', async function () {
*/ */
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) {
try { try {
const albumList = await media.getAlbums(allTypefetchOp); let coverUrifetchOp = {
selections: '',
selectionArgs: [],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumCoverUrifetchOp);
const album = albumList[0]; const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp); console.info('PROMISE getAlbum 004_01 album name = ' + album.albumName);
console.info('PROMISE getAlbum 004_01 album id = ' + album.albumId);
const fetchFileResult = await album.getFileAssets(coverUrifetchOp);
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
if (asset == undefined) {
expect(false).assertTrue();
done();
} else {
console.info('PROMISE getAlbum 004_01 coveruri = ' + album.coverUri);
console.info('PROMISE getAlbum 004_01 asset.uri = ' + asset.uri);
expect(asset.uri == album.coverUri).assertTrue(); expect(asset.uri == album.coverUri).assertTrue();
done(); done();
}
} catch (error) { } catch (error) {
console.info('ALBUM_PROMISE getAlbum 004_01 failed, message = ' + error); console.info('PROMISE getAlbum 004_01 failed, message = ' + error);
expect(false).assertTrue(); expect(false).assertTrue();
done(); 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'
describe('Create_File_Assets.test.js', function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function () {
onsole.info('MediaLibraryTest: beforeAll');
})
beforeEach(function () {
console.info('MediaLibraryTest: beforeEach');
})
afterEach(function () {
console.info('MediaLibraryTest: afterEach');
})
afterAll(function () {
console.info('MediaLibraryTest: afterAll');
console.info('MediaLibraryTest : createAsset : release begin');
if (media != undefined) {
media.release();
}
console.info('MediaLibraryTest : createAsset : release end');
})
/**
* @tc.number : 01
* @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01
* @tc.desc : Create an image file asset in predefined relative path
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 begin');
it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01', 0, async function (done) {
if (media == null || media == undefined) {
console.info('MediaLibraryTest : media == null');
} else {
let mediaType = mediaLibrary.MediaType.IMAGE;
let displayName = "02image.jpg";
let rp = "Pictures/";
console.info('MediaLibraryTest : createAsset begin');
media.createAsset(mediaType, displayName, rp, (createAssetErr, fileObj) => {
if (fileObj != undefined) {
console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileObj.uri);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : PASS');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 : FAIL');
expect(false).assertTrue();
done();
}
});
console.info('MediaLibraryTest : createAsset end');
}
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_01 end');
/**
* @tc.number : 02
* @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02
* @tc.desc : Create an image file asset in not predefined relative path
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 begin');
it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02', 0, async function (done) {
if (media == null || media == undefined) {
console.info('MediaLibraryTest : media == null');
} else {
let mediaType = mediaLibrary.MediaType.IMAGE;
let displayName = "02image.jpg";
let rp = "Pictures/test/001/";
console.info('MediaLibraryTest : createAsset begin');
media.createAsset(mediaType, displayName, rp, (createAssetErr, fileObj) => {
if (fileObj != undefined) {
console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileObj.uri);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 : PASS');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 : FAIL');
expect(false).assertTrue();
done();
}
});
console.info('MediaLibraryTest : createAsset end');
}
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_02 end');
/**
* @tc.number : 03
* @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03
* @tc.desc : Repeat to create same image file asset expect return error
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 begin');
it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03', 0, async function (done) {
if (media == null || media == undefined) {
console.info('MediaLibraryTest : media == null');
} else {
let mediaType = mediaLibrary.MediaType.IMAGE;
let displayName = "02image.jpg";
let rp = "Pictures/test/001/";
console.info('MediaLibraryTest : createAsset begin');
media.createAsset(mediaType, displayName, rp, (createAssetErr, fileObj) => {
if (fileObj == undefined) {
console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 : PASS');
expect(true).assertTrue();
done();
}
console.info('MediaLibraryTest : createAsset : FAIL');
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 : FAIL');
expect(false).assertTrue();
done();
});
console.info('MediaLibraryTest : createAsset end');
}
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03 end');
/**
* @tc.number : 04
* @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04
* @tc.desc : Create image file asset in invalid relative path expect return error
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 begin');
it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04', 0, async function (done) {
if (media == null || media == undefined) {
console.info('MediaLibraryTest : media == null');
} else {
let mediaType = mediaLibrary.MediaType.IMAGE;
let displayName = "04image.jpg";
let rp = "test/";
console.info('MediaLibraryTest : createAsset begin');
media.createAsset(mediaType, displayName, rp, (createAssetErr, fileObj) => {
if (createAssetErr != undefined) {
console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 : PASS');
expect(true).assertTrue();
done();
}
console.info('MediaLibraryTest : createAsset : FAIL');
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 : FAIL');
expect(false).assertTrue();
done();
});
console.info('MediaLibraryTest : createAsset end');
}
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_04 end');
/**
* @tc.number : 07
* @tc.name : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07
* @tc.desc : After create an image file asset, open and close it
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 begin');
it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07', 0, async function (done) {
if (media == null || media == undefined) {
console.info('MediaLibraryTest : media == null');
} else {
let mediaType = mediaLibrary.MediaType.IMAGE;
let displayName = "03image.jpg";
media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE, (err, rp) => {
if (rp != undefined) {
console.info('MediaLibraryTest : getPublicDirectory Successfull ' + rp);
console.info('MediaLibraryTest : createAsset begin');
media.createAsset(mediaType, displayName, rp, (createAssetErr, data) => {
if (data != undefined) {
console.info('MediaLibraryTest : createAsset Successfull ');
getObjectInfo(data);
} else {
console.info('MediaLibraryTest : createAsset Unsuccessfull ' + createAssetErr.message);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : FAIL');
expect(false).assertTrue();
done();
}
});
console.info('MediaLibraryTest : createAsset end');
} else {
console.info('MediaLibraryTest : getPublicDirectory : FAIL');
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : FAIL');
expect(false).assertTrue();
done();
}
});
}
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 end');
});
function getObjectInfo(fileAsset) {
console.info('MediaLibraryTest : getObjectInfo uri is ' + fileAsset.uri);
console.info("==========================fileAsset.open begin=======================>");
fileAsset.open('Rw').then((openError, fd) => {
if (openError == undefined) {
console.info('MediaLibraryTest : open : FAIL ' + openError.message);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : FAIL');
expect(false).assertTrue();
done();
}
console.info("==========================fileAsset.open success=======================>");
console.debug("open success fd = " + JSON.stringify(fd));
console.info("==========================fileAsset.close begin=======================>");
fileAsset.close(fd).then((closeErr) => {
if (closeErr == undefined) {
console.info('MediaLibraryTest : close : FAIL ' + closeErr.message);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : FAIL');
expect(false).assertTrue();
done();
}
console.info("==========================fileAsset.close success=======================>");
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_07 : PASS');
expect(true).assertTrue();
done();
});
console.info("==========================fileAsset.close end=======================>");
});
console.info("==========================fileAsset.open end=======================>");
}
});
\ No newline at end of file
/*
* 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'
describe('createFileAssetsPerformance.test.js', function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
let times = 100;
beforeAll(function () {
onsole.info('MediaLibraryTest: beforeAll');
})
beforeEach(function () {
console.info('MediaLibraryTest: beforeEach');
})
afterEach(function () {
console.info('MediaLibraryTest: afterEach');
})
afterAll(function () {
console.info('MediaLibraryTest: afterAll');
})
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_03
* @tc.name : Create an image file asset in predefined path
* @tc.desc : Create an image file asset in predefined path
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 begin');
it('SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01', 0, async function (done) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 begin1');
if (media == null || media == undefined) {
console.info('MediaLibraryTest : media == null');
} else {
let mediaType = mediaLibrary.MediaType.IMAGE;
let displayNamePrefix = "image";
let extendStr = ".jpg"
let rp = "Pictures/";
let displayName;
let conteEnd = 0;
for (let i = 0; i < times; i++) {
displayName = displayNamePrefix + i + extendStr;
console.info('MediaLibraryTest : createAsset begin');
media.createAsset(mediaType, displayName, rp).then((fileObj) => {
if (fileObj != undefined) {
console.info('MediaLibraryTest : createAsset Successfull file uri = ' + fileObj.uri);
conteEnd++;
if (conteEnd == times) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 : PASS');
expect(true).assertTrue();
done();
} else if (i == times) {
console.info('MediaLibraryTest : createAsset has error');
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 :Partial success');
expect(false).assertTrue();
done();
}
} else {
console.info('MediaLibraryTest : createAsset Unsuccessfull ');
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 : FAIL');
expect(false).assertTrue();
done();
}
});
console.info('MediaLibraryTest : createAsset end');
}
}
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_FILE_PERFORMANCE_01 end');
});
\ No newline at end of file
/*
* 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 image from '@ohos.multimedia.image';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('distributedCallback.test.js', function() {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function() {
onsole.info(
'Distributed. Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
})
beforeEach(function() {
console.info(
'Distributed. Callback MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.');
})
afterEach(function() {
console.info(
'Distributed. Callback MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
})
afterAll(function() {
console.info(
'Distributed. Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
})
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01
* @tc.name : getActivePeers
* @tc.desc : getActivePeers
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01', 0, async function(done) {
try {
done();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01 begin');
media.getActivePeers((error, peers) => {
expect(error == undefined).assertTrue();
});
done();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01 done');
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_01 fail, message = '
+ error);
done();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_02
* @tc.name : getAllPeers
* @tc.desc : getAllPeers
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_02', 0, async function(done) {
try {
done();
media.getAllPeers((error, peers) => {
expect(error == undefined).assertTrue();
});
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_CALLBACK_001_02 fail, message = '
+ error);
done();
}
done();
});
})
\ No newline at end of file
...@@ -39,7 +39,7 @@ const audioFetchOp = { ...@@ -39,7 +39,7 @@ const audioFetchOp = {
selectionArgs: [audioType.toString()], selectionArgs: [audioType.toString()],
}; };
describe('file.promise.test.js', function () { describe('favoriteTestPromise.test.js', function () {
var context = featureAbility.getContext(); var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN'); console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context); var media = mediaLibrary.getMediaLibrary(context);
......
...@@ -726,4 +726,3 @@ describe('fileTestPromise.test.js', function () { ...@@ -726,4 +726,3 @@ describe('fileTestPromise.test.js', function () {
// ------------------------------- file type end ----------------------------- // ------------------------------- file type end -----------------------------
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册