diff --git a/multimedia/photoAccess/common.ts b/multimedia/photoAccess/common.ts index 4ca722e543a97c60328b536696b47936aaee8871..c67c863dbaec92ef9a32ad34bc2e717f3e5687ad 100644 --- a/multimedia/photoAccess/common.ts +++ b/multimedia/photoAccess/common.ts @@ -81,6 +81,8 @@ export function photoFetchOption(testNum, key, value) : photoAccessHelper.FetchO photoKeys.DATE_TRASHED, photoKeys.HIDDEN, photoKeys.CAMERA_SHOT_KEY, + photoKeys.USER_COMMENT, + 'all_exif', ], predicates: predicates }; diff --git a/multimedia/photoAccess/photoAccessSystem/Test.json b/multimedia/photoAccess/photoAccessSystem/Test.json index a950807b054fc9437ea080e42d98427bab86651e..b5135d0f466ce336d48aac1cb123b223365673df 100644 --- a/multimedia/photoAccess/photoAccessSystem/Test.json +++ b/multimedia/photoAccess/photoAccessSystem/Test.json @@ -39,6 +39,15 @@ "pre-push": [], "push": [ "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp/01.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/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.mp4 ->/storage/media/100/local/temp/01.mp4" ] }, @@ -126,6 +135,16 @@ "cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/addPro02.jpg", "cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/addPro04.jpg", "cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/removePro02.jpg", + + "mediatool send /storage/media/100/local/temp/userCommentCb01.jpg", + "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/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/getExif.jpg", "chmod -R 777 /storage/media/100/local/files/*", "hilog -p off", "hilog -Q pidoff", diff --git a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/List.test.ets b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/List.test.ets index 3939a58baff57e07e87cc4504f83d97dc88aff93..423d1de6c4f67e27696e8ab529b39f679a03c79c 100644 --- a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/List.test.ets +++ b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/List.test.ets @@ -20,11 +20,13 @@ import setCoverUriTest from './Album/setCoverUri' import createAlbumTest from './createAlbum' import createAssetTest from './createAsset' import deleteAlbumsTest from './deleteAlbums' +import getExifTest from './getExif' import openTest from './open' import publicApiTestWithSystemApiTest from './publicApiTestWithSystemApi' import setFavoriteTest from './setFavorite' import setHiddenTest from './setHidden' import trashAssetsTest from './deleteAssets' +import setUserCommentTest from './setUserComment' export default function testsuite () { deleteAssetsTest() @@ -34,9 +36,11 @@ export default function testsuite () { createAlbumTest() createAssetTest() deleteAlbumsTest() + getExifTest() openTest() publicApiTestWithSystemApiTest() setFavoriteTest() setHiddenTest() trashAssetsTest() + setUserCommentTest() } diff --git a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/getExif.ets b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/getExif.ets new file mode 100644 index 0000000000000000000000000000000000000000..0458db70eb5e587752a3acb82295d5da78e801a3 --- /dev/null +++ b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/getExif.ets @@ -0,0 +1,202 @@ +/* + * 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 { describe, beforeAll, it, expect } from 'deccjsunit/index' +import { + photoKeys, + photoFetchOption, + getFileAsset, + getPermission, + fetchOption +} from '../../../../../../common' + +export default function getExifTest () { + describe('getExifTest', function () { + beforeAll(async function () { + console.info('beforeAll case') + await getPermission() + }) + + const exifInfo = { + ImageWidth: '3456', + UserComment: 'gray', + } + + 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(); + 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); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + async function getExifAbnormalCallback (done, testNum, fetchOps) { + 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 { + expect(false).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(); + 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); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + async function getExifAbnormalPromise (done, testNum, fetchOps) { + try { + const asset = await getFileAsset(testNum, fetchOps); + await asset.getExif(); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + done(); + } + } + + /** + * @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.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'); + 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.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_callback_001', 2, async function (done) { + const testNum = 'getExif_callback_001'; + const fetchOps = fetchOption(testNum, photoKeys.DISPLAY_NAME, 'getExif.jpg'); + await getExifAbnormalCallback(done, testNum, fetchOps); + }); + + /** + * @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.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'); + await getExifAbnormalCallback(done, testNum, fetchOps); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0000 + * @tc.name : getExif_promise_000 + * @tc.desc : getExif.jpg, fetchColumn with all_exif, check ImageWidth、UserComment + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('getExif_promise_000', 0, async function (done) { + const testNum = 'getExif_promise_000'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'getExif.jpg'); + await getExifPromise(done, testNum, fetchOps); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_GET_EXIF_0100 + * @tc.name : getExif_promise_001 + * @tc.desc : getExif.jpg, fetchColumn without all_exif, check ImageWidth、UserComment + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('getExif_promise_001', 2, async function (done) { + const testNum = 'getExif_promise_001'; + const fetchOps = fetchOption(testNum, photoKeys.DISPLAY_NAME, 'getExif.jpg'); + await getExifAbnormalPromise(done, testNum, fetchOps); + }); + + /** + * @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.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'); + await getExifAbnormalPromise(done, testNum, fetchOps); + }); + }) +} diff --git a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/setUserComment.ets b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/setUserComment.ets new file mode 100644 index 0000000000000000000000000000000000000000..be5957b9b3f80920069398650fb7decfc3acf59c --- /dev/null +++ b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/setUserComment.ets @@ -0,0 +1,229 @@ +/* + * 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 { describe, beforeAll, it, expect } from 'deccjsunit/index' +import { + photoKeys, + photoFetchOption, + getFileAsset, + getPermission +} from '../../../../../../common' + +export default function setUserCommentTest () { + describe('setUserCommentTest', function () { + + beforeAll(async function () { + console.info('beforeAll case') + await getPermission() + }) + + async function setUserCommentCallback (done, testNum, fetchOps, userComment) { + 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 key = photoKeys.USER_COMMENT; + const curUserComment: string = newAsset.get(key).toString(); + console.info(`${testNum} curUserComment: ${curUserComment}`); + expect(curUserComment).assertEqual(userComment); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + async function setUserCommentAbnormalCallback (done, testNum, fetchOps, userComment) { + try { + const asset = await getFileAsset(testNum, fetchOps); + asset.setUserComment(userComment, async (err) => { + try { + if (err !== undefined) { + console.info(`${testNum} err: ${err}`); + } else { + expect(false).assertTrue(); + } + } catch (error) { + console.info(`${testNum} error: ${error}`); + } + done(); + }) + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + done(); + } + } + + async function setUserCommentPromise (done, testNum, fetchOps, userComment) { + try { + const asset = await getFileAsset(testNum, fetchOps); + await asset.setUserComment(userComment); + const newAsset = await getFileAsset(testNum, fetchOps); + const key = photoKeys.USER_COMMENT; + const curUserComment: string = newAsset.get(key).toString(); + console.info(`${testNum} curUserComment: ${curUserComment}`); + expect(curUserComment).assertEqual(userComment); + done() + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + expect(false).assertTrue(); + done(); + } + } + + async function setUserCommentAbnormalPromise (done, testNum, fetchOps, userComment) { + try { + const asset = await getFileAsset(testNum, fetchOps); + await asset.setUserComment(userComment); + expect(false).assertTrue(); + done(); + } catch (error) { + console.info(`${testNum} failed; error: ${error}`); + done(); + } + } + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_SET_USER_COMMENT_0000 + * @tc.name : setUserComment_callback_000 + * @tc.desc : userComment is string('setUserComment_callback_000') + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('setUserComment_callback_000', 0, async function (done) { + const testNum = 'setUserComment_callback_000'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb01.jpg'); + const userComment = testNum; + await setUserCommentCallback(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_SET_USER_COMMENT_0100 + * @tc.name : setUserComment_callback_001 + * @tc.desc : userComment is string('') + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_callback_001', 2, async function (done) { + const testNum = 'setUserComment_callback_001'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb02.jpg'); + const userComment = ''; + await setUserCommentCallback(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_SET_USER_COMMENT_0200 + * @tc.name : setUserComment_callback_002 + * @tc.desc : userComment is undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_callback_002', 2, async function (done) { + const testNum = 'setUserComment_callback_002'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb03.jpg'); + const userComment = undefined; + await setUserCommentAbnormalCallback(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_CALLBACK_SET_USER_COMMENT_0300 + * @tc.name : setUserComment_callback_003 + * @tc.desc : userComment is number(123) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_callback_003', 2, async function (done) { + const testNum = 'setUserComment_callback_003'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb04.jpg'); + const userComment = 123; + await setUserCommentAbnormalCallback(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_SET_USER_COMMENT_0000 + * @tc.name : setUserComment_promise_000 + * @tc.desc : userComment is string('setUserComment_promise_000') + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('setUserComment_promise_000', 0, async function (done) { + const testNum = 'setUserComment_promise_000'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentPro01.jpg'); + const userComment = testNum; + await setUserCommentPromise(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_SET_USER_COMMENT_0100 + * @tc.name : setUserComment_promise_001 + * @tc.desc : userComment is string('') + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_promise_001', 2, async function (done) { + const testNum = 'setUserComment_promise_001'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb02.jpg'); + const userComment = ''; + await setUserCommentPromise(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_SET_USER_COMMENT_0200 + * @tc.name : setUserComment_promise_002 + * @tc.desc : userComment is undefined + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_promise_002', 2, async function (done) { + const testNum = 'setUserComment_promise_002'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb03.jpg'); + const userComment = undefined; + await setUserCommentAbnormalPromise(done, testNum, fetchOps, userComment); + }); + + /** + * @tc.number : SUB_PHOTOACCESS_HELPER_PROMISE_SET_USER_COMMENT_0300 + * @tc.name : setUserComment_promise_003 + * @tc.desc : userComment is number(123) + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('setUserComment_promise_003', 2, async function (done) { + const testNum = 'setUserComment_promise_003'; + const fetchOps = photoFetchOption(testNum, photoKeys.DISPLAY_NAME, 'userCommentCb04.jpg'); + const userComment = 123; + await setUserCommentAbnormalPromise(done, testNum, fetchOps, userComment); + }); + }) +}