diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn index dbda217a959b36b7d0ede89c2c6786b194fad4b6..33cefb0fad1655f4570d17dca763b805b55a5ea0 100644 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -75,6 +75,7 @@ group("multimedia") { "medialibrary/mediaLibrary_mediafetchoptions:mediaLibrary_mediafetchoptions_hap", "medialibrary/mediaLibrary_trash:mediaLibrary_trash_js_hap", "photoAccess/photoAccess:photoAccess_js_hap", + "photoAccess/photoAccessNoLocation:photoAccess_nolocation_js_hap", "photoAccess/photoAccessSystem:photoAccess_system_js_hap", ] } else { diff --git a/multimedia/photoAccess/photoAccess/Test.json b/multimedia/photoAccess/photoAccess/Test.json index 459f7e74f53b89843baaa6073a417d6346314ee5..93da47d90fce511f8b4192801e913bb8b6fa491f 100644 --- a/multimedia/photoAccess/photoAccess/Test.json +++ b/multimedia/photoAccess/photoAccess/Test.json @@ -135,10 +135,26 @@ "hilog -Q domainoff", "hilog -b D -D 0xD002B70", "scanner", - "sleep 5" + "sleep 10" ], "teardown-command": [ - "power-shell setmode 600" + "power-shell setmode 600", + "rm -rf /storage/media/100/local/files/Audios/*", + "rm -rf /storage/media/100/local/files/Audios/.*", + "rm -rf /storage/media/100/local/files/Camera/*", + "rm -rf /storage/media/100/local/files/Camera/.*", + "rm -rf /storage/media/100/local/files/Documents/*", + "rm -rf /storage/media/100/local/files/Documents/.*", + "rm -rf /storage/media/100/local/files/Download/*", + "rm -rf /storage/media/100/local/files/Download/.*", + "rm -rf /storage/media/100/local/files/Pictures/*", + "rm -rf /storage/media/100/local/files/Pictures/.*", + "rm -rf /storage/media/100/local/files/Videos/*", + "rm -rf /storage/media/100/local/files/Videos/.*", + "sleep 5", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "kill -9 `pidof com.ohos.medialibrary.medialibrarydata`", + "scanner" ] }, { diff --git a/multimedia/photoAccess/photoAccessNoLocation/AppScope/app.json b/multimedia/photoAccess/photoAccessNoLocation/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..893423d976645372c2f74a24ef3e018b1a73d053 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "ohos.acts.multimedia.photoaccess", + "vendor": "huawei", + "versionCode": 1000000, + "versionName": "1.0.0", + "debug": false, + "icon": "$media:icon", + "label": "$string:app_name", + "description": "$string:description_application", + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/AppScope/resources/base/element/string.json b/multimedia/photoAccess/photoAccessNoLocation/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee69f9a861d9dc269ed6638735d52674583498e1 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"ohosProject" + } + ] +} \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/AppScope/resources/base/media/app_icon.png b/multimedia/photoAccess/photoAccessNoLocation/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/photoAccess/photoAccessNoLocation/AppScope/resources/base/media/app_icon.png differ diff --git a/multimedia/photoAccess/photoAccessNoLocation/BUILD.gn b/multimedia/photoAccess/photoAccessNoLocation/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ea63d28381969d732128da7b55ddd55ae377807f --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("photoAccess_nolocation_js_hap") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":photoAccessNoLocation_js_assets", + ":photoAccessNoLocation_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsPhotoAccessNoLocationTest" + part_name = "media_library" + subsystem_name = "multimedia" +} + +ohos_app_scope("photoAccessNoLocation_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("photoAccessNoLocation_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("photoAccessNoLocation_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":photoAccessNoLocation_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/multimedia/photoAccess/photoAccessNoLocation/Test.json b/multimedia/photoAccess/photoAccessNoLocation/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..3a4efd8215018aecc5eac9f2c85c9cb2878ad153 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/Test.json @@ -0,0 +1,84 @@ +{ + "description": "Configuration for photoAccess Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "ohos.acts.multimedia.photoaccess", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 10000 + }, + "kits": [ + { + "type": "ShellKit", + "pre-push": [], + "run-command": [ + "rm -rf /storage/media/100/local/files/Audios/*", + "rm -rf /storage/media/100/local/files/Audios/.*", + "rm -rf /storage/media/100/local/files/Camera/*", + "rm -rf /storage/media/100/local/files/Camera/.*", + "rm -rf /storage/media/100/local/files/Documents/*", + "rm -rf /storage/media/100/local/files/Documents/.*", + "rm -rf /storage/media/100/local/files/Download/*", + "rm -rf /storage/media/100/local/files/Download/.*", + "rm -rf /storage/media/100/local/files/Pictures/*", + "rm -rf /storage/media/100/local/files/Pictures/.*", + "rm -rf /storage/media/100/local/files/Videos/*", + "rm -rf /storage/media/100/local/files/Videos/.*", + "sleep 5", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "kill -9 `pidof com.ohos.medialibrary.medialibrarydata`", + "scanner", + "sleep 5", + "mkdir /storage/media/100/local/temp", + "param set persist.ace.testmode.enabled 1" + ] + }, + { + "type": "PushKit", + "pre-push": [], + "push": [ + "./resource/medialibrary/getExif.jpg ->/storage/media/100/local/temp/getExif.jpg" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "mediatool send /storage/media/100/local/temp/getExif.jpg", + "chmod -R 777 /storage/media/100/local/files/*", + "hilog -p off", + "hilog -Q pidoff", + "hilog -Q domainoff", + "hilog -b D -D 0xD002B70", + "scanner", + "sleep 10" + ], + "teardown-command": [ + "power-shell setmode 600", + "rm -rf /storage/media/100/local/files/Audios/*", + "rm -rf /storage/media/100/local/files/Audios/.*", + "rm -rf /storage/media/100/local/files/Camera/*", + "rm -rf /storage/media/100/local/files/Camera/.*", + "rm -rf /storage/media/100/local/files/Documents/*", + "rm -rf /storage/media/100/local/files/Documents/.*", + "rm -rf /storage/media/100/local/files/Download/*", + "rm -rf /storage/media/100/local/files/Download/.*", + "rm -rf /storage/media/100/local/files/Pictures/*", + "rm -rf /storage/media/100/local/files/Pictures/.*", + "rm -rf /storage/media/100/local/files/Videos/*", + "rm -rf /storage/media/100/local/files/Videos/.*", + "sleep 5", + "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", + "kill -9 `pidof com.ohos.medialibrary.medialibrarydata`", + "scanner" + ] + }, + { + "test-file-name": [ + "ActsPhotoAccessNoLocationTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/Application/AbilityStage.ts b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..40e534cde0a2135620a01a7efe63262c703a96e7 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.app.ability.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() : void { + console.log("[Demo] MyAbilityStage onCreate"); + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/MainAbility/MainAbility.ts b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..31f9a4a3efce909a243c7706b2507365e0ee9e83 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,36 @@ +import Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) : void { + // Ability is creating, initialize resources for this ability + console.log('[Demo] MainAbility onCreate'); + globalThis.abilityWant = want; + } + + onDestroy() : void { + // Ability is destroying, release resources for this ability + console.log('[Demo] MainAbility onDestroy'); + } + + onWindowStageCreate(windowStage) : void { + console.log('[Demo] MainAbility onWindowStageCreate windowStage=' + windowStage); + globalThis.windowStage = windowStage; + globalThis.abilityContext = this.context; + windowStage.setUIContent(this.context, 'MainAbility/pages/index/index', null); + } + + onWindowStageDestroy() : void { + //Main window is destroyed, release UI related resources + console.log('[Demo] MainAbility onWindowStageDestroy'); + } + + onForeground() : void { + // Ability has brought to foreground + console.log('[Demo] MainAbility onForeground'); + } + + onBackground() : void { + // Ability has back to background + console.log('[Demo] MainAbility onBackground'); + } +}; \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/MainAbility/pages/index/index.ets b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/MainAbility/pages/index/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..61adec753ccbe22dadb12d30745894f82df7c8a4 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@ohos.router'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../../test/List.test' + + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + 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 diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestAbility/TestAbility.ts b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..e30683035686e87ac541b6f5ca1bf61167146537 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.app.ability.UIAbility' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) : void { + console.log('TestAbility onCreate'); + } + + onDestroy() : void { + console.log('TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage) : void { + console.log('TestAbility onWindowStageCreate'); + windowStage.loadContent('TestAbility/pages/index', (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + }; + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() : void { + console.log('TestAbility onWindowStageDestroy'); + } + + onForeground() : void { + console.log('TestAbility onForeground'); + } + + onBackground() : void { + console.log('TestAbility onBackground'); + } +}; \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestAbility/pages/index.ets b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1cf6eda5d963e40bc2e277218b30397f3ad43b09 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..b3ef899eef3f908584a59d5e7d19424e539282c0 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) : string { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]); + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}`; + } + } + return targetParams.trim(); +} + +async function onAbilityCreateCallback() : Promise { + console.log('onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err) : Promise { + console.info('addAbilityMonitorCallback : ' + JSON.stringify(err)); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() {}; + + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run'); + let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); + let cmd = 'aa start -d 0 -a com.example.myapplication.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters); + const debug = abilityDelegatorArguments.parameters['-D']; + if (debug === 'true') + { + cmd += ' -D'; + } + console.info('cmd : ' + cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }); + console.info('OpenHarmonyTestRunner onRun end'); + } +}; \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/test/List.test.ets b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..433ab58a348a4302035ee3c3029156869424fdbe --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import getExifNoLocationTest from './getExifNoLocation' + +export default function testsuite () { + getExifNoLocationTest() +} diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/test/getExifNoLocation.ets b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/test/getExifNoLocation.ets new file mode 100644 index 0000000000000000000000000000000000000000..2b7d4f0143a277cbdd44f182694948b9be130b08 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/ets/test/getExifNoLocation.ets @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundleManager from '@ohos.bundle.bundleManager'; +import { describe, beforeAll, it, expect } from 'deccjsunit/index' +import { + photoKeys, + photoFetchOption, + getFileAsset, +} from '../../../../../../common' + +export default function getExifNoLocationTest () { + describe('getExifNoLocationTest', function () { + beforeAll(async function () { + console.info('beforeAll case') + const atManager = abilityAccessCtrl.createAtManager(); + const appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; + const userId = 100; + const appInfo = await bundleManager.getApplicationInfo('ohos.acts.multimedia.photoaccess', appFlags, userId); + const tokenID = appInfo.accessTokenId; + try { + await atManager.grantUserGrantedPermission(tokenID, 'ohos.permission.READ_IMAGEVIDEO', 1); + } catch (error) { + console.info(`getPermission failed`); + } + }) + + async function getExifCallback (done, testNum, fetchOps) { + try { + const asset = await getFileAsset(testNum, fetchOps); + asset.getExif(async (err, result) => { + try { + if (err !== undefined) { + console.info(`${testNum} err: ${err}`); + expect(false).assertTrue(); + } else { + console.info(`${testNum} result: ${result}`) + expect(result.length > 0).assertTrue(); + expect(!result.includes('GPSLongitude')).assertTrue(); + expect(!result.includes('GPSLatitudeRef')).assertTrue(); + expect(!result.includes('GPSLongitudeRef')).assertTrue(); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + async function getExifPromise (done, testNum, fetchOps) { + try { + const asset = await getFileAsset(testNum, fetchOps); + const result = await asset.getExif(); + console.info(`${testNum} result: ${result}`) + expect(result.length > 0).assertTrue(); + expect(!result.includes('GPSLongitude')).assertTrue(); + expect(!result.includes('GPSLatitudeRef')).assertTrue(); + expect(!result.includes('GPSLongitudeRef')).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_NOLOCATION_0400 + * @tc.name : getExif_callback_004 + * @tc.desc : getExif.jpg, fetchColumn with all_exif, no MEDIA_LOCATION permission, check GPSLongitude + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('getExif_callback_004', 0, async function (done) { + const testNum = 'getExif_callback_004'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'getExif.jpg'); + await getExifCallback(done, testNum, fetchOps); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_NOLOCATION_0400 + * @tc.name : getExif_promise_004 + * @tc.desc : getExif.jpg, fetchColumn with all_exif, no MEDIA_LOCATION permission, check GPSLongitude + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('getExif_promise_004', 0, async function (done) { + const testNum = 'getExif_promise_004'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'getExif.jpg'); + await getExifPromise(done, testNum, fetchOps); + }); + }) +} diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/module.json b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..ee09d7dfcc1674b0bdf5322843d5dd90cf9d3d23 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/module.json @@ -0,0 +1,59 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:phone_entry_dsc", + "mainElement": "MainAbility", + "deviceTypes": [ + "tablet", + "default", + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "com.example.myapplication.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "visible": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.READ_IMAGEVIDEO" + }, + { + "name": "ohos.permission.WRITE_IMAGEVIDEO" + } + ] + } +} \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/element/string.json b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9d9daf0a55c0ba44e572b668ea9fe267fd3b1902 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsPhotoAccessNoLocationTest" + }, + { + "name": "form_description", + "value": "photoAccessSystem" + }, + { + "name": "serviceability_description", + "value": "photoAccessSystem" + }, + { + "name": "description_application", + "value": "photoAccessSystem test" + }, + { + "name": "app_name", + "value": "ActsPhotoAccessNoLocationTest" + } + ] +} \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/media/icon.png b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/profile/main_pages.json b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..ceb075cd80946aade673d707aac904fb8998bce9 --- /dev/null +++ b/multimedia/photoAccess/photoAccessNoLocation/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/index/index" + ] +} \ No newline at end of file diff --git a/multimedia/photoAccess/photoAccessNoLocation/signature/openharmony_sx.p7b b/multimedia/photoAccess/photoAccessNoLocation/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..7d5afa18405e1eae7290bb2d7a30451de2eca81a Binary files /dev/null and b/multimedia/photoAccess/photoAccessNoLocation/signature/openharmony_sx.p7b differ diff --git a/multimedia/photoAccess/photoAccessSystem/Test.json b/multimedia/photoAccess/photoAccessSystem/Test.json index 25d8eba7530214546a6a6bd4711e1b6119e10413..99add5a9d655c0d4988a1d8ed77fe4bf44b9a528 100644 --- a/multimedia/photoAccess/photoAccessSystem/Test.json +++ b/multimedia/photoAccess/photoAccessSystem/Test.json @@ -39,15 +39,20 @@ "pre-push": [], "push": [ "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/01.jpg", + "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/noExif.jpg", "./resource/medialibrary/getExif.jpg ->/storage/media/100/local/temp/getExif.jpg", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentCb01.jpg", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentCb02.jpg", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentCb03.jpg", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentCb04.jpg", + "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentCb05.jpg", + "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentCb06.jpg", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentPro01.jpg", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentPro02.jpg", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentPro03.jpg", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentPro04.jpg", + "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentPro05.jpg", + "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/userCommentPro06.jpg", "./resource/medialibrary/01.mp4 ->/storage/media/100/local/temp/01.mp4" ] }, @@ -140,11 +145,16 @@ "mediatool send /storage/media/100/local/temp/userCommentCb02.jpg", "mediatool send /storage/media/100/local/temp/userCommentCb03.jpg", "mediatool send /storage/media/100/local/temp/userCommentCb04.jpg", + "mediatool send /storage/media/100/local/temp/userCommentCb05.jpg", + "mediatool send /storage/media/100/local/temp/userCommentCb06.jpg", "mediatool send /storage/media/100/local/temp/userCommentPro01.jpg", "mediatool send /storage/media/100/local/temp/userCommentPro02.jpg", "mediatool send /storage/media/100/local/temp/userCommentPro03.jpg", "mediatool send /storage/media/100/local/temp/userCommentPro04.jpg", + "mediatool send /storage/media/100/local/temp/userCommentPro05.jpg", + "mediatool send /storage/media/100/local/temp/userCommentPro06.jpg", "mediatool send /storage/media/100/local/temp/getExif.jpg", + "mediatool send /storage/media/100/local/temp/noExif.jpg", "cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/getPhotoIndex01.jpg", "cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/getPhotoIndex02.jpg", @@ -173,7 +183,7 @@ "hilog -Q domainoff", "hilog -b D -D 0xD002B70", "scanner", - "sleep 5" + "sleep 10" ], "teardown-command": [ "power-shell setmode 600", diff --git a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/getExif.ets b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/getExif.ets index 0458db70eb5e587752a3acb82295d5da78e801a3..f277acd01f17bfaafecd1bea5a864a071afbd523 100644 --- a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/getExif.ets +++ b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/getExif.ets @@ -13,13 +13,15 @@ * limitations under the License. */ +import photoAccessHelper from '@ohos.file.photoAccessHelper'; +import dataSharePredicates from '@ohos.data.dataSharePredicates'; import { describe, beforeAll, it, expect } from 'deccjsunit/index' import { photoKeys, photoFetchOption, getFileAsset, getPermission, - fetchOption + fetchOption, } from '../../../../../../common' export default function getExifTest () { @@ -29,10 +31,41 @@ export default function getExifTest () { await getPermission() }) - const exifInfo = { - ImageWidth: '3456', - UserComment: 'gray', - } + const exifInfo = new Map([ + ['ApertureValue', '1.69 EV (f/1.8)'], + ['BitsPerSample', '8, 8, 8'], + ['DateTimeOriginal', '2019:11:15 20:48:30'], + ['DateTime', '2019:11:15 20:48:30'], + ['ExposureBiasValue', '0.00 EV'], + ['ExposureTime', '1/33 sec.'], + ['Flash', 'Flash fired, auto mode'], + ['FNumber', 'f/1.8'], + ['FocalLength', '4.0 mm'], + ['FocalLengthIn35mmFilm', '26'], + ['GPSLongitude', '0'], + ['GPSLatitudeRef', ''], + ['GPSLongitudeRef', ''], + ['GPSTimeStamp', '13:31:27.00'], + ['GPSDateStamp', '2023:04:13'], + ['ImageDescription', 'A gray picture'], + ['ImageLength', '4608'], + ['ImageWidth', '3456'], + ['ISOSpeedRatings', '200'], + ['LightSource', 'Daylight'], + ['Make', 'HW'], + ['MakerNote', ''], + ['MeteringMode', 'Pattern'], + ['Model', 'STK-LX1'], + ['Orientation', '0'], + ['PhotoMode', ''], + ['PixelXDimension', '3456'], + ['PixelYDimension', '4608'], + ['RecommendedExposureIndex', '200'], + ['SceneType', 'Directly photographed'], + ['SensitivityType', 'Standard output sensitivity (SOS)'], + ['StandardOutputSensitivity', ''], + ['WhiteBalance', 'Auto white balance'], + ]) async function getExifCallback (done, testNum, fetchOps) { try { @@ -46,9 +79,10 @@ export default function getExifTest () { console.info(`${testNum} result: ${result}`) expect(result.length > 0).assertTrue(); const msg = JSON.parse(result); - console.info(`${testNum} ImageWidth: ${msg.ImageWidth}, UserComment: ${msg.UserComment}`) - expect(msg.ImageWidth).assertEqual(exifInfo.ImageWidth); - expect(msg.UserComment).assertEqual(exifInfo.UserComment); + exifInfo.forEach((value, key, map) => { + console.info(`${testNum} key: ${key}, value: ${value}, msg[key]: ${msg[key]}`) + expect(value).assertEqual(msg[key].toString()) + }); } } catch (error) { console.info(`${testNum} error: ${error}`); @@ -66,11 +100,11 @@ export default function getExifTest () { try { const asset = await getFileAsset(testNum, fetchOps); asset.getExif(async (err, result) => { - console.info(`${testNum} err: ${err}, result: ${result}`); try { if (err !== undefined) { console.info(`${testNum} err: ${err}`); } else { + console.info(`${testNum} result: ${result}`); expect(false).assertTrue(); } } catch (error) { @@ -92,9 +126,10 @@ export default function getExifTest () { console.info(`${testNum} result: ${result}`) expect(result.length > 0).assertTrue(); const msg = JSON.parse(result); - console.info(`${testNum} ImageWidth: ${msg.ImageWidth}, UserComment: ${msg.UserComment}`) - expect(msg.ImageWidth).assertEqual(exifInfo.ImageWidth); - expect(msg.UserComment).assertEqual(exifInfo.UserComment); + exifInfo.forEach((value, key, map) => { + console.info(`${testNum} key: ${key}, value: ${value}, msg[key]: ${msg[key]}`) + expect(value).assertEqual(msg[key].toString()) + }); done(); } catch (error) { console.info(`${testNum} failed; error: ${error}`); @@ -118,21 +153,25 @@ export default function getExifTest () { /** * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_0000 * @tc.name : getExif_callback_000 - * @tc.desc : getExif.jpg, fetchColumn with all_exif, check ImageWidth、UserComment + * @tc.desc : getExif.jpg, fetchColumn with all_exif, check exif * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 */ it('getExif_callback_000', 0, async function (done) { const testNum = 'getExif_callback_000'; - const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'getExif.jpg'); + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif'], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'getExif.jpg'), + }; await getExifCallback(done, testNum, fetchOps); }); /** * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_0100 * @tc.name : getExif_callback_001 - * @tc.desc : getExif.jpg, fetchColumn without all_exif, check ImageWidth、UserComment + * @tc.desc : getExif.jpg, fetchColumn without all_exif, check exif * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 2 @@ -144,19 +183,187 @@ export default function getExifTest () { }); /** - * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_0200 - * @tc.name : getExif_callback_002 - * @tc.desc : 01.jpg, fetchColumn with all_exif, check ImageWidth、UserComment + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_0300 + * @tc.name : getExif_callback_003 + * @tc.desc : noExif.jpg, fetchColumn with all_exif and user_comment, check UserComment + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_callback_003', 2, async function (done) { + const testNum = 'getExif_callback_003'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif', photoKeys.USER_COMMENT], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'getExif.jpg'), + }; + try { + const asset = await getFileAsset(testNum, fetchOps); + asset.getExif(async (err, result) => { + try { + if (err !== undefined) { + console.info(`${testNum} err: ${err}`); + expect(false).assertTrue(); + } else { + console.info(`${testNum} result: ${result}`) + expect(result.includes('UserComment')).assertTrue(); + const msg = JSON.parse(result); + expect(msg.UserComment).assertEqual('gray'); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_0500 + * @tc.name : getExif_callback_005 + * @tc.desc : getExif.jpg, fetchColumn with all_exif, has MEDIA_LOCATION permission, check GPSLongitude + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_callback_005', 2, async function (done) { + const testNum = 'getExif_callback_005'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif'], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'getExif.jpg'), + }; + try { + const asset = await getFileAsset(testNum, fetchOps); + asset.getExif(async (err, result) => { + try { + if (err !== undefined) { + console.info(`${testNum} err: ${err}`); + expect(false).assertTrue(); + } else { + console.info(`${testNum} result: ${result}`) + expect(result.includes('GPSLongitude')).assertTrue(); + expect(result.includes('GPSLatitudeRef')).assertTrue(); + expect(result.includes('GPSLongitudeRef')).assertTrue(); + const msg = JSON.parse(result); + expect(msg.GPSLongitude).assertEqual(0); + expect(msg.GPSLatitudeRef).assertEqual(''); + expect(msg.GPSLongitudeRef).assertEqual(''); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_0600 + * @tc.name : getExif_callback_006 + * @tc.desc : noExif.jpg, fetchColumn with all_exif, check ImageWidth + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_callback_006', 2, async function (done) { + const testNum = 'getExif_callback_006'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif'], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'noExif.jpg'), + }; + try { + const asset = await getFileAsset(testNum, fetchOps); + asset.getExif(async (err, result) => { + try { + if (err !== undefined) { + console.info(`${testNum} err: ${err}`); + expect(false).assertTrue(); + } else { + console.info(`${testNum} result: ${result}`); + expect(result.includes('ImageWidth')).assertTrue(); + const msg = JSON.parse(result); + expect(msg.ImageWidth).assertEqual(''); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_0700 + * @tc.name : getExif_callback_007 + * @tc.desc : noExif.jpg, fetchColumn withoutout all_exif, check ImageWidth * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 2 */ - it('getExif_callback_002', 2, async function (done) { - const testNum = 'getExif_callback_002'; - const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, '01.jpg'); + it('getExif_callback_007', 2, async function (done) { + const testNum = 'getExif_callback_007'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: [], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'noExif.jpg'), + }; await getExifAbnormalCallback(done, testNum, fetchOps); }); + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_GET_EXIF_0900 + * @tc.name : getExif_callback_009 + * @tc.desc : noExif.jpg, fetchColumn with all_exif and USER_COMMENT, check UserComment + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_callback_009', 2, async function (done) { + const testNum = 'getExif_callback_009'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif', photoKeys.USER_COMMENT], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'noExif.jpg'), + }; + try { + const asset = await getFileAsset(testNum, fetchOps); + asset.getExif(async (err, result) => { + try { + if (err !== undefined) { + console.info(`${testNum} err: ${err}`); + expect(false).assertTrue(); + } else { + console.info(`${testNum} result: ${result}`) + expect(result.includes('UserComment')).assertTrue(); + const msg = JSON.parse(result); + expect(msg.UserComment).assertEqual(''); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + /** * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0000 * @tc.name : getExif_promise_000 @@ -186,17 +393,145 @@ export default function getExifTest () { }); /** - * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0200 - * @tc.name : getExif_promise_002 - * @tc.desc : 01.jpg, fetchColumn with all_exif, check ImageWidth、UserComment + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0300 + * @tc.name : getExif_promise_003 + * @tc.desc : noExif.jpg, fetchColumn with all_exif and user_comment, check UserComment + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_promise_003', 2, async function (done) { + const testNum = 'getExif_promise_003'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif', photoKeys.USER_COMMENT], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'getExif.jpg'), + }; + try { + const asset = await getFileAsset(testNum, fetchOps); + const result = await asset.getExif(); + console.info(`${testNum} result: ${result}`); + expect(result.includes('UserComment')).assertTrue(); + const msg = JSON.parse(result); + expect(msg.UserComment).assertEqual('gray'); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0500 + * @tc.name : getExif_promise_005 + * @tc.desc : getExif.jpg, fetchColumn with all_exif, has MEDIA_LOCATION permission, check GPSLongitude + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_promise_005', 2, async function (done) { + const testNum = 'getExif_promise_005'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif'], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'getExif.jpg'), + }; + try { + const asset = await getFileAsset(testNum, fetchOps); + const result = await asset.getExif(); + console.info(`${testNum} result: ${result}`); + expect(result.includes('GPSLongitude')).assertTrue(); + expect(result.includes('GPSLatitudeRef')).assertTrue(); + expect(result.includes('GPSLongitudeRef')).assertTrue(); + const msg = JSON.parse(result); + expect(msg.GPSLongitude).assertEqual(0); + expect(msg.GPSLatitudeRef).assertEqual(''); + expect(msg.GPSLongitudeRef).assertEqual(''); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0600 + * @tc.name : getExif_promise_006 + * @tc.desc : noExif.jpg, fetchColumn with all_exif, check ImageWidth + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_promise_006', 2, async function (done) { + const testNum = 'getExif_promise_006'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif'], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'noExif.jpg'), + }; + try { + const asset = await getFileAsset(testNum, fetchOps); + const result = await asset.getExif(); + console.info(`${testNum} result: ${result}`); + expect(result.includes('ImageWidth')).assertTrue(); + const msg = JSON.parse(result); + expect(msg.ImageWidth).assertEqual(''); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0700 + * @tc.name : getExif_promise_007 + * @tc.desc : noExif.jpg, fetchColumn withoutout all_exif, check ImageWidth * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 2 */ - it('getExif_promise_002', 2, async function (done) { - const testNum = 'getExif_promise_002'; - const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, '01.jpg'); + it('getExif_promise_007', 2, async function (done) { + const testNum = 'getExif_promise_007'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: [], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'noExif.jpg'), + }; await getExifAbnormalPromise(done, testNum, fetchOps); }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0900 + * @tc.name : getExif_promise_009 + * @tc.desc : noExif.jpg, fetchColumn with all_exif and USER_COMMENT, check UserComment + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_promise_009', 2, async function (done) { + const testNum = 'getExif_promise_009'; + const predicates = new dataSharePredicates.DataSharePredicates(); + const fetchOps : photoAccessHelper.FetchOptions = { + fetchColumns: ['all_exif', photoKeys.USER_COMMENT], + predicates: predicates.equalTo(photoKeys.DISPLAY_NAME, 'noExif.jpg'), + }; + try { + const asset = await getFileAsset(testNum, fetchOps); + const result = await asset.getExif(); + console.info(`${testNum} result: ${result}`) + expect(result.includes('UserComment')).assertTrue(); + const msg = JSON.parse(result); + expect(msg.UserComment).assertEqual(''); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); }) } diff --git a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/setUserComment.ets b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/setUserComment.ets index be5957b9b3f80920069398650fb7decfc3acf59c..8174ec7fbe5bc52c7db94ee8085b1d8cd4563ce2 100644 --- a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/setUserComment.ets +++ b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/setUserComment.ets @@ -18,7 +18,7 @@ import { photoKeys, photoFetchOption, getFileAsset, - getPermission + getPermission, } from '../../../../../../common' export default function setUserCommentTest () { @@ -109,7 +109,7 @@ export default function setUserCommentTest () { /** * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_SET_USER_COMMENT_0000 * @tc.name : setUserComment_callback_000 - * @tc.desc : userComment is string('setUserComment_callback_000') + * @tc.desc : userComment is string('setUserComment_callback_000'), query by get * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 @@ -166,10 +166,66 @@ export default function setUserCommentTest () { await setUserCommentAbnormalCallback(done, testNum, fetchOps, userComment); }); + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_SET_USER_COMMENT_0400 + * @tc.name : setUserComment_callback_004 + * @tc.desc : userComment is string('aaa...aaa'(141)) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_callback_004', 2, async function (done) { + const testNum = 'setUserComment_callback_004'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb05.jpg'); + let userComment = ''; + for (let i = 0; i < 141; i++) { + userComment += 'a'; + } + await setUserCommentAbnormalCallback(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_SET_USER_COMMENT_0500 + * @tc.name : setUserComment_callback_005 + * @tc.desc : userComment is string('setUserComment_callback_005'), query by getExif + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_callback_005', 2, async function (done) { + const testNum = 'setUserComment_callback_005'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb06.jpg'); + const userComment = testNum; + try { + const asset = await getFileAsset(testNum, fetchOps); + asset.setUserComment(userComment, async (err) => { + try { + if (err !== undefined) { + console.info(`${testNum} err: ${err}`); + expect(false).assertTrue(); + } else { + const newAsset = await getFileAsset(testNum, fetchOps); + const result = await newAsset.getExif(); + const msg = JSON.parse(result); + console.info(`${testNum} curUserComment: ${msg.UserComment}`); + expect(msg.UserComment).assertEqual(userComment); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); + /** * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_SET_USER_COMMENT_0000 * @tc.name : setUserComment_promise_000 - * @tc.desc : userComment is string('setUserComment_promise_000') + * @tc.desc : userComment is string('setUserComment_promise_000'), query by get * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 0 @@ -191,7 +247,7 @@ export default function setUserCommentTest () { */ it('setUserComment_promise_001', 2, async function (done) { const testNum = 'setUserComment_promise_001'; - const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb02.jpg'); + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentPro02.jpg'); const userComment = ''; await setUserCommentPromise(done, testNum, fetchOps, userComment); }); @@ -206,7 +262,7 @@ export default function setUserCommentTest () { */ it('setUserComment_promise_002', 2, async function (done) { const testNum = 'setUserComment_promise_002'; - const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb03.jpg'); + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentPro03.jpg'); const userComment = undefined; await setUserCommentAbnormalPromise(done, testNum, fetchOps, userComment); }); @@ -221,9 +277,55 @@ export default function setUserCommentTest () { */ it('setUserComment_promise_003', 2, async function (done) { const testNum = 'setUserComment_promise_003'; - const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb04.jpg'); + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentPro04.jpg'); const userComment = 123; await setUserCommentAbnormalPromise(done, testNum, fetchOps, userComment); }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_SET_USER_COMMENT_0400 + * @tc.name : setUserComment_promise_004 + * @tc.desc : userComment is string('bbb...bbb'(141)) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_promise_004', 2, async function (done) { + const testNum = 'setUserComment_promise_004'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentPro05.jpg'); + let userComment = ''; + for (let i = 0; i < 141; i++) { + userComment += 'b'; + } + await setUserCommentAbnormalPromise(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_SET_USER_COMMENT_0500 + * @tc.name : setUserComment_promise_005 + * @tc.desc : userComment is string('setUserComment_promise_005'), query by getExif + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_promise_005', 2, async function (done) { + const testNum = 'setUserComment_promise_005'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentPro06.jpg'); + const userComment = testNum; + try { + const asset = await getFileAsset(testNum, fetchOps); + await asset.setUserComment(userComment); + const newAsset = await getFileAsset(testNum, fetchOps); + const result = await newAsset.getExif(); + const msg = JSON.parse(result); + console.info(`${testNum} curUserComment: ${msg.UserComment}`); + expect(msg.UserComment).assertEqual(userComment); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + }); }) }