• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_SA_INTERCEPTOR_MANAGER_H
17 #define UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_SA_INTERCEPTOR_MANAGER_H
18 
19 #include "sa_interceptor_manager.h"
20 
21 #include "ability_manager_service.h"
22 #include "ability_util.h"
23 #include "hilog_tag_wrapper.h"
24 
25 namespace OHOS {
26 namespace AbilityRuntime {
27 
28 // Mock class for SAInterceptor
29 class MockSAInterceptor : public ISAInterceptor {
30 public:
31     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.AbiilityRuntime.ISAInterceptor");
OnCheckStarting(const std::string & params,Rule & rule)32     int32_t OnCheckStarting(const std::string &params, Rule &rule) override { return 0; }
AsObject()33     sptr<IRemoteObject> AsObject() override { return nullptr; }
34 };
35 
36 // Mock class for SAInterceptor return false
37 class MockSAInterceptorRetFalse : public ISAInterceptor {
38 public:
39     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.AbiilityRuntime.ISAInterceptor");
OnCheckStarting(const std::string & params,Rule & rule)40     int32_t OnCheckStarting(const std::string &params, Rule &rule) override { return -1; }
AsObject()41     sptr<IRemoteObject> AsObject() override { return nullptr; }
42 };
43 
44 class MockIRemoteObject : public IRemoteObject {
45 public:
46     static sptr<MockIRemoteObject> instance;
MockIRemoteObject()47     MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {}
~MockIRemoteObject()48     ~MockIRemoteObject() {}
GetObjectRefCount()49     int32_t GetObjectRefCount() override
50     {
51         return 0;
52     }
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)53     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
54     {
55         return ERR_OK;
56     }
IsProxyObject()57     bool IsProxyObject() const override
58     {
59         return true;
60     }
CheckObjectLegality()61     bool CheckObjectLegality() const override
62     {
63         return true;
64     }
AddDeathRecipient(const sptr<DeathRecipient> & recipient)65     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override
66     {
67         return true;
68     }
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)69     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override
70     {
71         return true;
72     }
Marshalling(Parcel & parcel)73     bool Marshalling(Parcel &parcel) const override
74     {
75         return true;
76     }
AsInterface()77     sptr<IRemoteBroker> AsInterface() override
78     {
79         return nullptr;
80     }
Dump(int fd,const std::vector<std::u16string> & args)81     int Dump(int fd, const std::vector<std::u16string> &args) override
82     {
83         return 0;
84     }
GetObjectDescriptor()85     std::u16string GetObjectDescriptor() const
86     {
87         std::u16string descriptor = std::u16string();
88         return descriptor;
89     }
90 };
91 
92 class MockDeathRecipient : public IRemoteObject::DeathRecipient {
93 public:
94     enum {
95         ADD_DEATH_RECIPIENT,
96         REMOVE_DEATH_RECIPIENT,
97         NOTICE_DEATH_RECIPIENT,
98         TEST_SERVICE_DEATH_RECIPIENT,
99         TEST_DEVICE_DEATH_RECIPIENT,
100     };
OnRemoteDied(const wptr<IRemoteObject> & remote)101     void OnRemoteDied(const wptr<IRemoteObject> &remote)
102     {
103         return;
104     }
105 };
106 } // namespace AbilityRuntime
107 } // namespace OHOS
108 #endif // UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_SA_INTERCEPTOR_MANAGER_H