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

!2692 sync medialib xts to release

Merge pull request !2692 from 潘强标/3.1
......@@ -12,13 +12,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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('./fileTestPromise.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('./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('./albumGetFileAssetsPromise.test.js')
require('./albumTestCallBack.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
/*
* 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) 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('deleteFileAssetsPerformance.test.js', function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
let fileList_;
let fileKeyObj = mediaLibrary.FileKey
let type = mediaLibrary.MediaType.IMAGE
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + " = ? ",
selectionArgs: [type.toString()],
order: fileKeyObj.DATE_ADDED,
}
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_GET_FILE_ASSETS_FOR_DELETE_01
* @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_GET_FILE_ASSETS_FOR_DELETE_01 begin');
it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01', 0, async function (done) {
media.getFileAssets(fetchOp, (getFileAssetsErr, queryResultSet) => {
if (queryResultSet != undefined) {
console.info('MediaLibraryTest : getAllObject Successfull ' + queryResultSet.getCount());
if (queryResultSet.getCount() > 0) {
queryResultSet.getAllObject((getAllObjectErr, fileList) => {
if (fileList != undefined) {
fileList_ = fileList;
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 :PASS');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 :FAIL'
+ getAllObjectErr.message);
expect(false).assertTrue();
done();
}
});
} else {
console.info('MediaLibraryTest : getFileAssets :No data');
expect(true).assertTrue();
done();
}
} else {
console.info('MediaLibraryTest : getFileAssets Unsuccessfull ' + getFileAssetsErr.message);
console.info('MediaLibraryTest : getFileAssets :FAIL');
expect(false).assertTrue();
done();
}
});
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 end');
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_ASSET_01
* @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_DELETE_FILE_PERFORMANCE_01 begin');
it('SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01', 0, async function (done) {
if (fileList_ != undefined) {
let counteEnd = 0;
for (let i = 0; i < fileList_.length; i++) {
let fileAsset = fileList_[i];
console.info('MediaLibraryTest : uri is ' + fileAsset.uri);
media.deleteAsset(fileAsset.uri, (deleteAssetErr, deleteRows) => {
if (deleteRows >= 0) {
console.info('MediaLibraryTest : Delete Asset Successfull ' + deleteRows);
counteEnd++;
if (counteEnd == fileList_.length) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 : PASS');
expect(true).assertTrue();
done();
} else if (i == fileList_.length - 1) {
console.info('MediaLibraryTest : delete has error');
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :Partial success');
expect(false).assertTrue();
done();
}
} else {
console.info('MediaLibraryTest : delete error ' + deleteAssetErr.message);
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :FAIL');
expect(false).assertTrue();
done();
}
});
}
} else {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :FAIL'
+ getAllObjectErr.message);
expect(false).assertTrue();
done();
}
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 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('getAlbumsPerformance.test.js', function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
let times = 25;
let AlbumNoArgsfetchOp = {
selections: "",
selectionArgs: [""],
}
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_GET_ALBUMS_PERFORMANCE_01
* @tc.name :
* @tc.desc :
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 begin');
it('SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01', 0, async function (done) {
for (let i = 0; i < times; i++) {
const albumArray = await media.getAlbums(AlbumNoArgsfetchOp);
if (albumArray != undefined) {
console.info('MediaLibraryTest : getAlbums : PASS ' + albumArray.length);
expect(true).assertTrue();
} else {
console.info('MediaLibraryTest : getAlbums : FAIL');
expect(false).assertTrue();
}
}
console.info('MediaLibraryTest : for : end');
done();
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_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('distributed.promise.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. Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
})
beforeEach(function () {
console.info('Distributed. Promise MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.');
})
afterEach(function () {
console.info('Distributed. Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
})
afterAll(function () {
console.info('Distributed. Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
})
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_distributed_001_01
* @tc.name : getActivePeers
* @tc.desc : getActivePeers
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01', 0, async function (done) {
try {
done();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 begin');
let peers = await media.getActivePeers();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 done');
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 fail, message = ' + error);
done();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02
* @tc.name : getAllPeers
* @tc.desc : getAllPeers
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02', 0, async function (done) {
try {
done();
let peers = await media.getAllPeers();
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02 fail, message = ' + error);
done();
}
done();
});
})
\ 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
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* 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
......@@ -15,57 +15,71 @@
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('smartAlbumOperatePerformance_object.test.js', async function () {
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('distributedPromise.test.js', function() {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
let times = 50;
beforeAll(function () {
onsole.info('MediaLibraryTest: beforeAll');
beforeAll(function() {
onsole.info(
'Distributed. Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
})
beforeEach(function () {
console.info('MediaLibraryTest: beforeEach');
beforeEach(function() {
console.info(
'Distributed. Promise MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.');
})
afterEach(function () {
console.info('MediaLibraryTest: afterEach');
afterEach(function() {
console.info(
'Distributed. Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
})
afterAll(function () {
console.info('MediaLibraryTest: afterAll');
afterAll(function() {
console.info(
'Distributed. Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
})
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_CREATE_SMARTALBUM_PERFORMANCE_01
* @tc.name :
* @tc.desc :
* @tc.number : SUB_MEDIA_MEDIALIBRARY_distributed_001_01
* @tc.name : getActivePeers
* @tc.desc : getActivePeers
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01', 0, async function(done) {
try {
done();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 begin');
let peers = await media.getActivePeers();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 done');
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 fail, message = ' + error);
done();
}
done();
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_SMARTALBUM_PERFORMANCE_01 begin');
it('SUB_MEDIA_MEDIALIBRARY_CREATE_SMARTALBUM_PERFORMANCE_01', 0, async function (done) {
for (let i = 0; i < times; i++) {
console.info('MediaLibraryTest : createSmartAlbum begin :times: ' + i);
const smartAlbum = await media.createSmartAlbum("laoxu886");
if (smartAlbum != undefined) {
console.info('MediaLibraryTest : createSmartAlbum albumuri ' + smartAlbum.albumUri);
console.info('MediaLibraryTest : createSmartAlbum :PASS times: ' + i);
expect(true).assertTrue();
} else {
console.info('MediaLibraryTest : createSmartAlbum : FAIL');
expect(false).assertTrue();
}
console.info('MediaLibraryTest : createSmartAlbum after :times: ' + i);
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02
* @tc.name : getAllPeers
* @tc.desc : getAllPeers
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02', 0, async function(done) {
try {
done();
let peers = await media.getAllPeers();
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_02 fail, message = ' + error);
done();
}
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_CREATE_SMARTALBUM_PERFORMANCE_01 end');
done();
});
});
\ No newline at end of file
})
\ 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('favSmartAlbum.promise.test.js', function () {
let mediaType = mediaLibrary.MediaType.IMAGE;
let path = "Pictures/"
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
var asset;
var favSmartAlbum;
beforeAll(function () {
console.info('Smart Album Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
})
beforeEach(function () {
console.info('Smart Album Callback MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.');
})
afterEach(function () {
console.info('Smart Album Callback MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
})
afterAll(function () {
console.info('Smart Album Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
})
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_CALLBACK_001
* @tc.name : Get PrivateSmartAlbum by fav
* @tc.desc : Get PrivateSmartAlbum by fav
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_CALLBACK_001', 0, async function (done) {
try {
asset = await media.createAsset(mediaType, "imagefavtest.jpg", path);
media.getPrivateAlbum(mediaLibrary.PrivateAlbumType.TYPE_FAVORITE, getPrivateAlbumCallBack);
done();
} catch (error) {
console.info('MediaLibraryTest : CALLBACK_001 getPrivateAlbum fail, message = ' + error);
done();
}
});
function getPrivateAlbumCallBack(err, favSmartAlbums) {
if (favSmartAlbums != undefined) {
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getPrivateAlbum favSmartAlbums');
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK favSmartAlbums ' + favSmartAlbums[0].albumName);
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK favSmartAlbums ' + favSmartAlbums[0].albumCapacity);
favSmartAlbum = favSmartAlbums[0];
favSmartAlbum.addAsset(asset.uri, addAssetCallBack);
done();
} else {
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getPrivateAlbumCallBack Unsuccessfull ' + err);
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getPrivateAlbumCallBack : FAIL');
done();
}
}
function addAssetCallBack(err, data) {
if (data != undefined) {
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK fav addAsset success');
favSmartAlbum.getFileAssets(getFileAssetsCallBack);
favSmartAlbum.removeAsset(asset.uri, removeAssetCallBack);
done();
} else {
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK addAssetCallBack Unsuccessfull ' + err);
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK addAssetCallBack : FAIL');
done();
}
}
function removeAssetCallBack(err, data) {
if (data != undefined) {
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK fav removeAsset success');
favSmartAlbum.getFileAssets(getFileAssetsCallBack);
done();
} else {
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK removeAssetCallBack Unsuccessfull ' + err);
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getPrivateremoveAssetCallBackAlbumCallBack : FAIL');
done();
}
}
function getFileAssetsCallBack(err, fSmartFetchFileResult) {
if (fSmartFetchFileResult != undefined) {
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getFileAssetsCallBack Successfull fSmartFetchFileResult = ' +
fSmartFetchFileResult.getCount());
done();
} else {
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getFileAssetsCallBack Unsuccessfull ' + err);
console.info('MediaLibraryTest : SMARTALBUM_CALLBACK getFileAssetsCallBack : FAIL');
done();
}
}
})
......@@ -39,7 +39,7 @@ const audioFetchOp = {
selectionArgs: [audioType.toString()],
};
describe('file.promise.test.js', function () {
describe('favoriteTestPromise.test.js', function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
......
/*
* 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, it, expect} from 'deccjsunit/index';
describe('fileAssetUriTestCallback.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_URI_CALLBACK_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_URI_CALLBACK_005_35', 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() ],
};
const fetchFileResult = await media.getFileAssets(fetchOp);
expect(fetchFileResult != undefined).assertTrue();
let firstObject = await fetchFileResult.getFirstObject();
const id = firstObject.id;
const uri = firstObject.uri;
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 uri:'
+ uri);
const serachUri = 'dataability:///media/image/' + id;
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 serachUri:'
+ serachUri);
let serchfetchOp = {
uri:serachUri.toString(),
selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs : [ type.toString()],
};
const result = await media.getFileAssets(serchfetchOp);
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 getFileAssets by uri:'
+ serachUri + ",result.getCount():" + result.getCount());
asset = await result.getFirstObject();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 asset.uri:'
+ asset.uri);
expect(asset.uri == serachUri).assertTrue();
fd = await asset.open('r');
expect(fd > 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 fd:' + fd);
asset.close(fd, async (error) => {
fd1 = await asset.open('r');
expect(fd1 > 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 fd1:'
+ fd1);
await asset.close(fd1);
done();
});
} catch (error) {
console.info(
`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 error:${error}`);
expect(false).assertTrue();
done();
}
});
//======================== CLOSE BEGIN ================================
});
\ No newline at end of file
......@@ -726,4 +726,3 @@ describe('fileTestPromise.test.js', function () {
// ------------------------------- file type end -----------------------------
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册