• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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 */
15import AbilityConstant from "@ohos.app.ability.AbilityConstant"
16import Ability from "@ohos.app.ability.UIAbility"
17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
18
19class AbilityTest extends Ability {
20    onSaveState(reason, wantParam) {
21        if (reason == AbilityConstant.StateType.APP_RECOVERY) {
22            wantParam["test3"] = 3;
23            return AbilityConstant.OnSaveResult.ALL_AGREE
24        }
25        return AbilityConstant.OnSaveResult.ALL_REJECT
26    }
27}
28
29export default function ActsAbilityConstantTest() {
30describe("ActsAbilityConstantTest", function () {
31    /**
32    * @tc.number: DFX_DFR_AbilityConstant_Interface_0100
33    * @tc.name: onSaveState接口测试
34    * @tc.desc: appRecovery interface test.
35    */
36    it("DFX_DFR_AbilityConstant_Interface_0100", 0, function () {
37        console.info("-------------------------DFX_DFR_AbilityConstant_Interface_0100 start-------------------------");
38        try{
39            let ability_test = new AbilityTest();
40            let StateType = AbilityConstant.StateType.APP_RECOVERY;
41            let wantParam = {"test1": 1, "test2": 2};
42            let ret = ability_test.onSaveState(StateType, wantParam);
43            if (wantParam["test3"] == 3) {
44                expect(true).assertTrue();
45            } else {
46                console.info("test3 not exist");
47                expect(false).assertTrue();
48            }
49            expect(ret).assertEqual(AbilityConstant.OnSaveResult.ALL_AGREE);
50        }catch(error){
51            console.info("DFX_DFR_AbilityConstant_Interface_0100 err = " + error);
52            expect(false).assertTrue();
53        }
54        console.info("DFX_DFR_AbilityConstant_Interface_0100 end");
55    })
56
57    /**
58    * @tc.number: DFX_DFR_AbilityConstant_Interface_0200
59    * @tc.name: 检验AbilityConstant属性返回值是否符合预期
60    * @tc.desc: appRecovery interface test.
61    */
62    it("DFX_DFR_AbilityConstant_Interface_0200", 0, function () {
63        console.info("-------------------------DFX_DFR_AbilityConstant_Interface_0200 start-------------------------");
64        try{
65            expect(AbilityConstant.LaunchReason.APP_RECOVERY).assertEqual(4);
66            expect(AbilityConstant.OnSaveResult.ALL_AGREE).assertEqual(0);
67            expect(AbilityConstant.OnSaveResult.CONTINUATION_REJECT).assertEqual(1);
68            expect(AbilityConstant.OnSaveResult.CONTINUATION_MISMATCH).assertEqual(2);
69            expect(AbilityConstant.OnSaveResult.RECOVERY_AGREE).assertEqual(3);
70            expect(AbilityConstant.OnSaveResult.RECOVERY_REJECT).assertEqual(4);
71        }catch(error){
72            console.info("DFX_DFR_AbilityConstant_Interface_0200 err = " + error);
73            expect(false).assertTrue();
74        }
75        console.info("DFX_DFR_AbilityConstant_Interface_0200 end");
76    })
77
78})
79}