• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import photoAccessHelper from '@ohos.file.photoAccessHelper'
17import { describe, it, expect, beforeAll } from '@ohos/hypium'
18import common from '@ohos.app.ability.common';
19import { getPermission,driveFn,sleep } from '../common';
20
21export default function releaseTest () {
22  describe('releaseTest', () => {
23    let testContext: common.UIAbilityContext = AppStorage.get('testContext') as common.UIAbilityContext;
24    beforeAll(async () => {
25      console.info('beforeAll case');
26      await getPermission();
27      await driveFn();
28      await sleep(1000);
29    });
30    /**
31     * @tc.number    : SUB_PHOTOACCESS_HELPER_CALLBACK_RELEASE_0000
32     * @tc.name      : release_callback_000
33     * @tc.desc      : release photoAccessHelper instance
34     * @tc.size      : MEDIUM
35     * @tc.type      : Function
36     * @tc.level     : Level 0
37     */
38    it('release_callback_000', 0, async (done: Function) => {
39      const testNum = 'release_callback_000'
40      try {
41        let helper = photoAccessHelper.getPhotoAccessHelper(testContext)
42        await helper.release((err) => {
43          if (err !== undefined) {
44            console.info(`${testNum} err: ${err}`);
45            expect(false).assertTrue();
46          }
47          done();
48        })
49      } catch (error) {
50        console.error(`${testNum} failed; error: ${error}`);
51        expect(false).assertTrue()
52        done();
53      }
54    })
55
56    /**
57     * @tc.number    : SUB_PHOTOACCESS_HELPER_PROMISE_RELEASE_0000
58     * @tc.name      : release_promise_000
59     * @tc.desc      : release photoAccessHelper instance
60     * @tc.size      : MEDIUM
61     * @tc.type      : Function
62     * @tc.level     : Level 0
63     */
64    it('release_promise_000', 0, async (done: Function) => {
65      const testNum = 'release_promise_000'
66      try {
67        let helper = photoAccessHelper.getPhotoAccessHelper(testContext)
68        await helper.release()
69        done();
70      } catch (error) {
71        console.error(`${testNum} failed; error: ${error}`);
72        expect(false).assertTrue()
73        done();
74      }
75    })
76  })
77}
78