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

!2272 Add MediaLibrary XTS test cases.

Merge pull request !2272 from 张代曰/master
...@@ -19,7 +19,7 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -19,7 +19,7 @@ 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('GetFileAssets_GetCount_GetAllObjects', function () { describe('fileAssetGetThumbnailCallBack.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);
...@@ -56,13 +56,17 @@ describe('GetFileAssets_GetCount_GetAllObjects', function () { ...@@ -56,13 +56,17 @@ describe('GetFileAssets_GetCount_GetAllObjects', function () {
order: fileKeyObj.dateAdded, order: fileKeyObj.dateAdded,
}; };
beforeAll(function () { beforeAll(function () {
//onsole.info('beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
}); });
beforeEach(function () { beforeEach(function () {
//console.info('MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.');
}); });
afterEach(function () { afterEach(function () {
//console.info('MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
}); });
afterAll(function () { afterAll(function () {
//console.info('MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
}); });
/** /**
......
...@@ -12,12 +12,26 @@ ...@@ -12,12 +12,26 @@
* 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('./FileAssetGetThumbnailCallBack.test.js')
require('./FileAssetGetThumbnailPromise.test.js')
require('./albumGetFileAssetsPromise.test.js')
require('./albumTestCallBack.test.js')
require('./albumTestPromise.test.js')
require('./distributed.test.js')
require('./favoriteTestCallBack.test.js') require('./favoriteTestCallBack.test.js')
require('./fileTestPromise.test.js')
require('./favoriteTestPromise.test.js') require('./favoriteTestPromise.test.js')
require('./fetchFileResultCallBack.test.js')
require('./fetchFileResultPromise.test.js')
require('./fileAsset2.test.js') require('./fileAsset2.test.js')
require('./fileAssetTestPromise.test.js') require('./fileAssetTestPromise.test.js')
require('./fileAssetUriTestCallBack.test.js')
require('./fileTestCallBack.test.js')
require('./fileTestPromise.test.js')
require('./filekeyTestPromise.test.js')
require('./getAllPeersDeviceTestPromise.test.js')
require('./getAllPeersTestPromise.test.js')
require('./mediaLibraryTestPromise.test.js') require('./mediaLibraryTestPromise.test.js')
require('./albumGetFileAssetsPromise.test.js') require('./mediaLibraryTestPromiseOnOff.test.js')
require('./albumTestPromise.test.js') require('./favtrashTestCallBack.test.js')
require('./favtrashTestPromise.test.js')
...@@ -16,7 +16,7 @@ import mediaLibrary from '@ohos.multimedia.medialibrary'; ...@@ -16,7 +16,7 @@ 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);
......
...@@ -37,7 +37,7 @@ let fileNoArgsfetchOp = { ...@@ -37,7 +37,7 @@ let fileNoArgsfetchOp = {
selectionArgs: [], selectionArgs: [],
}; };
describe('album.callback.test.js', function () { describe('album.callback.test.js', async function () {
let path = 'Pictures/'; let path = 'Pictures/';
console.info('MediaLibraryTest : Delete begin'); console.info('MediaLibraryTest : Delete begin');
let fetchFileResult = await media.getFileAssets(fileNoArgsfetchOp); let fetchFileResult = await media.getFileAssets(fileNoArgsfetchOp);
......
...@@ -75,7 +75,7 @@ function checkAlbumAttr(done, album) { ...@@ -75,7 +75,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 +392,7 @@ describe('album.promise.test.js', async function () { ...@@ -392,9 +392,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 +417,7 @@ describe('album.promise.test.js', async function () { ...@@ -419,9 +417,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 +443,7 @@ describe('album.promise.test.js', async function () { ...@@ -447,9 +443,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) {
......
/*
* 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. * Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -15,60 +15,79 @@ ...@@ -15,60 +15,79 @@
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 image from '@ohos.multimedia.image';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' import {
describe,
beforeAll,
describe('getAlbumsPerformance.test.js', function () { beforeEach,
afterEach,
afterAll,
it,
expect
} from 'deccjsunit/index'
describe('distributed.promise.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);
console.info('MediaLibraryTest : getMediaLibrary OUT'); console.info('MediaLibraryTest : getMediaLibrary OUT');
let times = 25;
let AlbumNoArgsfetchOp = {
selections: "",
selectionArgs: [""],
}
beforeAll(function () { beforeAll(function () {
onsole.info('MediaLibraryTest: beforeAll'); onsole.info('Distributed. Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
}) })
beforeEach(function () { beforeEach(function () {
console.info('MediaLibraryTest: beforeEach'); console.info('Distributed. Promise MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.');
}) })
afterEach(function () { afterEach(function () {
console.info('MediaLibraryTest: afterEach'); console.info('Distributed. Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
}) })
afterAll(function () { afterAll(function () {
console.info('MediaLibraryTest: afterAll'); 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_GET_ALBUMS_PERFORMANCE_01 * @tc.number : SUB_MEDIA_MEDIALIBRARY_distributed_001_01
* @tc.name : * @tc.name : getActivePeers
* @tc.desc : * @tc.desc : getActivePeers
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01', 0, async function (done) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 begin'); try {
it('SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01', 0, async function (done) { done();
for (let i = 0; i < times; i++) { console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 begin');
const albumArray = await media.getAlbums(AlbumNoArgsfetchOp); let peers = await media.getActivePeers();
if (albumArray != undefined) { console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 done');
console.info('MediaLibraryTest : getAlbums : PASS ' + albumArray.length); done();
expect(true).assertTrue(); } catch (error) {
} else { console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DISTRIBUTED_001_01 fail, message = ' + error);
console.info('MediaLibraryTest : getAlbums : FAIL'); done();
expect(false).assertTrue();
} }
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();
} }
console.info('MediaLibraryTest : for : end');
done(); done();
}); });
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_ALBUMS_PERFORMANCE_01 end'); })
}); \ 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();
}
}
})
/*
* 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;
var trashSmartAlbum;
beforeAll(function () {
onsole.info('Smart Album Promise MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
})
beforeEach(function () {
console.info('Smart Album Promise MediaLibraryTest: beforeEach:Prerequisites at the test case level, which are executed before each test case is executed.');
})
afterEach(function () {
console.info('Smart Album Promise MediaLibraryTest: afterEach: Test case-level clearance conditions, which are executed after each test case is executed.');
})
afterAll(function () {
console.info('Smart Album Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
})
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_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_PROMISE_001_01', 0, async function (done) {
try {
asset = await media.createAsset(mediaType, "imageGetPrivatealbum002.jpg", path);
const favSmartAlbums = await media.getPrivateAlbum(mediaLibrary.PrivateAlbumType.TYPE_FAVORITE);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum favSmartAlbums 001_01');
console.info('MediaLibraryTest : SMARTALBUM_PROMISE favSmartAlbums 001_01 ' + favSmartAlbums[0].albumName);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE favSmartAlbums 001_01 ' +
favSmartAlbums[0].albumCapacity);
favSmartAlbum = favSmartAlbums[0];
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_01 fail, message = ' + error);
expect(false).assertTrue();
done();
}
done();
});
it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_02', 0, async function (done) {
try {
const trashSmartAlbums = await media.getPrivateAlbum(mediaLibrary.PrivateAlbumType.TYPE_TRASH);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum trashSmartAlbums 001_02');
console.info('MediaLibraryTest : SMARTALBUM_PROMISE trashSmartAlbums 001_02 ' +
trashSmartAlbums[0].albumName);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE trashSmartAlbums 001_02 ' +
trashSmartAlbums[0].albumCapacity);
trashSmartAlbum = trashSmartAlbums[0];
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_02 fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_03', 0, async function (done) {
try {
const favSmartAlbums = await media.getPrivateAlbum(666);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_03 success');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_03 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_04', 0, async function (done) {
try {
const favSmartAlbums = await media.getPrivateAlbum("666");
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum success 001_04');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_04 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_05', 0, async function (done) {
try {
const favSmartAlbums = await media.getPrivateAlbum(6.66666);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum success 001_05');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_05 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_GETPRIVATEALBUM_PROMISE_001_06', 0, async function (done) {
try {
const favSmartAlbums = await media.getPrivateAlbum();
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum success 001_06');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getPrivateAlbum 001_06 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002
* @tc.name : Add asset
* @tc.desc : Add asset
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_01', 0, async function (done) {
try {
await favSmartAlbum.addAsset(asset.uri);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_01 uri = ', asset.uri);
let fSmartFetchFileResult = await favSmartAlbum.getFileAssets();
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getFileAssets 002_01 Successfull fSmartFetchFileResult = '
+ fSmartFetchFileResult.getCount());
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_01 fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_02', 0, async function (done) {
try {
await favSmartAlbum.addAsset(666);
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_02 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_03', 0, async function (done) {
try {
await favSmartAlbum.addAsset("666");
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_03 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_04', 0, async function (done) {
try {
await favSmartAlbum.addAsset(0.666);
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_04 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_ADDASSET_PROMISE_002_05', 0, async function (done) {
try {
await favSmartAlbum.addAsset();
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav addAsset 002_05 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003
* @tc.name : Remove asset
* @tc.desc : Remove asset
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_01', 0, async function (done) {
try {
await favSmartAlbum.removeAsset(asset.uri);
let fSmartFetchFileResultNew = await favSmartAlbum.getFileAssets();
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getFileAssets Successfull removeAsset 003_01 fSmartFetchFileResultNew = ' +
fSmartFetchFileResultNew.getCount());
await media.deleteAsset(asset.uri);
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_01 fail, message = ' + error);
}
});
it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_02', 0, async function (done) {
try {
await favSmartAlbum.removeAsset(666);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_02 success');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_02 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_03', 0, async function (done) {
try {
await favSmartAlbum.removeAsset("666");
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_03 success');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_03 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_04', 0, async function (done) {
try {
await favSmartAlbum.removeAsset(0.666);
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_04 success');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_04 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
it('SUB_MEDIA_MEDIALIBRARY_REMOVEASSET_PROMISE_003_05', 0, async function (done) {
try {
await favSmartAlbum.removeAsset();
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_05 success');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav removeAsset 003_05 fail, message = ' + error);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETASSET_PROMISE_004
* @tc.name : get FileAssets
* @tc.desc : get FileAssets
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETASSET_PROMISE_004_01', 0, async function (done) {
try {
let fSmartFetchFileResultGet = await favSmartAlbum.getFileAssets();
console.info('MediaLibraryTest : SMARTALBUM_PROMISE getFileAssets Successfull 004_01 fSmartFetchFileResultGet = ' +
fSmartFetchFileResultGet.getCount());
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SMARTALBUM_PROMISE fav getFileAssets 004_01 fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
})
...@@ -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);
......
/*
* 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('fileAsset.callback.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;
function executeAtError(testNum, bool, error, done) {
console.info(
`SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK${testNum} failed, error: ${error}`
);
expect(bool).assertTrue();
if (typeof done === "function") {
done();
}
}
//======================== FILE BEGIN ==================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_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_CALLBACK_005_35', 0, async function (done) {
const testNum = "_005_35";
let asset;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.VIDEO;
let fetchOp = {
uri: 'dataability://123456789/media/external/images/media/10',
networkId: '123456789',
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [type.toString()],
};
media.getFileAssets(fetchOp, (error, fetchFileResult) => {
try{
console.info(`MediaLibraryTest : ==1==`);
fetchFileResult.getAllObject((error, dataList) => {
console.info(`MediaLibraryTest : ==2==`);
try{
console.info(`MediaLibraryTest : ==3==`);
asset = dataList[0];
console.info(`MediaLibraryTest : ==4==`);
asset.open('r', (error, innerFd) => {
fd = innerFd;
try{
asset.close(fd, (error) => {
try{
asset.open('r', (error, innerFd1) => {
fd1 = innerFd1;
try{
asset.close(fd1, (error) => {
try{
if (fd > 0 && fd1 > 0) {
console.info(`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK${testNum} success`);
expect(true).assertTrue();
done();
} else {
console.info(`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK${testNum} failed`);
expect(false).assertTrue();
done();
}
}catch(error){
executeAtError(testNum, false, error, done);
}
});
}catch(error){
executeAtError(testNum, false, error, done);
}
});
}catch(error){
executeAtError(testNum, false, error, done);
}
});
}catch(error){
executeAtError(testNum, false, error, done);
}
});
}catch(error){
executeAtError(testNum, true, error, done);
}
});
}catch(error){
executeAtError(testNum, true, error, done);
}
});
} catch (error) {
console.info(`MediaLibraryTest : ==5==`);
console.info(`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_CALLBACK${testNum} error:${error}`);
asset.close(fd, () =>{
try{
console.info(`MediaLibraryTest : ==6==`);
asset1.close(fd1, () => {
console.info(`MediaLibraryTest : ==7==`);
expect(false).assertTrue();
done();
});
}catch(error){
console.info(`MediaLibraryTest : ==8==`);
expect(false).assertTrue();
done();
}
});
}
});
//======================== CLOSE BEGIN ================================
});
\ No newline at end of file
...@@ -726,4 +726,3 @@ describe('fileTestPromise.test.js', function () { ...@@ -726,4 +726,3 @@ describe('fileTestPromise.test.js', function () {
// ------------------------------- file type end ----------------------------- // ------------------------------- file type end -----------------------------
}); });
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe('getFileAssetsPerformance.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 queryResultSet_;
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_PERFORMANCE_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_PERFORMANCE_01 begin');
it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_PERFORMANCE_01', 0, async function (done) {
for (let i = 0; i < times; i++) {
const queryResultSet = await media.getFileAssets(fetchOp);
if (queryResultSet != undefined) {
console.info('MediaLibraryTest : getFileAssets : PASS ' + queryResultSet.getCount());
expect(true).assertTrue();
} else {
console.info('MediaLibraryTest : getFileAssets : FAIL');
expect(false).assertTrue();
}
}
console.info('MediaLibraryTest : for : end');
done();
});
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_PERFORMANCE_01 end');
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册