提交 7465ed7f 编写于 作者: Y yangbo

photoAccessHelper xts update

Signed-off-by: Nyangbo <yangbo258@huawei.com>
上级 eb5bed67
......@@ -238,28 +238,36 @@ const getPermission = async function (name, context) {
name = "ohos.acts.multimedia.mediaLibrary";
}
console.info('getPermission start: ' + name);
let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA", "ohos.permission.WRITE_MEDIA"];
let atManager = abilityAccessCtrl.createAtManager();
atManager.requestPermissionsFromUser(context, permissions, (err, result) => {
if (err) {
console.info('getPermission failed: ' + JSON.stringify(err));
} else {
console.info('getPermission suc: ' + JSON.stringify(result));
}
});
let driver = uitest.Driver.create();
await sleep(500);
try {
console.info('getPermission start: ' + name);
let isGetPermission = false;
let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA", "ohos.permission.WRITE_MEDIA"];
let atManager = abilityAccessCtrl.createAtManager();
atManager.requestPermissionsFromUser(context, permissions, (err, result) => {
if (err) {
console.info('getPermission failed: ' + JSON.stringify(err));
} else {
console.info('getPermission suc: ' + JSON.stringify(result));
isGetPermission = true;
}
});
for (let i = 0; i < 10; i++) {
let driver = uitest.Driver.create();
await sleep(500);
let button = await driver.findComponent(uitest.ON.text('允许'));
if (button != undefined) {
await button.click();
for (let i = 0; i < 10; i++) {
if (isGetPermission) {
break;
}
await sleep(500);
let button = await driver.findComponent(uitest.ON.text('允许'));
if (button != undefined) {
await button.click();
}
}
console.info("getPermission end");
} catch (error) {
console.info('getPermission error: ' + error);
}
console.info("getPermission end");
};
const MODIFY_ERROR_CODE_01 = "-1000";
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -6,7 +6,7 @@
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import bundleManager from '@ohos.bundle.bundleManager';
......@@ -159,32 +158,6 @@ export async function createUserAlbum(testNum, albumName) : Promise<photoAccessH
});
}
//systemApi
export async function deleteAllUserAlbum(testNum) : Promise<void> {
try {
const helper = photoAccessHelper.getPhotoAccessHelper(globalThis.abilityContext);
let fetchResult = await helper.getAlbums(albumType.USER, albumSubtype.USER_GENERIC);
let count = fetchResult.getCount();
console.info(`${testNum} deleteAllUserAlbum count: ${count}`);
if (count <= 0) {
return;
}
const albumList = await fetchResult.getAllObjects();
console.info(`${testNum} deleteAllUserAlbum getAllObjects: ${albumList.length}`);
await helper.deleteAlbums(albumList);
fetchResult = await helper.getAlbums(albumType.USER, albumSubtype.USER_GENERIC);
if (fetchResult.getCount() === 0) {
console.info(`${testNum} deleteAllUserAlbum suc`);
} else {
console.info(`${testNum} deleteAllUserAlbum failed! fetchResult.getCount(): ${fetchResult.getCount()}`);
}
fetchResult.close();
} catch (error) {
console.info(`${testNum} deleteAllUserAlbum failed! error: ${error}`);
throw error;
}
};
export async function getFileAsset(testNum, fetchOps) : Promise<photoAccessHelper.PhotoAsset> {
let asset: photoAccessHelper.PhotoAsset;
try {
......
......@@ -6,14 +6,26 @@
"bundle-name": "ohos.acts.multimedia.photoaccess",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
"type": "ShellKit",
"pre-push": [],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /storage/media/100/local/files/Audios/*",
"rm -rf /storage/media/100/local/files/Audios/.*",
"rm -rf /storage/media/100/local/files/Camera/*",
"rm -rf /storage/media/100/local/files/Camera/.*",
"rm -rf /storage/media/100/local/files/Documents/*",
"rm -rf /storage/media/100/local/files/Documents/.*",
"rm -rf /storage/media/100/local/files/Download/*",
"rm -rf /storage/media/100/local/files/Download/.*",
"rm -rf /storage/media/100/local/files/Pictures/*",
"rm -rf /storage/media/100/local/files/Pictures/.*",
"rm -rf /storage/media/100/local/files/Videos/*",
"rm -rf /storage/media/100/local/files/Videos/.*",
"sleep 5",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"kill -9 `pidof com.ohos.medialibrary.medialibrarydata`",
"scanner",
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......@@ -21,7 +20,6 @@ import {
albumSubtype,
photoKeys,
fetchOption,
getFileAsset,
} from '../../../../../../../common'
export default function albumGetAssetsTest () {
......
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
// @ts-nocheck
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......@@ -78,14 +78,16 @@ export default function addAssetsTest () {
const testNum = 'addAssets_callback_003';
try {
const album = await helper.createAlbum(testNum);
const fetchOps1 = fetchOption(testNum, photoKeys.DISPLAY_NAME, 'addCb03.jpg');
const fetchOps2 = fetchOption(testNum, photoKeys.DISPLAY_NAME, 'addCb01.mp4');
const assetList: Array<photoAccessHelper.PhotoAsset> = new Array();
const asset1 = await getFileAsset(testNum, fetchOps1);
assetList.push(asset1);
const asset2 = await getFileAsset(testNum, fetchOps2);
assetList.push(asset2);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.in(photoKeys.DISPLAY_NAME, ['addCb03.jpg', 'addCb01.mp4']);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
const fetchResult = await helper.getAssets(fetchOps);
console.info(`${testNum} fetchResult: ${fetchResult.getCount()}`);
const assetList = await fetchResult.getAllObjects();
fetchResult.close();
album.addAssets(assetList, async (err) => {
try {
if (err) {
......@@ -109,6 +111,37 @@ export default function addAssetsTest () {
}
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_ADD_ASSETS_0400
* @tc.name : addAssets_callback_004
* @tc.desc : add empty array to user album
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('addAssets_callback_004', 2, async function (done) {
const testNum = 'addAssets_callback_004';
try {
const album = await helper.createAlbum(testNum);
album.addAssets([], async (err) => {
try {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
}
} catch (error) {
console.info(`${testNum} error: ${error}`);
}
done();
})
} catch (error) {
console.info(`${testNum} failed; error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_ADD_ASSETS_0500
* @tc.name : addAssets_callback_005
......@@ -176,18 +209,20 @@ export default function addAssetsTest () {
const testNum = 'addAssets_promise_003';
try {
const album = await helper.createAlbum(testNum);
const fetchOps1 = fetchOption(testNum, photoKeys.DISPLAY_NAME, 'addPro03.jpg');
const fetchOps2 = fetchOption(testNum, photoKeys.DISPLAY_NAME, 'addPro01.mp4');
const assetList: Array<photoAccessHelper.PhotoAsset> = new Array();
const asset1 = await getFileAsset(testNum, fetchOps1);
assetList.push(asset1);
const asset2 = await getFileAsset(testNum, fetchOps2);
assetList.push(asset2);
await album.addAssets(assetList);
const fetchResult = await album.getAssets(fetchAllOption());
expect(fetchResult.getCount()).assertEqual(2);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.in(photoKeys.DISPLAY_NAME, ['addCb03.jpg', 'addCb01.mp4']);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
const fetchResult = await helper.getAssets(fetchOps);
console.info(`${testNum} fetchResult: ${fetchResult.getCount()}`);
const assetList = await fetchResult.getAllObjects();
fetchResult.close();
await album.addAssets(assetList);
const albumFetchResult = await album.getAssets(fetchAllOption());
expect(albumFetchResult.getCount()).assertEqual(2);
albumFetchResult.close();
done();
} catch (error) {
console.info(`${testNum} failed; error: ${error}`);
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......@@ -115,6 +114,36 @@ export default function removeAssetsTest () {
}
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_REMOVE_ASSETS_0300
* @tc.name : removeAssets_callback_003
* @tc.desc : user album remove empty array
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('removeAssets_callback_003', 2, async function (done) {
const testNum = 'removeAssets_callback_003';
try {
const album = await helper.createAlbum(testNum);
album.removeAssets([], async (err) => {
try {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
}
} catch (error) {
console.info(`${testNum} error: ${error}`);
}
done();
})
} catch (error) {
console.info(`${testNum} failed; error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_REMOVE_ASSETS_0400
* @tc.name : removeAssets_callback_004
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......@@ -38,7 +37,7 @@ export default function albumGetCountTest () {
* @tc.level : Level 0
*/
it('album_getCount_callback_000', 0, async function (done) {
const testNum = 'album_getCount_callback_000';
const testNum = 'album_getCount_callback_000';
try {
const subTypes : Array<photoAccessHelper.AlbumSubtype> = [
albumSubtype.VIDEO,
......@@ -61,8 +60,8 @@ export default function albumGetCountTest () {
}
}
} catch (error) {
console.info(`${testNum} failed; error: ${error}`);
expect(false).assertTrue();
console.info(`${testNum} failed; error: ${error}`);
expect(false).assertTrue();
done();
}
});
......@@ -76,7 +75,7 @@ export default function albumGetCountTest () {
* @tc.level : Level 0
*/
it('album_getCount_callback_001', 0, async function (done) {
const testNum = 'album_getCount_callback_001';
const testNum = 'album_getCount_callback_001';
try {
const albumName = genRadomStr(10);
await createUserAlbum(testNum, albumName);
......@@ -92,7 +91,7 @@ export default function albumGetCountTest () {
done();
} catch (error) {
console.info(`${testNum} failed; error: ${error}`);
expect(false).assertTrue();
expect(false).assertTrue();
done();
}
});
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -36,6 +36,7 @@ import assetGetNextObjectTest from './PhotoAssetFetchResult/getNextObject'
import assetGetPositionObjectTest from './PhotoAssetFetchResult/getObjectByPosition'
import assetIsAfterLastTest from './PhotoAssetFetchResult/isAfterLast'
import createAssetTest from './PhotoAccessHelper/createAsset'
import createDeleteRequestTest from './PhotoAccessHelper/createDeleteRequest'
import getAlbumsTest from './PhotoAccessHelper/getAlbums'
import getAssetsTest from './PhotoAccessHelper/getAssets'
import unRegisterChangeTest from './PhotoAccessHelper/unRegisterChange'
......@@ -72,6 +73,7 @@ export default function testsuite () {
assetGetPositionObjectTest()
assetIsAfterLastTest()
createAssetTest()
createDeleteRequestTest()
getAlbumsTest()
getAssetsTest()
unRegisterChangeTest()
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import { photoType } from '../../../../../../../common'
......@@ -242,7 +241,7 @@ export default function createAssetTest () {
const options: photoAccessHelper.CreateOptions = undefined;
await createAssetAbnormalCallback1(done, testNum, type, extension, options);
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_CREATE_IMAGE_0000
* @tc.name : createImage_promise_000
......
/*
* Copyright (C) 2023 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 photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import { genRadomStr, photoType } from '../../../../../../../common';
export default function createDeleteRequestTest() {
describe('createDeleteRequestTest', function () {
const helper = photoAccessHelper.getPhotoAccessHelper(globalThis.abilityContext)
const ERR_CODE_PARAMERTER_INVALID = 13900020;
const createFiles = async (count) => {
try {
const uriList: Array<string> = new Array();
for (let i = 0; i < count; i++) {
let title = genRadomStr(10);
let asset = await helper.createAsset(title + '.jpg');
let fd = await asset.open('rw');
await asset.close(fd);
uriList.push(asset.uri);
}
return uriList;
} catch (error) {
console.info(`delete_popup createFiles error ${error}`);
}
};
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_CREATE_DELETE_REQUEST_0000
* @tc.name : createDeleteRequest_callback_000
* @tc.desc : delete 1 file
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('createDeleteRequest_callback_000', 0, async function (done) {
const testNum = 'createDeleteRequest_callback_000';
try {
let uriList = await createFiles(1);
console.info(`${testNum} uriList: ${JSON.stringify(uriList)}`)
helper.createDeleteRequest(uriList, (err) => {
try {
if (err) {
console.info(`${testNum} error ${JSON.stringify(err)}`);
} else {
console.log(`${testNum} delete suc`);
}
} catch (error) {
console.info(`${testNum} error ${JSON.stringify(error)}`);
}
done();
})
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_CREATE_DELETE_REQUEST_0000
* @tc.name : createDeleteRequest_promise_000
* @tc.desc : delete 1 file
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('createDeleteRequest_promise_000', 0, async function (done) {
const testNum = 'createDeleteRequest_promise_000';
try {
let uriList = await createFiles(1);
helper.createDeleteRequest(uriList)
.then(() => {
console.log(`${testNum} delete suc`);
})
.catch((error) => {
console.info(`${testNum} error ${JSON.stringify(error)}`);
expect(true).assertTrue();
});
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
});
}
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
// @ts-nocheck
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......@@ -94,7 +94,7 @@ export default function getAlbumsTest () {
* @tc.type : Function
* @tc.level : Level 2
*/
it('getAlbums_callback_001', 0, async function (done) {
it('getAlbums_callback_001', 2, async function (done) {
const testNum = 'getAlbums_callback_001';
try {
// Firstly, create an album
......@@ -134,7 +134,7 @@ export default function getAlbumsTest () {
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_PHOTOACCESS_HELPER_CALLBACK_GET_ALBUM_003', 0, async function (done) {
it('getAlbums_callback_002', 0, async function (done) {
const testNum = 'getAlbums_callback_002';
try {
let subTypes : Array<photoAccessHelper.AlbumSubtype> = [
......@@ -225,7 +225,7 @@ export default function getAlbumsTest () {
* @tc.type : Function
* @tc.level : Level 2
*/
it('getAlbums_promise_001', 0, async function (done) {
it('getAlbums_promise_001', 2, async function (done) {
const testNum = 'getAlbums_promise_001';
try {
// Firstly, create an album
......@@ -254,7 +254,7 @@ export default function getAlbumsTest () {
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_PHOTOACCESS_HELPER_PROMISE_GET_ALBUM_003', 0, async function (done) {
it('getAlbums_promise_002', 0, async function (done) {
const testNum = 'getAlbums_promise_002';
try {
let subTypes : Array<photoAccessHelper.AlbumSubtype> = [
......@@ -278,5 +278,81 @@ export default function getAlbumsTest () {
done();
}
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_ALBUMS_0300
* @tc.name : getAlbums_promise_003
* @tc.desc : get user albums by orderByAsc
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('getAlbums_promise_003', 2, async function (done) {
const testNum = 'getAlbums_promise_003';
try {
const albumNames = ['b', 'a', 'c'];
for (let i = 0; i < albumNames.length; i++) {
await helper.createAlbum(albumNames[i]);
}
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.in(albumKeys.ALBUM_NAME, albumNames).orderByAsc(albumKeys.ALBUM_NAME);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
const fetchResult = await helper.getAlbums(albumType.USER, albumSubtype.USER_GENERIC, fetchOps);
expect(fetchResult.getCount()).assertEqual(3);
const resultList = await fetchResult.getAllObjects();
const expectNames = ['a', 'b', 'c'];
for (let i = 0; i < albumNames.length; i++) {
console.info(`${testNum} albumName: ${resultList[i].albumName}`);
expect(resultList[i].albumName).assertEqual(expectNames[i]);
}
done();
} catch (error) {
console.info(`${testNum} failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_ALBUMS_0400
* @tc.name : getAlbums_promise_004
* @tc.desc : get user albums by orderByDesc
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('getAlbums_promise_004', 2, async function (done) {
const testNum = 'getAlbums_promise_004';
try {
const albumNames = ['x', 'y', 'z'];
for (let i = 0; i < albumNames.length; i++) {
await helper.createAlbum(albumNames[i]);
}
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.in(albumKeys.ALBUM_NAME, albumNames).orderByDesc(albumKeys.ALBUM_NAME);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
const fetchResult = await helper.getAlbums(albumType.USER, albumSubtype.USER_GENERIC, fetchOps);
expect(fetchResult.getCount()).assertEqual(3);
const resultList = await fetchResult.getAllObjects();
const expectNames = ['z', 'y', 'x'];
for (let i = 0; i < albumNames.length; i++) {
console.info(`${testNum} albumName: ${resultList[i].albumName}`);
expect(resultList[i].albumName).assertEqual(expectNames[i]);
}
done();
} catch (error) {
console.info(`${testNum} failed, error: ${error}`);
expect(false).assertTrue();
done();
}
});
})
}
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......@@ -22,7 +21,6 @@ import {
photoKeys,
getFileAsset,
photoFetchOption,
photoType,
} from '../../../../../../../common'
export default function registerChangeTest () {
......@@ -34,15 +32,15 @@ export default function registerChangeTest () {
const DEFAULT_ALBUM_URI = photoAccessHelper.DefaultChangeUri.DEFAULT_ALBUM_URI;
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_ON_CALLBACK_0100
* @tc.name : on_callback_001
* @tc.number : SUB_PHOTOACCESS_HELPER_REGISTERCHANGE_CALLBACK_0100
* @tc.name : registerChange_callback_001
* @tc.desc : listening motify file displayName, type NOTIFY_UPDATE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('on_callback_001', 0, async function (done) {
const testNum = 'on_callback_001';
it('registerChange_callback_001', 0, async function (done) {
const testNum = 'registerChange_callback_001';
try {
let fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'on01.jpg');
const asset = await getFileAsset(testNum, fetchOps);
......@@ -69,15 +67,15 @@ export default function registerChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_ON_CALLBACK_0700
* @tc.name : on_callback_007
* @tc.number : SUB_PHOTOACCESS_HELPER_REGISTERCHANGE_CALLBACK_0700
* @tc.name : registerChange_callback_007
* @tc.desc : listening create album, type NOTIFY_ADD
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('on_callback_007', 0, async function (done) {
const testNum = 'on_callback_007';
it('registerChange_callback_007', 0, async function (done) {
const testNum = 'registerChange_callback_007';
try {
let changeDataUri = '';
let listenCount = 0;
......@@ -104,15 +102,15 @@ export default function registerChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_ON_CALLBACK_0800
* @tc.name : on_callback_008
* @tc.number : SUB_PHOTOACCESS_HELPER_REGISTERCHANGE_CALLBACK_0800
* @tc.name : registerChange_callback_008
* @tc.desc : listening change albumName, type NOTIFY_UPDATE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('on_callback_008', 0, async function (done) {
const testNum = 'on_callback_008';
it('registerChange_callback_008', 0, async function (done) {
const testNum = 'registerChange_callback_008';
try {
let albumUri = '';
let count = 0;
......@@ -140,15 +138,15 @@ export default function registerChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_ON_CALLBACK_1100
* @tc.name : on_callback_011
* @tc.number : SUB_PHOTOACCESS_HELPER_REGISTERCHANGE_CALLBACK_1100
* @tc.name : registerChange_callback_011
* @tc.desc : listening album removeAssets, type NOTIFY_ALBUM_ADD_ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('on_callback_011', 0, async function (done) {
const testNum = 'on_callback_011';
it('registerChange_callback_011', 0, async function (done) {
const testNum = 'registerChange_callback_011';
try {
let albumName = 'testAlbum' + Date.now();
let album = await helper.createAlbum(albumName);
......@@ -176,15 +174,15 @@ export default function registerChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_ON_CALLBACK_1200
* @tc.name : on_callback_012
* @tc.number : SUB_PHOTOACCESS_HELPER_REGISTERCHANGE_CALLBACK_1200
* @tc.name : registerChange_callback_012
* @tc.desc : listening album removeAssets, type NOTIFY_ALBUM_REMOVE_ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('on_callback_012', 0, async function (done) {
const testNum = 'on_callback_012';
it('registerChange_callback_012', 0, async function (done) {
const testNum = 'registerChange_callback_012';
try {
let albumName = 'testAlbum' + Date.now();
let album = await helper.createAlbum(albumName);
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......@@ -22,9 +21,6 @@ import {
photoKeys,
getFileAsset,
photoFetchOption,
photoType,
albumType,
albumSubtype
} from '../../../../../../../common'
export default function unRegisterChangeTest () {
......@@ -34,15 +30,15 @@ export default function unRegisterChangeTest () {
const DEFAULT_ALBUM_URI = photoAccessHelper.DefaultChangeUri.DEFAULT_ALBUM_URI;
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_OFF_0100
* @tc.name : off_001
* @tc.number : SUB_PHOTOACCESS_UNREGISTERCHANGE_0100
* @tc.name : unRegisterChange_001
* @tc.desc : off listening motify file displayName, type NOTIFY_UPDATE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('off_001', 0, async function (done) {
const testNum = 'off_001';
it('unRegisterChange_001', 0, async function (done) {
const testNum = 'unRegisterChange_001';
try {
const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'off01.jpg');
const asset = await getFileAsset(testNum, fetchOps);
......@@ -69,15 +65,15 @@ export default function unRegisterChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_OFF_0700
* @tc.name : off_007
* @tc.number : SUB_PHOTOACCESS_UNREGISTERCHANGE_0700
* @tc.name : unRegisterChange_007
* @tc.desc : off listening create album, type NOTIFY_ADD
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('off_007', 0, async function (done) {
const testNum = 'off_007';
it('unRegisterChange_007', 0, async function (done) {
const testNum = 'unRegisterChange_007';
try {
let count = 0;
helper.registerChange(DEFAULT_ALBUM_URI, true, async (changeData) => {
......@@ -100,15 +96,15 @@ export default function unRegisterChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_OFF_0800
* @tc.name : off_008
* @tc.number : SUB_PHOTOACCESS_UNREGISTERCHANGE_0800
* @tc.name : unRegisterChange_008
* @tc.desc : off listening create album, type NOTIFY_UPDATE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('off_008', 0, async function (done) {
const testNum = 'off_008';
it('unRegisterChange_008', 0, async function (done) {
const testNum = 'unRegisterChange_008';
try {
let albumUri = '';
let count = 0;
......@@ -136,15 +132,15 @@ export default function unRegisterChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_OFF_1000
* @tc.name : off_010
* @tc.number : SUB_PHOTOACCESS_UNREGISTERCHANGE_1000
* @tc.name : unRegisterChange_010
* @tc.desc : off listening change album overUri, type NOTIFY_UPDATE
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('off_010', 0, async function example(done) {
const testNum = 'off_010';
it('unRegisterChange_010', 0, async function example(done) {
const testNum = 'unRegisterChange_010';
try {
let albumUri = '';
let count = 0;
......@@ -175,15 +171,15 @@ export default function unRegisterChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_OFF_1100
* @tc.name : off_011
* @tc.number : SUB_PHOTOACCESS_UNREGISTERCHANGE_1100
* @tc.name : unRegisterChange_011
* @tc.desc : off listening album removeAssets, type NOTIFY_ALBUM_ADD_ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('off_011', 0, async function (done) {
const testNum = 'off_011';
it('unRegisterChange_011', 0, async function (done) {
const testNum = 'unRegisterChange_011';
try {
let albumName = 'testAlbum' + Date.now();
let album = await helper.createAlbum(albumName);
......@@ -210,15 +206,15 @@ export default function unRegisterChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_OFF_1200
* @tc.name : off_012
* @tc.number : SUB_PHOTOACCESS_UNREGISTERCHANGE_1200
* @tc.name : unRegisterChange_012
* @tc.desc : off listening album removeAssets, type NOTIFY_ALBUM_REMOVE_ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('off_012', 0, async function (done) {
const testNum = 'off_012';
it('unRegisterChange_012', 0, async function (done) {
const testNum = 'unRegisterChange_012';
try {
let albumName = 'testAlbum' + Date.now();
let album = await helper.createAlbum(albumName);
......@@ -246,15 +242,15 @@ export default function unRegisterChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_OFF_1500
* @tc.name : off_015
* @tc.number : SUB_PHOTOACCESS_UNREGISTERCHANGE_1500
* @tc.name : unRegisterChange_015
* @tc.desc : off remove all listening
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it('off_015', 0, async function (done) {
const testNum = 'off_015';
it('unRegisterChange_015', 0, async function (done) {
const testNum = 'unRegisterChange_015';
try {
let fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'off15.jpg');
const asset = await getFileAsset(testNum, fetchOps);
......@@ -285,15 +281,15 @@ export default function unRegisterChangeTest () {
});
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_OFF_CALLBACK_0000
* @tc.name : off_callback_000
* @tc.number : SUB_PHOTOACCESS_UNREGISTERCHANGE_CALLBACK_0000
* @tc.name : unRegisterChange_callback_000
* @tc.desc : off remove specified callback
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it('off_callback_000', 0, async function (done) {
const testNum = 'off_callback_000';
it('unRegisterChange_callback_000', 0, async function (done) {
const testNum = 'unRegisterChange_callback_000';
try {
let fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'offCb01.jpg');
const asset = await getFileAsset(testNum, fetchOps);
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import { describe, it, expect } from 'deccjsunit/index'
import {
photoKeys,
......@@ -28,12 +27,13 @@ export default function checkAttrTest () {
async function checkAssetAttr (done, testNum, displayName, mediaType) {
try {
let key = photoKeys.DISPLAY_NAME;
let uri = 'file://media/Photo/';
const fetchOps = fetchOption(testNum, key, displayName);
const asset = await getFileAsset(testNum, fetchOps);
console.info(`${testNum} uri: ${asset.uri} filetype: ${asset.photoType} displayName: ${asset.displayName}`)
const id = getId(asset.uri);
expect(asset.uri).assertEqual(uri + id);
const expectUri = 'file://media/Photo/' + id;
const isIncludes = asset.uri.includes(expectUri);
expect(isIncludes).assertTrue();
expect(asset.photoType).assertEqual(mediaType);
expect(asset.displayName).assertEqual(displayName);
done();
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import fileio from "@ohos.fileio";
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......@@ -30,8 +29,9 @@ export default function commitModifyTest () {
try {
const asset = await getFileAsset(testNum, fetchOps);
const oldTitle: photoAccessHelper.MemberType = asset.get(photoKeys.TITLE).toString();
console.info(`${testNum} oldTitle: ${typeof oldTitle}`);
console.info(`${testNum} oldTitle: ${oldTitle}`);
asset.set(photoKeys.TITLE, newTitle);
console.info(`${testNum} newTitle: ${newTitle}`);
asset.commitModify(async (err) => {
try {
if (err) {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import { describe, it, expect } from 'deccjsunit/index'
import {
photoKeys,
......@@ -32,7 +31,10 @@ export default function getTest () {
console.info(`${testNum} key: ${key}, value: ${value}, asset.key: ${asset.get(key)}`);
if (key === 'uri') {
const id = getId(asset.get(key));
expect(asset.get(key)).assertEqual(value + id);
const expectUri = value + id;
const uri = asset.get(key).toString();
const isIncludes = uri.includes(expectUri);
expect(isIncludes).assertTrue();
} else if (key === 'date_added' || key === 'date_modified' || key === 'date_taken') {
expect(isNum(asset.get(key))).assertTrue();
} else {
......
......@@ -13,14 +13,12 @@
* limitations under the License.
*/
// @ts-nocheck
import fileio from "@ohos.fileio";
import { describe, it, expect } from 'deccjsunit/index'
import {
photoKeys,
fetchOption,
getFileAsset,
isNum,
} from '../../../../../../../common'
export default function getReadOnlyFdTest () {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import image from '@ohos.multimedia.image';
import { describe, it, expect } from 'deccjsunit/index'
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,11 +13,10 @@
* limitations under the License.
*/
// @ts-nocheck
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
fetchOption,
photoType,
photoKeys
} from '../../../../../../../common'
......@@ -30,17 +29,18 @@ export default function assetGetFirstObjectTest () {
try {
let fetchResult = await helper.getAssets(fetchOps);
console.info(`${testNum} fetchResult: ${fetchResult.getCount()}`);
expect(fetchResult.getCount() > 0).assertTrue();
expect(fetchResult.getCount()).assertEqual(1);
fetchResult.getFirstObject((err, asset) => {
try {
if (err !== undefined) {
console.info(`${testNum} getFirstObject failed; err: ${err}`);
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
} else {
console.info(`${testNum} asset: ${asset.displayName}`);
expect(asset !== undefined).assertTrue();
}
} catch (error) {
console.info(`${testNum} getFirstObject failed; error: ${error}`);
console.info(`${testNum} error: ${error}`);
}
fetchResult.close();
done();
......@@ -55,9 +55,10 @@ export default function assetGetFirstObjectTest () {
async function getFirstObjectPromiseTest (done, testNum, fetchOps) {
try {
let fetchResult = await helper.getAssets(fetchOps);
expect(fetchResult.getCount() > 0).assertTrue();
expect(fetchResult.getCount()).assertEqual(1);
const asset = await fetchResult.getFirstObject();
fetchResult.close();
console.info(`${testNum} asset: ${asset.displayName}`);
expect(asset !== undefined).assertTrue();
done();
} catch (error) {
......@@ -79,7 +80,12 @@ export default function assetGetFirstObjectTest () {
*/
it('getFirstObject_callback_000', 0, async function (done) {
const testNum = 'getFirstObject_callback_000';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.IMAGE);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.IMAGE).and().equalTo(photoKeys.DISPLAY_NAME, '01.jpg');
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await getFirstObjectCallbackTest(done, testNum, fetchOps);
});
......@@ -94,7 +100,12 @@ export default function assetGetFirstObjectTest () {
*/
it('getFirstObject_promise_000', 0, async function (done) {
const testNum = 'getFirstObject_promise_000';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.IMAGE);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.IMAGE).and().equalTo(photoKeys.DISPLAY_NAME, '01.jpg');
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await getFirstObjectPromiseTest(done, testNum, fetchOps);
});
......@@ -110,7 +121,12 @@ export default function assetGetFirstObjectTest () {
*/
it('getFirstObject_callback_001', 0, async function (done) {
const testNum = 'getFirstObject_callback_001';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.VIDEO);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.VIDEO).and().equalTo(photoKeys.DISPLAY_NAME, '01.mp4');
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await getFirstObjectCallbackTest(done, testNum, fetchOps);
});
......@@ -125,7 +141,12 @@ export default function assetGetFirstObjectTest () {
*/
it('getFirstObject_promise_001', 0, async function (done) {
const testNum = 'getFirstObject_promise_001';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.VIDEO);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.VIDEO).and().equalTo(photoKeys.DISPLAY_NAME, '01.mp4');
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await getFirstObjectPromiseTest(done, testNum, fetchOps);
});
})
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,11 +13,10 @@
* limitations under the License.
*/
// @ts-nocheck
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
fetchOption,
photoType,
photoKeys
} from '../../../../../../../common'
......@@ -29,7 +28,7 @@ export default function assetGetNextObjectTest () {
async function getNextObjectCallbackTest (done, testNum, fetchOps) {
try {
let fetchResult = await helper.getAssets(fetchOps);
expect(fetchResult.getCount() > 1).assertTrue();
expect(fetchResult.getCount()).assertEqual(2);
await fetchResult.getFirstObject();
fetchResult.getNextObject((err, asset) => {
try {
......@@ -55,7 +54,7 @@ export default function assetGetNextObjectTest () {
async function getNextObjectPromiseTest (done, testNum, fetchOps) {
try {
let fetchResult = await helper.getAssets(fetchOps);
expect(fetchResult.getCount() > 1).assertTrue();
expect(fetchResult.getCount()).assertEqual(2);
let asset = await fetchResult.getFirstObject();
asset = await fetchResult.getNextObject();
fetchResult.close();
......@@ -80,7 +79,12 @@ export default function assetGetNextObjectTest () {
*/
it('getNextObject_callback_000', 0, async function (done) {
const testNum = 'getNextObject_callback_000';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.IMAGE);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.IMAGE).limit(2, 0);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await getNextObjectCallbackTest(done, testNum, fetchOps);
});
......@@ -95,7 +99,12 @@ export default function assetGetNextObjectTest () {
*/
it('getNextObject_promise_000', 0, async function (done) {
const testNum = 'getNextObject_promise_000';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.IMAGE);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.IMAGE).limit(2, 0);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await getNextObjectPromiseTest(done, testNum, fetchOps);
});
......@@ -111,7 +120,12 @@ export default function assetGetNextObjectTest () {
*/
it('getNextObject_callback_001', 0, async function (done) {
const testNum = 'getNextObject_callback_001';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.VIDEO);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.VIDEO).limit(2, 0);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await getNextObjectCallbackTest(done, testNum, fetchOps);
});
......@@ -126,7 +140,12 @@ export default function assetGetNextObjectTest () {
*/
it('getNextObject_promise_001', 0, async function (done) {
const testNum = 'getNextObject_promise_001';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.VIDEO);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.VIDEO).limit(2, 0);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await getNextObjectPromiseTest(done, testNum, fetchOps);
});
})
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,11 +13,10 @@
* limitations under the License.
*/
// @ts-nocheck
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
fetchOption,
photoType,
photoKeys
} from '../../../../../../../common'
......@@ -30,17 +29,12 @@ export default function assetIsAfterLastTest () {
try {
let fetchResult = await helper.getAssets(fetchOps);
let count = fetchResult.getCount();
expect(count > 1).assertTrue();
expect(count).assertEqual(2);
let asset = await fetchResult.getFirstObject();
for (let i = 1; i < count; i++) {
asset = await fetchResult.getNextObject();
if (i + 1 === count) {
const result = fetchResult.isAfterLast();
expect(result).assertTrue();
fetchResult.close();
done();
}
}
asset = await fetchResult.getNextObject();
const result = fetchResult.isAfterLast();
expect(result).assertTrue();
done();
} catch (error) {
console.info(`${testNum} failed; error: ${error}`);
expect(false).assertTrue();
......@@ -59,7 +53,12 @@ export default function assetIsAfterLastTest () {
*/
it('isAfterLast_callback_000', 0, async function (done) {
const testNum = 'isAfterLast_callback_000';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.IMAGE);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.IMAGE).limit(2, 0);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await isAfterLastCallbackTest(done, testNum, fetchOps);
});
......@@ -74,7 +73,12 @@ export default function assetIsAfterLastTest () {
*/
it('isAfterLast_callback_001', 0, async function (done) {
const testNum = 'isAfterLast_callback_001';
const fetchOps = fetchOption(testNum, photoKeys.PHOTO_TYPE, photoType.VIDEO);
const predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo(photoKeys.PHOTO_TYPE, photoType.IMAGE).limit(2, 0);
const fetchOps : photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
await isAfterLastCallbackTest(done, testNum, fetchOps);
});
})
......
......@@ -13,16 +13,15 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, beforeAll, it, expect } from 'deccjsunit/index'
import { getPermission } from '../../../../../../common'
export default function getUserFileMgrTest () {
describe('getUserFileMgrTest', function () {
export default function getPhotoAccessHelper () {
describe('getPhotoAccessHelper', function () {
beforeAll(async function () {
console.info('beforeAll case')
await getPermission('ohos.acts.multimedia.photoaccess');
await getPermission();
})
/**
......
......@@ -8,8 +8,7 @@
"deviceTypes": [
"tablet",
"default",
"phone",
"2in1"
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
......
......@@ -6,14 +6,26 @@
"bundle-name": "ohos.acts.multimedia.photoaccess",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
"testcase-timeout": 10000
},
"kits": [
{
"type": "ShellKit",
"pre-push": [],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /storage/media/100/local/files/Audios/*",
"rm -rf /storage/media/100/local/files/Audios/.*",
"rm -rf /storage/media/100/local/files/Camera/*",
"rm -rf /storage/media/100/local/files/Camera/.*",
"rm -rf /storage/media/100/local/files/Documents/*",
"rm -rf /storage/media/100/local/files/Documents/.*",
"rm -rf /storage/media/100/local/files/Download/*",
"rm -rf /storage/media/100/local/files/Download/.*",
"rm -rf /storage/media/100/local/files/Pictures/*",
"rm -rf /storage/media/100/local/files/Pictures/.*",
"rm -rf /storage/media/100/local/files/Videos/*",
"rm -rf /storage/media/100/local/files/Videos/.*",
"sleep 5",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"kill -9 `pidof com.ohos.medialibrary.medialibrarydata`",
"scanner",
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, beforeAll, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, beforeAll, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, beforeAll, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, beforeAll, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, beforeAll, it, expect } from 'deccjsunit/index'
import {
......@@ -36,7 +35,7 @@ export default function deleteAlbumsTest () {
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_DELETE_ALBUMS_0000
* @tc.name : deleteAlbums_callback_000
* @tc.desc : delete user test
* @tc.desc : delete user albums
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
......@@ -120,7 +119,7 @@ export default function deleteAlbumsTest () {
/**
* @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_DELETE_ALBUMS_0000
* @tc.name : deleteAlbums_promise_000
* @tc.desc : delete albums test
* @tc.desc : delete user albums
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import fileio from "@ohos.fileio";
import { describe, beforeAll, it, expect } from 'deccjsunit/index'
import {
......@@ -46,8 +45,6 @@ export default function openTest() {
let write = await fileio.write(fd, testNum);
expect(write).assertEqual(testNum.length);
let newAsset = await getFileAsset(testNum, fetchOp);
// expect(newAsset.get(photoKeys.DATE_MODIFIED) != asset.get(photoKeys.DATE_MODIFIED)).assertTrue();
}
} catch (error) {
console.info(`${testNum} error: ${error}`);
......@@ -75,6 +72,9 @@ export default function openTest() {
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead).assertEqual(assetBytes);
console.info(`${testNum} read suc`);
await fileio.write(fd, testNum);
expect(false).assertTrue();
}
} catch (error) {
console.info(`${testNum} error: ${error}`);
......@@ -100,14 +100,15 @@ export default function openTest() {
} else {
let write = await fileio.write(fd, testNum);
expect(write).assertEqual(testNum.length);
await asset.close(fd);
let newAsset = await getFileAsset(testNum, fetchOp);
// expect(newAsset.get(photoKeys.DATE_MODIFIED) != asset.get(photoKeys.DATE_MODIFIED)).assertTrue();
let buf = new ArrayBuffer(4096);
await fileio.read(fd, buf);
expect(false).assertTrue();
}
} catch (error) {
console.info(`${testNum} error: ${error}`);
await asset.close(fd);
}
await asset.close(fd);
done();
});
} catch (error) {
......@@ -118,9 +119,10 @@ export default function openTest() {
};
async function rwOpenPromise(done, testNum, fetchOp, assetBytes) {
const asset = await getFileAsset(testNum, fetchOp);
let asset;
let fd;
try {
asset = await getFileAsset(testNum, fetchOp);
fd = await asset.open('rw');
console.info(`${testNum} fd: ${fd}`);
let buf = new ArrayBuffer(4096);
......@@ -129,50 +131,71 @@ export default function openTest() {
let write = await fileio.write(fd, testNum);
expect(write).assertEqual(testNum.length);
let newAsset = await getFileAsset(testNum, fetchOp);
// expect(newAsset.get(photoKeys.DATE_MODIFIED) != asset.get(photoKeys.DATE_MODIFIED)).assertTrue();
await asset.close(fd);
done();
} catch (error) {
console.info(`${testNum} failed, error: ${error}`);
await asset.close(fd);
expect(false).assertTrue();
done();
} finally {
if (asset) {
await asset.close(fd);
}
}
};
async function rOpenPromise(done, testNum, fetchOp, assetBytes) {
let asset;
let fd;
try {
const asset = await getFileAsset(testNum, fetchOp);
const fd = await asset.open('r');
asset = await getFileAsset(testNum, fetchOp);
fd = await asset.open('r');
console.info(`${testNum} fd: ${fd}`);
let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf);
expect(res.bytesRead).assertEqual(assetBytes);
await asset.close(fd);
try {
await fileio.write(fd, testNum);
expect(false).assertTrue();
} catch (error) {
console.info(`${testNum} error: ${error}`);
}
done();
} catch (error) {
console.info(`${testNum} failed, error: ${error}`);
expect(false).assertTrue();
done();
} finally {
if (asset) {
await asset.close(fd);
}
}
};
async function wOpenPromise(done, testNum, fetchOp) {
let asset;
let fd;
try {
const asset = await getFileAsset(testNum, fetchOp);
const fd = await asset.open('w');
asset = await getFileAsset(testNum, fetchOp);
fd = await asset.open('w');
let write = await fileio.write(fd, testNum);
expect(write).assertEqual(testNum.length);
let newAsset = await getFileAsset(testNum, fetchOp);
// expect(newAsset.get(photoKeys.DATE_MODIFIED) != asset.get(photoKeys.DATE_MODIFIED)).assertTrue();
await asset.close(fd);
try {
let buf = new ArrayBuffer(4096);
await fileio.read(fd, buf);
expect(false).assertTrue();
} catch (error) {
console.info(`${testNum} error: ${error}`);
}
done();
} catch (error) {
console.info(`${testNum} failed, error: ${error}`);
expect(false).assertTrue();
done();
} finally {
if (asset) {
await asset.close(fd);
}
}
};
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
// @ts-nocheck
import photoAccessHelper from '@ohos.file.photoAccessHelper'
import { describe, it, expect } from 'deccjsunit/index'
import {
......
......@@ -8,8 +8,7 @@
"deviceTypes": [
"tablet",
"default",
"phone",
"2in1"
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册