1 /*
2  * Copyright (c) 2021-2023 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 
16 #ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_LIFECYCLE_CALLBACK_H
17 #define MOCK_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_LIFECYCLE_CALLBACK_H
18 
19 #include "want.h"
20 #include "ability_lifecycle_callbacks.h"
21 #include <gtest/gtest.h>
22 namespace OHOS {
23 namespace AppExecFwk {
24 using Want = OHOS::AAFwk::Want;
25 
26 class MockAbilityLifecycleCallbacks : public AbilityLifecycleCallbacks {
27 public:
28     MockAbilityLifecycleCallbacks() = default;
29     virtual ~MockAbilityLifecycleCallbacks() = default;
30 
31     /**
32      *
33      * Will be called when the given ability calls Ability->onStart
34      *
35      * @param Ability Indicates the ability object that calls the onStart() method.
36      */
OnAbilityStart(const std::shared_ptr<AbilityRuntime::UIAbility> & ability)37     virtual void OnAbilityStart(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
38     {
39         GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityStart called";
40     }
41 
42     /**
43      *
44      * Will be called when the given ability calls Ability->onInactive
45      *
46      * @param Ability Indicates the Ability object that calls the onInactive() method.
47      */
OnAbilityInactive(const std::shared_ptr<AbilityRuntime::UIAbility> & ability)48     virtual void OnAbilityInactive(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
49     {
50         GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityInactive called";
51     }
52 
53     /**
54      *
55      * Will be called when the given ability calls Ability->onBackground
56      *
57      * @param Ability Indicates the Ability object that calls the onBackground() method.
58      */
OnAbilityBackground(const std::shared_ptr<AbilityRuntime::UIAbility> & ability)59     virtual void OnAbilityBackground(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
60     {
61         GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityBackground called";
62     }
63 
64     /**
65      *
66      * Will be called when the given ability calls Ability->onForeground
67      *
68      * @param Ability Indicates the Ability object that calls the onForeground() method.
69      */
OnAbilityForeground(const std::shared_ptr<AbilityRuntime::UIAbility> & ability)70     virtual void OnAbilityForeground(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
71     {
72         GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityForeground called";
73     }
74 
75     /**
76      *
77      * Will be called when the given ability calls Ability->onActive
78      *
79      * @param Ability Indicates the Ability object that calls the onActive() method.
80      */
OnAbilityActive(const std::shared_ptr<AbilityRuntime::UIAbility> & ability)81     virtual void OnAbilityActive(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
82     {
83         GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityActive called";
84     }
85 
86     /**
87      *
88      * Will be called when the given ability calls Ability->onStop
89      *
90      * @param Ability Indicates the Ability object that calls the onStop() method.
91      */
OnAbilityStop(const std::shared_ptr<AbilityRuntime::UIAbility> & ability)92     virtual void OnAbilityStop(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
93     {
94         GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityStop called";
95     }
96 
97     /**
98      *
99      * Will be Called when an ability calls Ability#onSaveAbilityState(PacMap).
100      *
101      * @param outState Indicates the PacMap object passed to the onSaveAbilityState() callback.
102      */
OnAbilitySaveState(const PacMap & outState)103     virtual void OnAbilitySaveState(const PacMap& outState)
104     {
105         GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityStop called";
106     }
107 };
108 }  // namespace AppExecFwk
109 }  // namespace OHOS
110 #endif  // MOCK_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_LIFECYCLE_CALLBACK_H
111