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

!4997 XTS Split 0816

Merge pull request !4997 from caochuan/master
......@@ -9,7 +9,7 @@
# 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.
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
......@@ -43,6 +43,7 @@ group("multimedia") {
"medialibrary/mediaLibrary_fileKey:mediaLibrary_fileKey_hap",
"medialibrary/mediaLibrary_fileResult:mediaLibrary_fileResult_hap",
"medialibrary/mediaLibrary_getThumbnail:mediaLibrary_getThumbnail_hap",
"medialibrary/mediaLibrary_js:mediaLibrary_js_hap",
"medialibrary/mediaLibrary_js_standard:mediaLibrary_js_hap",
]
} else {
......
{
"app":{
"bundleName":"ohos.acts.multimedia.mediaLibrary",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:entry_MainAbility",
"description":"$string:mainability_description",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
}
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("mediaLibrary_js_hap") {
hap_profile = "entry/src/main/module.json"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsMediaLibraryJs"
}
ohos_app_scope("medialibrary_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("mediaLibrary_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("mediaLibrary_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":medialibrary_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for mediaLibrary Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "600000"
},
"kits": [
{
"type": "ShellKit",
"pre-push": [
],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
]
},
{
"type": "PushKit",
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata",
"./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/{Static,On,Off,OnAlbum,OffAlbum}",
"mkdir -pv /storage/media/100/local/files/Videos//{Static,On,Off}",
"mkdir -pv /storage/media/100/local/files/Audios/{Static,On,Off}",
"mkdir -pv /storage/media/100/local/files/Documents/{Static,On,Off}",
"for d in Static On Off OnAlbum OffAlbum; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static On Off; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static On Off; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in Static On Off; do for i in $$(seq 1); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"chmod -R 777 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
"hilog -Q pidoff",
"hilog -p off",
"hilog -b I",
"hilog -b D -D 0xD002B70",
"scanner_demo",
"sleep 10"
]
},
{
"test-file-name": [
"ActsMediaLibraryJs.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
\ 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 file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
}
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ 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 router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibraryTestPromise from './mediaLibraryTestPromise.test.ets'
import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets'
export default function testsuite(abilityContext) {
mediaLibraryTestPromise(abilityContext)
mediaLibraryTestPromiseOnOffTest(abilityContext)
}
......@@ -13,200 +13,245 @@
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILE_TYPE,
FILEKEY,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
getPermission,
isNum,
} from '../../../../../../common';
let fileKeyObj = mediaLibrary.FileKey;
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO;
let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let fileType = mediaLibrary.MediaType.FILE;
let imagesfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
let videosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
};
let audiosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
};
let filesfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
let imageRelativefetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Pictures/Static01/', imageType.toString()],
};
let videoRelativefetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Videos/Static01/', videoType.toString()],
};
let audioRelativefetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Audios/Static01/', audioType.toString()],
};
let fileRelativefetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Documents/Static01/', fileType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC",
};
let imageAndVideofetchOp = {
selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' +
fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)',
selectionArgs: ['Videos/Static01/', 'Pictures/Static01/', imageType.toString(), videoType.toString()],
};
let imageAndVideoAndfilefetchOp = {
selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' +
fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)',
selectionArgs: ['Documents/Static01/', 'Videos/Static01/', 'Pictures/Static01/', imageType.toString(), videoType.toString(), fileType.toString()],
order: fileKeyObj.DATE_ADDED + " DESC",
};
let imageAndVideoAndfileAndAudiofetchOp = {
selections: '(' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ? or ' + fileKeyObj.RELATIVE_PATH + '= ?' + ') AND (' +
fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?)',
selectionArgs: ['Documents/Static01/', 'Videos/Static01/', 'Pictures/Static01/', 'Audios/Static01/', imageType.toString(), videoType.toString(), fileType.toString(), audioType.toString(),],
order: fileKeyObj.DATE_ADDED + " DESC",
};
let allTypefetchOp = {
selections: '',
selectionArgs: [],
};
async function copyFile(fd1, fd2) {
let stat = await fileio.fstat(fd1);
let buf = new ArrayBuffer(stat.size);
await fileio.read(fd1, buf);
await fileio.write(fd2, buf);
}
const props = {
image: {
mimeType: 'image/*',
displayName: '01.jpg',
relativePath: 'Pictures/Static01/',
size: '348113',
mediaType: imageType.toString(),
title: '01',
width: '1279',
height: '1706',
orientation: '0',
duration: '0',
albumId: '1118',
},
video: {
mimeType: 'video/mp4',
displayName: '01.mp4',
relativePath: 'Videos/Static01/',
size: '4853005',
mediaType: videoType.toString(),
title: '01',
width: '1280',
height: '720',
orientation: '0',
duration: '10100',
},
audio: {
mimeType: 'audio/mpeg',
displayName: '01.mp3',
relativePath: 'Audios/Static01/',
size: '1958311',
mediaType: audioType.toString(),
title: '01',
artist: '元数据测试',
width: '219600',
height: '219600',
orientation: '0',
duration: '219600',
},
file: {
mimeType: 'file/*',
displayName: '01.dat',
relativePath: 'Documents/Static01/',
size: '10',
mediaType: fileType.toString(),
title: '01',
width: '0',
height: '0',
orientation: '0',
duration: '0',
}
}
function isNum(value) {
return typeof value === 'number' && !isNaN(value);
}
async function checkFileAssetAttr(done, fetchFileResult, type, count, typesArr) {
expect(fetchFileResult != undefined).assertTrue();
expect(fetchFileResult.getCount() == count).assertTrue();
let asset = await fetchFileResult.getFirstObject();
if (count > 1) {
type = asset.mimeType.match(/[a-z]+/g)[0]
}
if (type == 'audio' && asset.artist != props[type].artist) {
expect(false).assertTrue();
done();
}
if (typesArr) {
let assetList = await fetchFileResult.getAllObject();
for (const assetItem of assetList) {
expect(typesArr.includes(assetItem.mimeType)).assertTrue();
}
}
if(!isNum(asset.dateTaken)) {
expect(false).assertTrue();
done();
}
if (
asset.mimeType != props[type].mimeType ||
asset.displayName != props[type].displayName ||
asset.relativePath != props[type].relativePath ||
asset.size != props[type].size ||
asset.mediaType != props[type].mediaType ||
asset.title != props[type].title ||
asset.width != props[type].width ||
asset.height != props[type].height ||
asset.orientation != props[type].orientation ||
asset.duration != props[type].duration
) {
expect(false).assertTrue();
done();
}
}
export default function mediaLibraryTestPromiseTest(abilityContext){
export default function mediaLibraryTestPromiseTest(abilityContext) {
describe('mediaLibraryTestPromiseTest', function () {
const context = featureAbility.getContext();
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
let imageAndVideofetchOp = {
selections: '(' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ?' + ') AND (' +
FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ?)',
selectionArgs: ['Videos/Static/', 'Pictures/Static/', IMAGE_TYPE.toString(), VIDEO_TYPE.toString()],
};
let imageAndVideoAndfilefetchOp = {
selections: '(' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ?' + ') AND (' +
FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ?)',
selectionArgs: ['Documents/Static/', 'Videos/Static/', 'Pictures/Static/', IMAGE_TYPE.toString(), VIDEO_TYPE.toString(), FILE_TYPE.toString()],
order: FILEKEY.DATE_ADDED + " DESC",
};
let imageAndVideoAndfileAndAudiofetchOp = {
selections: '(' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ? or ' + FILEKEY.RELATIVE_PATH + '= ?' + ') AND (' +
FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ? or ' + FILEKEY.MEDIA_TYPE + '= ?)',
selectionArgs: ['Documents/Static/', 'Videos/Static/', 'Pictures/Static/', 'Audios/Static/', IMAGE_TYPE.toString(), VIDEO_TYPE.toString(), FILE_TYPE.toString(), AUDIO_TYPE.toString(),],
order: FILEKEY.DATE_ADDED + " DESC",
};
async function copyFile(fd1, fd2) {
let stat = await fileio.fstat(fd1);
let buf = new ArrayBuffer(stat.size);
await fileio.read(fd1, buf);
await fileio.write(fd2, buf);
}
beforeAll(function () { });
beforeEach(function () { });
afterEach(async function () { await sleep(200)});
afterAll(function () { });
const props = {
image: {
mimeType: 'image/*',
displayName: '01.jpg',
relativePath: 'Pictures/Static/',
size: 348113,
mediaType: IMAGE_TYPE.toString(),
title: '01',
width: 1279,
height: 1706,
orientation: 0,
duration: '0',
albumId: '1118',
},
video: {
mimeType: 'video/mp4',
displayName: '01.mp4',
relativePath: 'Videos/Static/',
size: 4853005,
mediaType: VIDEO_TYPE.toString(),
title: '01',
width: 1280,
height: 720,
orientation: 0,
duration: '10100',
},
audio: {
mimeType: 'audio/mpeg',
displayName: '01.mp3',
relativePath: 'Audios/Static/',
size: 1958311,
mediaType: AUDIO_TYPE.toString(),
title: '01',
artist: '元数据测试',
width: 219600,
height: 219600,
orientation: 0,
duration: '219600',
},
file: {
mimeType: 'file/*',
displayName: '01.dat',
relativePath: 'Documents/Static/',
size: 10,
mediaType: FILE_TYPE.toString(),
title: '01',
width: 0,
height: 0,
orientation: 0,
duration: '0',
}
}
async function checkFileAssetAttr(done, testNum, fetchOps, type, count, typesArr) {
try {
const fetchFileResult = await media.getFileAssets(fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, count);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
if (count > 1) {
type = asset.mimeType.match(/[a-z]+/g)[0]
}
if (type == 'audio') {
expect(asset.artist).assertEqual(props[type].artist);
}
if (typesArr) {
let assetList = await fetchFileResult.getAllObject();
for (const assetItem of assetList) {
expect(typesArr.includes(assetItem.mimeType)).assertTrue();
}
}
if (!isNum(asset.dateTaken)) {
expect(false).assertTrue();
done();
return;
}
expect(asset.mimeType).assertEqual(props[type].mimeType);
expect(asset.displayName).assertEqual(props[type].displayName);
expect(asset.relativePath).assertEqual(props[type].relativePath);
expect(asset.size).assertEqual(props[type].size);
expect(asset.mediaType.toString()).assertEqual(props[type].mediaType);
expect(asset.title.toString()).assertEqual(props[type].title);
expect(asset.width).assertEqual(props[type].width);
expect(asset.height).assertEqual(props[type].height);
expect(asset.orientation).assertEqual(props[type].orientation);
expect(asset.duration.toString()).assertEqual(props[type].duration);
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
var timestamp = new Date().getTime();
var jpgName = timestamp + '.jpg';
var videoName = timestamp + '.mp4';
var audioName = timestamp + '.mp3';
var fileName = timestamp + '.mp3';
const checkGetPublicDirectory = async (done, testNum, dir, val) => {
try {
const res = await media.getPublicDirectory(dir);
expect(res).assertEqual(val);
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
const getFileAssetsAbnormal = async (done, testNum, fetchOps) => {
try {
await media.getFileAssets(fetchOps);
expect(false).assertTrue();
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(true).assertTrue();
done();
}
}
const getFileAssetsZero = async (done, testNum, fetchOps) => {
try {
let fetchFileResult = await media.getFileAssets(fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 0);
expect(checkAssetCountPass).assertTrue();
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
const createAssetTest = async (done, testNum, fetchOps, type, name, path) => {
try {
const fetchFileResult = await media.getFileAssets(fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
const creatAsset = await media.createAsset(type, name, path);
const fd = await asset.open('rw');
const creatAssetFd = await creatAsset.open('rw');
await copyFile(fd, creatAssetFd);
await creatAsset.close(creatAssetFd);
await asset.close(fd);
expect(true).assertTrue();
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
const createAssetSameNameTest = async (done, testNum, fetchOps, type, name, path) => {
try {
const fetchFileResult = await media.getFileAssets(fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
const creatAsset = await media.createAsset(type, name, path);
const fd = await asset.open('rw');
const creatAssetFd = await creatAsset.open('rw');
await copyFile(fd, creatAssetFd);
await creatAsset.close(creatAssetFd);
await asset.close(fd);
try {
await media.createAsset(type, name, path);
expect(false).assertTrue();
done();
} catch (error) {
expect(true).assertTrue();
done();
}
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001
* @tc.name : getMediaLibrary
......@@ -235,17 +280,11 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imageRelativefetchOp);
let count = 1;
let type = 'image';
await checkFileAssetAttr(done, fetchFileResult, type, count, null)
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 001 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001';
let currentFetchOps = fetchOps('Pictures/Static/', IMAGE_TYPE);
let type = 'image';
let count = 1;
await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, null)
});
/**
......@@ -257,17 +296,11 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(videoRelativefetchOp);
let count = 1;
let type = 'video';
await checkFileAssetAttr(done, fetchFileResult, type, count, null)
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 002 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_002';
let currentFetchOps = fetchOps('Videos/Static/', VIDEO_TYPE);
let type = 'video';
let count = 1;
await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, null)
});
/**
......@@ -279,17 +312,11 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(audioRelativefetchOp);
let count = 1;
let type = 'audio';
await checkFileAssetAttr(done, fetchFileResult, type, count, null)
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 003 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_003';
let currentFetchOps = fetchOps('Audios/Static/', AUDIO_TYPE);
let type = 'audio';
let count = 1;
await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, null)
});
/**
......@@ -301,17 +328,11 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(fileRelativefetchOp);
let count = 1;
let type = 'file';
await checkFileAssetAttr(done, fetchFileResult, type, count, null)
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 004 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_004';
let currentFetchOps = fetchOps('Documents/Static/', FILE_TYPE);
let type = 'file';
let count = 1;
await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, null)
});
/**
......@@ -323,18 +344,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imageAndVideofetchOp);
let count = 2;
let type = 'video';
let typesArr = ['image/*', 'video/mp4']
await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr)
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 005 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_005';
let currentFetchOps = imageAndVideofetchOp;
let type = 'video';
let count = 2;
let typesArr = ['image/*', 'video/mp4']
await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, typesArr)
});
/**
......@@ -346,18 +361,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imageAndVideoAndfilefetchOp);
let count = 3;
let type = 'file';
let typesArr = ['image/*', 'video/mp4', 'file/*']
await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr)
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 006 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006';
let currentFetchOps = imageAndVideoAndfilefetchOp;
let type = 'file';
let count = 3;
let typesArr = ['image/*', 'video/mp4', 'file/*']
await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, typesArr)
});
/**
......@@ -369,18 +378,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_007', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imageAndVideoAndfileAndAudiofetchOp);
let count = 4;
let type = 'audio';
let typesArr = ['image/*', 'video/mp4', 'file/*', 'audio/mpeg']
await checkFileAssetAttr(done, fetchFileResult, type, count, typesArr)
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 007 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_006';
let currentFetchOps = imageAndVideoAndfileAndAudiofetchOp;
let type = 'audio';
let count = 4;
let typesArr = ['image/*', 'video/mp4', 'file/*', 'audio/mpeg']
await checkFileAssetAttr(done, testNum, currentFetchOps, type, count, typesArr)
});
/**
......@@ -392,20 +395,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008', 0, async function (done) {
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + 'abc= ?',
selectionArgs: ['abc'],
let currentFetchOps = {
selections: FILEKEY.MEDIA_TYPE + '= ?',
selectionArgs: [],
};
try {
await media.getFileAssets(fetchOp);
console.info('MediaLibraryTest : getFileAssets 008 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getFileAssets 008 passed`);
expect(true).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_008';
await getFileAssetsZero(done, testNum, currentFetchOps)
});
/**
......@@ -417,24 +412,16 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009', 0, async function (done) {
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['abc', audioType.toString()],
let currentFetchOps = {
selections: FILEKEY.MEDIA_TYPE + 'abc= ?',
selectionArgs: [AUDIO_TYPE.toString()],
};
try {
await media.getFileAssets(fetchOp);
console.info('MediaLibraryTest : getFileAssets 009 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : getFileAssets 009 passed');
expect(true).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009';
await getFileAssetsAbnormal(done, testNum, currentFetchOps)
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_009
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010
* @tc.name : getFileAssets
* @tc.desc : query all assets
* @tc.size : MEDIUM
......@@ -442,26 +429,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) {
let fetchOp = {
selections:
fileKeyObj.MEDIA_TYPE +
'abc= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: ['abc', videoType.toString(), fileType.toString()],
let currentFetchOps = {
selections: FILEKEY.MEDIA_TYPE + '= ?',
selectionArgs: [111],
};
try {
await media.getFileAssets(fetchOp);
console.info('MediaLibraryTest : getFileAssets 010 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : getFileAssets 010 passed');
expect(true).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010';
await getFileAssetsZero(done, testNum, currentFetchOps)
});
/**
......@@ -473,28 +446,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) {
let fetchOp = {
selections:
fileKeyObj.MEDIA_TYPE +
'abc= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()],
let currentFetchOps = {
selections: 'abc' + '= ?',
selectionArgs: [AUDIO_TYPE.toString()],
};
try {
await media.getFileAssets(fetchOp);
console.info('MediaLibraryTest : getFileAssets 011 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : getFileAssets 011 passed');
expect(true).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011';
await getFileAssetsAbnormal(done, testNum, currentFetchOps)
});
/**
......@@ -506,18 +463,10 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001', 0, async function (done) {
try {
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
const dicResult = await media.getPublicDirectory(DIR_CAMERA);
expect(dicResult == 'Camera/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 001 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_001';
let dir = mediaLibrary.DirectoryType.DIR_CAMERA;
let val = 'Camera/';
await checkGetPublicDirectory(done, testNum, dir, val)
});
/**
......@@ -529,18 +478,10 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002', 0, async function (done) {
try {
let DIR_VIDEO = mediaLibrary.DirectoryType.DIR_VIDEO;
const dicResult = await media.getPublicDirectory(DIR_VIDEO);
console.log(dicResult);
expect(dicResult == 'Videos/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 002 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_002';
let dir = mediaLibrary.DirectoryType.DIR_VIDEO;
let val = 'Videos/';
await checkGetPublicDirectory(done, testNum, dir, val)
});
/**
......@@ -552,18 +493,10 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003', 0, async function (done) {
try {
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const dicResult = await media.getPublicDirectory(DIR_IMAGE);
expect(dicResult == 'Pictures/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 003 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_003';
let dir = mediaLibrary.DirectoryType.DIR_IMAGE;
let val = 'Pictures/';
await checkGetPublicDirectory(done, testNum, dir, val)
});
/**
......@@ -575,18 +508,10 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004', 0, async function (done) {
try {
let DIR_AUDIO = mediaLibrary.DirectoryType.DIR_AUDIO;
const dicResult = await media.getPublicDirectory(DIR_AUDIO);
expect(dicResult == 'Audios/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 004 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004';
let dir = mediaLibrary.DirectoryType.DIR_AUDIO;
let val = 'Audios/';
await checkGetPublicDirectory(done, testNum, dir, val)
});
/**
......@@ -598,18 +523,10 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_005', 0, async function (done) {
try {
let DIR_DOCUMENTS = mediaLibrary.DirectoryType.DIR_DOCUMENTS;
const dicResult = await media.getPublicDirectory(DIR_DOCUMENTS);
expect(dicResult == 'Documents/').assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : getPublicDirectory 005 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_GETPUBLICDIRECTORY_004';
let dir = mediaLibrary.DirectoryType.DIR_DOCUMENTS;
let val = 'Documents/';
await checkGetPublicDirectory(done, testNum, dir, val)
});
/**
......@@ -642,27 +559,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, jpgName, path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 001 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 001 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001';
let currentFetchOps = fetchOps('Pictures/Static/', IMAGE_TYPE);
let type = IMAGE_TYPE;
let name = new Date().getTime() + '.jpg';
let path = 'Pictures/Create/';
await createAssetTest(done, testNum, currentFetchOps, type, name, path)
});
/**
......@@ -674,26 +576,13 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, jpgName, path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 002 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 002 passed`);
expect(true).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_002';
let currentFetchOps = fetchOps('Pictures/Static/', IMAGE_TYPE);
let type = IMAGE_TYPE;
let name = new Date().getTime() + '.jpg';
let path = 'Pictures/Create/';
await createAssetSameNameTest(done, testNum, currentFetchOps, type, name, path)
});
/**
......@@ -705,26 +594,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(videoType, videoName, path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 003 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 003 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_003';
let currentFetchOps = fetchOps('Videos/Static/', VIDEO_TYPE);
let type = VIDEO_TYPE;
let name = new Date().getTime() + '.mp4';
let path = 'Videos/Create/';
await createAssetTest(done, testNum, currentFetchOps, type, name, path)
});
/**
......@@ -736,26 +611,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(videoType, videoName, path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 004 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 004 passed`);
expect(true).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_004';
let currentFetchOps = fetchOps('Videos/Static/', VIDEO_TYPE);
let type = VIDEO_TYPE;
let name = new Date().getTime() + '.mp4';
let path = 'Videos/Create/';
await createAssetSameNameTest(done, testNum, currentFetchOps, type, name, path)
});
/**
......@@ -767,26 +628,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO);
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(audioType, audioName, path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 005 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 005 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_005';
let currentFetchOps = fetchOps('Audios/Static/', AUDIO_TYPE);
let type = AUDIO_TYPE;
let name = new Date().getTime() + '.mp3';
let path = 'Audios/Create/';
await createAssetTest(done, testNum, currentFetchOps, type, name, path)
});
/**
......@@ -798,26 +645,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO);
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(videoType, audioName, path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 006 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 006 passed`);
expect(true).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_006';
let currentFetchOps = fetchOps('Audios/Static/', AUDIO_TYPE);
let type = AUDIO_TYPE;
let name = new Date().getTime() + '.mp3';
let path = 'Audios/Create/';
await createAssetSameNameTest(done, testNum, currentFetchOps, type, name, path)
});
/**
......@@ -829,26 +662,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD);
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(audioType, fileName, path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 007 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 007 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_007';
let currentFetchOps = fetchOps('Documents/Static/', FILE_TYPE);
let type = FILE_TYPE;
let name = new Date().getTime() + '.dat';
let path = 'Documents/Create/';
await createAssetTest(done, testNum, currentFetchOps, type, name, path)
});
/**
......@@ -860,26 +679,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_DOWNLOAD);
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(fileType, fileName, path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 008 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 008 passed`);
expect(true).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_008';
let currentFetchOps = fetchOps('Documents/Static/', FILE_TYPE);
let type = FILE_TYPE;
let name = new Date().getTime() + '.dat';
let path = 'Documents/Create/';
await createAssetSameNameTest(done, testNum, currentFetchOps, type, name, path)
});
/**
......@@ -891,26 +696,12 @@ export default function mediaLibraryTestPromiseTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_009', 0, async function (done) {
try {
const path = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const filePath = path + "image/";
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, jpgName, filePath);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
await creatAsset1.close(creatAssetFd1);
await asset1.close(fd1);
console.info('MediaLibraryTest : createAsset 009 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : createAsset 009 failed, error: ${error}`);
expect(false).assertTrue();
done();
}
let testNum = 'SUB__MEDIA_MIDIALIBRARY_PROMISE_CREATEASSET_001';
let currentFetchOps = fetchOps('Pictures/Static/', IMAGE_TYPE);
let type = IMAGE_TYPE;
let name = new Date().getTime() + '.jpg';
let path = 'Pictures/Create/Temp';
await createAssetTest(done, testNum, currentFetchOps, type, name, path)
});
});
}
......
......@@ -13,108 +13,112 @@
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILE_TYPE,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
albumFetchOps,
getPermission,
checkAlbumsCount,
} from '../../../../../../common';
export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
describe('mediaLibraryTestPromiseOnOffTest', function () {
const context = featureAbility.getContext();
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(function () { });
beforeEach(function () { });
afterEach(function () { });
afterAll(function () { });
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let fileType = mediaLibrary.MediaType.FILE;
let imagesfetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Pictures/Dynamic01/', imageType.toString()],
};
let videosfetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Videos/Dynamic01/', videoType.toString()],
};
let audiosfetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Audios/Dynamic01/', audioType.toString()],
};
let filesfetchOp = {
selections: fileKeyObj.RELATIVE_PATH + '= ? AND ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: ['Documents/Dynamic01/', fileType.toString()],
};
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryGetThumbnail');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001
* @tc.name : ON
* @tc.desc : ON Image ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001', 0, async function (done) {
const onTest = async (done, testNum, type, fetchOps) => {
try {
let conut = 0;
media.on('imageChange', () => {
console.info('MediaLibraryTest : on 001 callback');
conut++;
});
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
media.on(type, () => { conut++; });
const fetchFileResult = await media.getFileAssets(fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
await sleep(1000)
expect(conut > 0).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : on 001 failed, error: ${error}`);
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
media.off('imageChange');
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002
* @tc.name : ON
* @tc.desc : ON Video ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002', 0, async function (done) {
}
const offTest = async (done, testNum, type, fetchOps) => {
try {
let conut = 0;
media.on('videoChange', () => {
console.info('MediaLibraryTest : on 002 callback');
media.on(type, () => {
conut++;
});
const fetchFileResult = await media.getFileAssets(videosfetchOp);
await sleep(200)
const fetchFileResult = await media.getFileAssets(fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
media.off(type);
await sleep(200)
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
expect(conut > 0).assertTrue();
await sleep(1000)
expect(conut).assertEqual(0);
done();
} catch (error) {
console.info(`MediaLibraryTest : on 002 failed, error: ${error}`);
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
media.off('videoChange');
done();
}
}
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001
* @tc.name : ON
* @tc.desc : ON Image ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001', 0, async function (done) {
let type = 'imageChange'
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001';
let currentFetchOps = fetchOps('Pictures/On/', IMAGE_TYPE);
await onTest(done, testNum, type, currentFetchOps)
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002
* @tc.name : ON
* @tc.desc : ON Video ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002', 0, async function (done) {
let type = 'videoChange'
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002';
let currentFetchOps = fetchOps('Videos/On/', VIDEO_TYPE);
await onTest(done, testNum, type, currentFetchOps)
});
/**
......@@ -126,29 +130,10 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003', 0, async function (done) {
try {
let conut = 0;
media.on('audioChange', () => {
console.info('MediaLibraryTest : on 003 callback');
conut++;
});
const fetchFileResult = await media.getFileAssets(audiosfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
expect(conut > 0).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : on 003 failed, error: ${error}`);
expect(false).assertTrue();
media.off('audioChange');
done();
}
let type = 'audioChange'
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003';
let currentFetchOps = fetchOps('Audios/On/', AUDIO_TYPE);
await onTest(done, testNum, type, currentFetchOps)
});
/**
......@@ -160,61 +145,43 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004', 0, async function (done) {
try {
let conut = 0;
media.on('fileChange', () => {
console.info('MediaLibraryTest : on 004 callback');
conut++;
});
const fetchFileResult = await media.getFileAssets(filesfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
expect(conut > 0).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : on 004 failed, error: ${error}`);
expect(false).assertTrue();
media.off('fileChange');
done();
}
let type = 'fileChange'
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004';
let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE);
await onTest(done, testNum, type, currentFetchOps)
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005
* @tc.name : ON
* @tc.desc : ON ALBUM ASSET
* @tc.desc : ON ALBUM
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005', 0, async function (done) {
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005'
try {
let conut = 0;
media.on('albumChange', () => {
console.info('MediaLibraryTest : on 005 callback');
conut++;
});
const fetchFileResult = await media.getFileAssets(filesfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
expect(conut == 0).assertTrue();
let currentFetchOps = albumFetchOps('Pictures/', 'OnAlbum', IMAGE_TYPE);
const albumList = await media.getAlbums(currentFetchOps);
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, 1);
if (!albumCountPass) return;
const album = albumList[0];
const oldName = album.albumName
album.albumName = album.albumName + 'changename';
await album.commitModify();
await sleep(1000)
expect(conut > 0).assertTrue();
album.albumName = oldName;
await album.commitModify();
done();
} catch (error) {
console.info(`MediaLibraryTest : on 005 failed, error: ${error}`);
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
media.off('albumChange');
done();
}
});
......@@ -236,7 +203,8 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
console.info('MediaLibraryTest : on 006 callback');
conut++;
});
const fetchFileResult = await media.getFileAssets(filesfetchOp);
let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE);
const fetchFileResult = await media.getFileAssets(currentFetchOps);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
await asset.commitModify();
......@@ -272,7 +240,9 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
console.info('MediaLibraryTest : on 007 callback');
conut++;
});
const fetchFileResult = await media.getFileAssets(filesfetchOp);
let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE);
const fetchFileResult = await media.getFileAssets(currentFetchOps);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
await asset.commitModify();
......@@ -300,42 +270,10 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001', 0, async function (done) {
try {
media.on('imageChange', () => {
console.info('MediaLibraryTest : off 001 failed');
expect(false).assertTrue();
media.off('imageChange');
done();
});
await new Promise(res => {
setTimeout(() => {
res(true)
}, 300)
})
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
media.off('imageChange');
await new Promise(res => {
setTimeout(() => {
res(true)
}, 600)
})
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
console.info('MediaLibraryTest : off 001 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 001 failed, error: ${error}`);
expect(false).assertTrue();
media.off('imageChange');
done();
}
let type = 'imageChange'
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_001';
let currentFetchOps = fetchOps('Pictures/Off/', IMAGE_TYPE);
await offTest(done, testNum, type, currentFetchOps)
});
/**
......@@ -347,42 +285,10 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002', 0, async function (done) {
try {
media.on('videoChange', () => {
console.info('MediaLibraryTest : off 002 failed');
expect(false).assertTrue();
media.off('videoChange');
done();
});
await new Promise(res => {
setTimeout(() => {
res(true)
}, 300)
})
const fetchFileResult = await media.getFileAssets(videosfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
media.off('videoChange');
await new Promise(res => {
setTimeout(() => {
res(true)
}, 600)
})
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
console.info('MediaLibraryTest : off 002 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 002 failed, error: ${error}`);
expect(false).assertTrue();
media.off('videoChange');
done();
}
let type = 'videoChange'
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_002';
let currentFetchOps = fetchOps('Videos/Off/', VIDEO_TYPE);
await offTest(done, testNum, type, currentFetchOps)
});
/**
......@@ -394,42 +300,10 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003', 0, async function (done) {
try {
media.on('audioChange', () => {
console.info('MediaLibraryTest : off 003 failed');
expect(false).assertTrue();
media.off('audioChange');
done();
});
await new Promise(res => {
setTimeout(() => {
res(true)
}, 300)
})
const fetchFileResult = await media.getFileAssets(audiosfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
media.off('audioChange');
await new Promise(res => {
setTimeout(() => {
res(true)
}, 600)
})
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
console.info('MediaLibraryTest : off 003 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 003 failed, error: ${error}`);
expect(false).assertTrue();
media.off('audioChange');
done();
}
let type = 'audioChange'
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_003';
let currentFetchOps = fetchOps('Audios/Off/', AUDIO_TYPE);
await offTest(done, testNum, type, currentFetchOps)
});
/**
......@@ -441,89 +315,10 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004', 0, async function (done) {
try {
media.on('fileChange', () => {
console.info('MediaLibraryTest : off 004 failed');
expect(false).assertTrue();
media.off('fileChange');
done();
});
await new Promise(res => {
setTimeout(() => {
res(true)
}, 300)
})
const fetchFileResult = await media.getFileAssets(videosfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename';
media.off('fileChange');
await new Promise(res => {
setTimeout(() => {
res(true)
}, 600)
})
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
console.info('MediaLibraryTest : off 004 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 004 failed, error: ${error}`);
expect(false).assertTrue();
media.off('fileChange');
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005
* @tc.name : off
* @tc.desc : off album ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_005', 0, async function (done) {
try {
media.on('albumChange', () => {
console.info('MediaLibraryTest : off 005 failed');
expect(false).assertTrue();
media.off('albumChange');
done();
});
await new Promise(res => {
setTimeout(() => {
res(true)
}, 300)
})
const fetchFileResult = await media.getFileAssets(videosfetchOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'albumChange';
media.off('albumChange');
await new Promise(res => {
setTimeout(() => {
res(true)
}, 600)
})
await asset.commitModify();
await new Promise(res => {
setTimeout(() => {
res(true)
}, 1000)
})
console.info('MediaLibraryTest : off 005 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 005 failed, error: ${error}`);
expect(false).assertTrue();
media.off('fileChange');
done();
}
let type = 'fileChange'
let testNum = 'SUB_MEDIA_MIDIALIBRARY_PROMISE_OFF_004';
let currentFetchOps = fetchOps('Documents/Off/', FILE_TYPE);
await offTest(done, testNum, type, currentFetchOps)
});
/**
......@@ -547,7 +342,8 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
res(true)
}, 300)
})
const fetchFileResult = await media.getFileAssets(videosfetchOp);
let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE);
const fetchFileResult = await media.getFileAssets(currentFetchOps);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'deviceChange';
media.off('deviceChange');
......@@ -596,7 +392,8 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext){
})
media.off('remoteFileChange');
const fetchFileResult = await media.getFileAssets(videosfetchOp);
let currentFetchOps = fetchOps('Documents/On/', FILE_TYPE);
const fetchFileResult = await media.getFileAssets(currentFetchOps);
const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'remoteFileChange';
await new Promise(res => {
......
{
"module": {
"name": "phone",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:mainability_description",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"abilities": [
{
"name": "ohos.acts.multimedia.mediaLibrary.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description",
"icon": "$media:icon",
"label": "$string:entry_MainAbility",
"visible": true,
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "use ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.MEDIA_LOCATION",
"reason":"use ohos.permission.MEDIA_LOCATION"
},
{
"name": "ohos.permission.READ_MEDIA",
"reason":"use ohos.permission.READ_MEDIA"
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason":"use ohos.permission.WRITE_MEDIA"
}
]
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
{
"src": [
"pages/index/index",
"pages/second/second"
]
}
\ No newline at end of file
......@@ -17,8 +17,6 @@ import fileAssetCallBack2Test from './fileAssetCallBack2.test.ets'
import fileAssetTestCallbackTest from './fileAssetTestCallback.test.ets'
import fileTestCallBackTest from './fileTestCallBack.test.ets'
import mediaLibraryTestCallBackTest from './mediaLibraryTestCallBack.test.ets'
import mediaLibraryTestPromiseTest from './mediaLibraryTestPromise.test.ets'
import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets'
export default function testsuite(abilityContext) {
getPermissionTest()
......@@ -26,6 +24,4 @@ export default function testsuite(abilityContext) {
fileAssetTestCallbackTest(abilityContext)
fileTestCallBackTest(abilityContext)
mediaLibraryTestCallBackTest(abilityContext)
mediaLibraryTestPromiseTest(abilityContext)
mediaLibraryTestPromiseOnOffTest(abilityContext)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册