提交 e7e856fb 编写于 作者: C caochuan

XTS Split 0815

 fix ActsFileAssetUriJsTest and ActsFileAssetGetThumbnailJsTest
Signed-off-by: Ncaochuan <weiyufeng@neusoft.com>
上级 a4ae1ed7
......@@ -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")
......@@ -39,8 +39,10 @@ group("multimedia") {
"medialibrary/mediaLibrary_favorite:mediaLibrary_favorite_hap",
"medialibrary/mediaLibrary_file:mediaLibrary_file_hap",
"medialibrary/mediaLibrary_fileAsset:mediaLibrary_fileAsset_hap",
"medialibrary/mediaLibrary_fileAssetUri:mediaLibrary_fileAssetUri_hap",
"medialibrary/mediaLibrary_fileKey:mediaLibrary_fileKey_hap",
"medialibrary/mediaLibrary_fileResult:mediaLibrary_fileResult_hap",
"medialibrary/mediaLibrary_getThumbnail:mediaLibrary_getThumbnail_hap",
"medialibrary/mediaLibrary_js_standard:mediaLibrary_js_hap",
]
} else {
......
......@@ -26,6 +26,7 @@ const presetsCount = {
ActsMediaLibraryFileKey: { assetsCount: 4, albumsCount: 4 },
ActsMediaLibraryFileAsset: { assetsCount: 4, albumsCount: 4 },
ActsMediaLibraryFile: { assetsCount: 4, albumsCount: 4 },
ActsMediaLibraryGetThumbnail: { assetsCount: 3, albumsCount: 3 },
}
const IMAGE_TYPE = mediaLibrary.MediaType.IMAGE;
......
{
"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_fileAssetUri_hap") {
hap_profile = "entry/src/main/module.json"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsMediaLibraryFileAssetUri"
}
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",
"mkdir -pv /storage/media/100/local/files/Videos/Static",
"mkdir -pv /storage/media/100/local/files/Audios/Static",
"mkdir -pv /storage/media/100/local/files/Documents/Static",
"for d in Static; do for i in $$(seq 2); 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; do for i in $$(seq 2); 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; do for i in $$(seq 2); 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; do for i in $$(seq 2); 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 D -D 0xD002B70",
"scanner_demo",
"sleep 10"
]
},
{
"test-file-name": [
"ActsMediaLibraryFileAssetUri.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 fileAssetUriTestPromise from './fileAssetUriTestPromise.test.ets'
import fileAssetUriTestCallback from './fileAssetUriTestCallback.test.ets'
export default function testsuite(abilityContext) {
fileAssetUriTestCallback(abilityContext)
fileAssetUriTestPromise(abilityContext)
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
AUDIO_TYPE,
VIDEO_TYPE,
FILE_TYPE,
FILEKEY,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
getPermission,
} from '../../../../../../common';
export default function filekeyTestCallbackTest(abilityContext) {
describe('filekeyTestCallbackTest', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await checkPresetsAssets(media, 'ActsMediaLibraryFileAssetUri');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const serachUri = async (done, testNum, fetchOp, type) => {
try {
const fetchFileResult = await media.getFileAssets(fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 2);
if (!checkAssetCountPass) return;
let firstObject = await fetchFileResult.getFirstObject();
const id = firstObject.id;
const uri = firstObject.uri;
const serachUri = `datashare:///media/${type}/${id}`;
console.info(`${testNum} :uri ${uri};serachUri${serachUri})`)
let serchfetchOp = {
uri: serachUri.toString(),
selections: '',
selectionArgs: [],
};
media.getFileAssets(serchfetchOp, async (err, result) => {
if (err) {
console.info(`${testNum}, err: ${err}`)
expect(false).assertTrue();
done();
return;
}
checkAssetCountPass = await checkAssetsCount(done, testNum, result, 1);
if (!checkAssetCountPass) return;
let asset = await result.getFirstObject();
expect(asset.uri).assertEqual(serachUri);
expect(asset.id).assertEqual(id);
done();
});
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_001
* @tc.name : uri
* @tc.desc : serach image asset by uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_001', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_001';
let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE);
let type = 'image';
await serachUri(done, testNum, currentFetchOp, type);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_002
* @tc.name : uri
* @tc.desc : serach audio asset by uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_002', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_002';
let currentFetchOp = fetchOps('Audios/Static/', AUDIO_TYPE);
let type = 'audio';
await serachUri(done, testNum, currentFetchOp, type);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_003
* @tc.name : uri
* @tc.desc : serach video asset by uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_003', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_003';
let currentFetchOp = fetchOps('Videos/Static/', VIDEO_TYPE);
let type = 'video';
await serachUri(done, testNum, currentFetchOp, type);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_004
* @tc.name : uri
* @tc.desc : serach file asset by uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_004', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_Callback_004';
let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE);
let type = 'file';
await serachUri(done, testNum, currentFetchOp, type);
});
});
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
IMAGE_TYPE,
AUDIO_TYPE,
VIDEO_TYPE,
FILE_TYPE,
FILEKEY,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
getPermission,
} from '../../../../../../common';
export default function filekeyTestPromiseTest(abilityContext) {
describe('filekeyTestPromiseTest', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await checkPresetsAssets(media, 'ActsMediaLibraryFileAssetUri');
});
beforeEach(function () {
console.info('beforeEach case');
});
afterEach(async function () {
console.info('afterEach case');
await sleep()
});
afterAll(function () {
console.info('afterAll case');
});
const serachUri = async (done, testNum, fetchOp, type) => {
try {
const fetchFileResult = await media.getFileAssets(fetchOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 2);
if (!checkAssetCountPass) return;
let firstObject = await fetchFileResult.getFirstObject();
const id = firstObject.id;
const uri = firstObject.uri;
const serachUri = `datashare:///media/${type}/${id}`;
console.info(`${testNum} :uri ${uri};serachUri${serachUri})`)
let serchfetchOp = {
uri: serachUri.toString(),
selections: '',
selectionArgs: [],
};
const result = await media.getFileAssets(serchfetchOp);
checkAssetCountPass = await checkAssetsCount(done, testNum, result, 1);
if (!checkAssetCountPass) return;
let asset = await result.getFirstObject();
expect(asset.uri).assertEqual(serachUri);
expect(asset.id).assertEqual(id);
done();
} catch (error) {
console.info(`${testNum} failed error: ${error}`)
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_001
* @tc.name : uri
* @tc.desc : serach image asset by uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_001', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_001';
let currentFetchOp = fetchOps('Pictures/Static/', IMAGE_TYPE);
let type = 'image';
await serachUri(done, testNum, currentFetchOp, type);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_002
* @tc.name : uri
* @tc.desc : serach audio asset by uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_002', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_002';
let currentFetchOp = fetchOps('Audios/Static/', AUDIO_TYPE);
let type = 'audio';
await serachUri(done, testNum, currentFetchOp, type);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_003
* @tc.name : uri
* @tc.desc : serach video asset by uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_003', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_003';
let currentFetchOp = fetchOps('Videos/Static/', VIDEO_TYPE);
let type = 'video';
await serachUri(done, testNum, currentFetchOp, type);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_004
* @tc.name : uri
* @tc.desc : serach file asset by uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_004', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_ASSET_URI_PROMISE_004';
let currentFetchOp = fetchOps('Documents/Static/', FILE_TYPE);
let type = 'file';
await serachUri(done, testNum, currentFetchOp, type);
});
});
}
{
"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
......@@ -33,17 +33,16 @@
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/ImageInfo",
"mkdir -pv /storage/media/100/local/files/Audios/Static2",
"mkdir -pv /storage/media/100/local/files/Audios/Static",
"cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/ImageInfo/01.jpg",
"cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/Static2/01.mp3",
"cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/Static/01.mp3",
"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 D -D 0xD002B70",
"aa start -a com.ohos.photos.MainAbility -b com.ohos.photos",
"scanner_demo",
"sleep 10"
]
......
......@@ -64,7 +64,7 @@ export default function filekeyTestCallbackTest(abilityContext) {
try {
let assetOp = fetchOps('Pictures/ImageInfo/', IMAGE_TYPE);
if (type == 'audioAlbum' || type == 'artist' || type == 'duration') {
assetOp = fetchOps('Audios/Static2/', AUDIO_TYPE);
assetOp = fetchOps('Audios/Static/', AUDIO_TYPE);
}
console.info(`${testNum} assOp : ${JSON.stringify(assetOp)}`)
let fetchFileResult = await media.getFileAssets(assetOp);
......
......@@ -64,7 +64,7 @@ export default function filekeyTestPromiseTest(abilityContext) {
try {
let assetOp = fetchOps('Pictures/ImageInfo/', IMAGE_TYPE);
if (type == 'audioAlbum' || type == 'artist' || type == 'duration') {
assetOp = fetchOps('Audios/Static2/', AUDIO_TYPE);
assetOp = fetchOps('Audios/Static/', AUDIO_TYPE);
}
console.info(`${testNum} assOp : ${JSON.stringify(assetOp)}`)
let fetchFileResult = await media.getFileAssets(assetOp);
......
{
"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_getThumbnail_hap") {
hap_profile = "entry/src/main/module.json"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsMediaLibraryGetThumbnailTest"
}
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": "300000"
},
"kits": [
{
"type": "ShellKit",
"pre-push": [
],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.MediaLibraryDataA/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA"
]
},
{
"type": "PushKit",
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/Thumbnail",
"mkdir -pv /storage/media/100/local/files/Videos/Thumbnail",
"mkdir -pv /storage/media/100/local/files/Audios/Thumbnail",
"cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.jpg /storage/media/100/local/files/Pictures/Thumbnail",
"cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.mp3 /storage/media/100/local/files/Audios/Thumbnail",
"cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.mp4 /storage/media/100/local/files/Videos/Thumbnail",
"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 D -D 0xD002B70",
"scanner_demo",
"sleep 10"
],
"teardown-command":[
"rm -rf /storage/media/100/local/files/*"
]
},
{
"test-file-name": [
"ActsMediaLibraryGetThumbnailTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
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) 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 getThumbnailPromise from './getThumbnailPromise.test.ets'
import getThumbnailCallback from './getThumbnailCallback.test.ets'
export default function testsuite(abilityContext) {
getThumbnailCallback(abilityContext)
getThumbnailPromise(abilityContext)
}
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import image from '@ohos.multimedia.image';
import {
sleep,
IMAGE_TYPE,
VIDEO_TYPE,
AUDIO_TYPE,
FILEKEY,
checkPresetsAssets,
checkAssetsCount,
fetchOps,
getPermission,
} from '../../../../../../common';
export default function getThumbnailPromise(abilityContext) {
describe('getThumbnailPromise', function () {
image.createPixelMap(new ArrayBuffer(4096), { size: { height: 1, width: 2 } }).then((pixelmap) => { });
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');
});
async function testGetThumbnail(done, testNum, dOp, size,) {
try {
let fetchFileResult = await media.getFileAssets(dOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
console.info(`${testNum}:displayName ${asset.displayName}`)
let pixelmap;
if (size == 'default') {
size = { width: 256, height: 256 };
pixelmap = await asset.getThumbnail()
} else {
pixelmap = await asset.getThumbnail(size)
}
let info = await pixelmap.getImageInfo();
console.info(`${testNum}:: pixel width ${info.size.width},pixel height: ${info.size.height}`);
console.info(`${testNum}:: param width ${size.width},param height: ${size.height}`);
expect(info.size.width == size.width).assertTrue();
expect(info.size.height == size.height).assertTrue();
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(false).assertTrue();
done();
}
}
async function testGetThumbnailError(done, testNum, dOp, size,) {
try {
let fetchFileResult = await media.getFileAssets(dOp);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return;
let asset = await fetchFileResult.getFirstObject();
let s: mediaLibrary.Size = size;
let pixelmap = await asset.getThumbnail(s);
let info = await pixelmap.getImageInfo();
console.info(`${testNum}:: pixel width ${info.size.width},pixel height: ${info.size.height}`);
expect(false).assertTrue();
done();
} catch (error) {
console.info(`${testNum}:: error :${error}`);
expect(true).assertTrue();
done();
}
}
// ------------------------------ image type start -----------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_01';
let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE);
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, dOp, size)
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by { width: 128, height: 256 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_02';
let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE);
let size = { width: 128, height: 256 };
await testGetThumbnail(done, testNum, dOp, size);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_03';
let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE);
let size = 'default';
await testGetThumbnail(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by { width: 1, height: 1 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_04';
let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE);
let size = { width: 1, height: 1 };
await testGetThumbnail(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by { width: 1024, height: 1024 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_05';
let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE);
let size = { width: 0, height: 0 };
await testGetThumbnailError(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(image) by { width: -128, height: -128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_06';
let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE);
let size = { width: -128, height: -128 };
await testGetThumbnailError(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_001_07';
let dOp = fetchOps('Pictures/Thumbnail/', IMAGE_TYPE);
let size = { width: 1024, height: 1024 };
await testGetThumbnail(done, testNum, dOp, size,);
});
// ------------------------------image type end--------------------------
// ------------------------------video type start -----------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_01';
let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE);
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, dOp, size)
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by { width: 128, height: 256 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_02';
let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE);
let size = { width: 128, height: 256 };
await testGetThumbnail(done, testNum, dOp, size);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_03';
let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE);
let size = 'default';
await testGetThumbnail(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by { width: 1, height: 1 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_04';
let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE);
let size = { width: 1, height: 1 };
await testGetThumbnail(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by { width: 0, height: 0 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_05';
let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE);
let size = { width: 0, height: 0 };
await testGetThumbnailError(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by { width: -128, height: -128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_06';
let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE);
let size = { width: -128, height: -128 };
await testGetThumbnailError(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(video) by { width: 1024, height: 1024 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_002_07';
let dOp = fetchOps('Videos/Thumbnail/', VIDEO_TYPE);
let size = { width: 1024, height: 1024 };
await testGetThumbnail(done, testNum, dOp, size,);
});
// ------------------------------video type end--------------------------
// ------------------------------audio type start -----------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: 128, height: 128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_01';
let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE);
let size = { width: 128, height: 128 };
await testGetThumbnail(done, testNum, dOp, size)
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: 128, height: 256 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_02';
let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE);
let size = { width: 128, height: 256 };
await testGetThumbnail(done, testNum, dOp, size);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by no arg
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_03';
let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE);
let size = 'default';
await testGetThumbnail(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: 1, height: 1 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_04';
let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE);
let size = { width: 1, height: 1 };
await testGetThumbnail(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: 0, height: 0 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_05';
let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE);
let size = { width: 0, height: 0 };
await testGetThumbnailError(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: -128, height: -128 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_06';
let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE);
let size = { width: -128, height: -128 };
await testGetThumbnailError(done, testNum, dOp, size,);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07
* @tc.name : getThumbnail
* @tc.desc : getThumbnail(audio) by { width: 1024, height: 1024 }
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_GETTHUMBNAIL_PROMISE_003_07';
let dOp = fetchOps('Audios/Thumbnail/', AUDIO_TYPE);
let size = { width: 1024, height: 1024 };
await testGetThumbnail(done, testNum, dOp, size,);
});
// ------------------------------audio type end--------------------------
});
}
{
"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
......@@ -14,11 +14,7 @@
*/
import getPermissionTest from './getPermission.test.ets'
import fileAssetCallBack2Test from './fileAssetCallBack2.test.ets'
import FileAssetGetThumbnailCallBackTest from './FileAssetGetThumbnailCallBack.test.ets'
import FileAssetGetThumbnailPromiseTest from './FileAssetGetThumbnailPromise.test.ets'
import fileAssetTestCallbackTest from './fileAssetTestCallback.test.ets'
import fileAssetUriTestCallBackTest from './fileAssetUriTestCallBack.test.ets'
import fileAssetUriTestPromiseTest from './fileAssetUriTestPromise.test.ets'
import fileTestCallBackTest from './fileTestCallBack.test.ets'
import mediaLibraryTestCallBackTest from './mediaLibraryTestCallBack.test.ets'
import mediaLibraryTestPromiseTest from './mediaLibraryTestPromise.test.ets'
......@@ -27,11 +23,7 @@ import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.tes
export default function testsuite(abilityContext) {
getPermissionTest()
fileAssetCallBack2Test(abilityContext)
FileAssetGetThumbnailCallBackTest(abilityContext)
FileAssetGetThumbnailPromiseTest(abilityContext)
fileAssetTestCallbackTest(abilityContext)
fileAssetUriTestCallBackTest(abilityContext)
fileAssetUriTestPromiseTest(abilityContext)
fileTestCallBackTest(abilityContext)
mediaLibraryTestCallBackTest(abilityContext)
mediaLibraryTestPromiseTest(abilityContext)
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import featureAbility from '@ohos.ability.featureAbility'
import fileio from '@ohos.fileio';
import {describe, it, expect} from 'deccjsunit/index';
export default function fileAssetUriTestCallBackTest(abilityContext){
describe('fileAssetUriTestCallBackTest', function() {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(abilityContext);
console.info('MediaLibraryTest : getMediaLibrary OUT');
const fileKeyObj = mediaLibrary.FileKey;
//======================== FILE BEGIN ==================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35
* @tc.name : close
* @tc.desc : asset close the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35', 0, async function(done) {
let asset;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.IMAGE;
let fetchOp = {
selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs : [ type.toString() ],
};
const fetchFileResult = await media.getFileAssets(fetchOp);
expect(fetchFileResult != undefined).assertTrue();
let firstObject = await fetchFileResult.getFirstObject();
const id = firstObject.id;
const uri = firstObject.uri;
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 uri:'
+ uri);
const serachUri = 'datashare:///media/image/' + id;
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 serachUri:'
+ serachUri);
let serchfetchOp = {
uri:serachUri.toString(),
selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs : [ type.toString()],
};
const result = await media.getFileAssets(serchfetchOp);
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 getFileAssets by uri:'
+ serachUri + ",result.getCount():" + result.getCount());
asset = await result.getFirstObject();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 asset.uri:'
+ asset.uri);
expect(asset.uri == serachUri).assertTrue();
fd = await asset.open('r');
expect(fd > 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 fd:' + fd);
asset.close(fd, async (error) => {
fd1 = await asset.open('r');
expect(fd1 > 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 fd1:'
+ fd1);
await asset.close(fd1);
done();
});
} catch (error) {
console.info(
`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_CALLBACK_005_35 error:${error}`);
expect(false).assertTrue();
done();
}
});
//======================== CLOSE BEGIN ================================
});
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import featureAbility from '@ohos.ability.featureAbility'
import fileio from '@ohos.fileio';
import {describe, it, expect} from 'deccjsunit/index';
export default function fileAssetUriTestPromiseTest(abilityContext){
describe('fileAssetUriTestPromiseTest', function() {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(abilityContext);
console.info('MediaLibraryTest : getMediaLibrary OUT');
const fileKeyObj = mediaLibrary.FileKey;
//======================== FILE BEGIN ==================================
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35
* @tc.name : close
* @tc.desc : asset close the type of video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35', 0, async function(done) {
let asset;
let fd;
let fd1;
try {
let type = mediaLibrary.MediaType.IMAGE;
let fetchOp = {
selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs : [ type.toString() ],
};
const fetchFileResult = await media.getFileAssets(fetchOp);
expect(fetchFileResult != undefined).assertTrue();
let firstObject = await fetchFileResult.getFirstObject();
const id = firstObject.id;
const uri = firstObject.uri;
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 uri:' + uri);
const serachUri = 'datashare:///media/image/' + id;
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 serachUri:'
+ serachUri);
let serchfetchOp = {
uri : serachUri.toString(),
selections : fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs : [ type.toString() ],
};
const result = await media.getFileAssets(serchfetchOp);
console.info(
'MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 getFileAssets by uri:'
+ serachUri + ",result.getCount():" + result.getCount());
asset = await result.getFirstObject();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 asset.uri:'
+ asset.uri);
expect(asset.uri == serachUri).assertTrue();
fd = await asset.open('r');
expect(fd > 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 fd:' + fd);
await asset.close(fd);
fd1 = await asset.open('r');
expect(fd1 > 0).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 fd1:' + fd1);
await asset.close(fd1);
done();
} catch (error) {
console.info(
`MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_OPENANDCLOSE_ASSET_URI_PROMISE_005_35 error:${error}`);
expect(false).assertTrue();
done();
}
});
//======================== CLOSE BEGIN ================================
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册