• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (c) 2021 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_SERVICE_H
18 #define UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_SERVICE_H
19 
20 #include <gmock/gmock.h>
21 #define protected public
22 #define private public
23 #include "dataobs_mgr_stub.h"
24 
25 namespace OHOS {
26 namespace AAFwk {
27 class MockDataObsMgrService : public DataObsManagerStub {
28 public:
29     MockDataObsMgrService() = default;
30     virtual ~MockDataObsMgrService() = default;
31 
32     int RegisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, int32_t userId,
33         DataObsOption opt = DataObsOption()) override
34     {
35         onChangeCall_++;
36         return NO_ERROR;
37     }
38     int UnregisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, int32_t userId,
39         DataObsOption opt = DataObsOption()) override
40     {
41         onChangeCall_++;
42         return NO_ERROR;
43     }
44     int NotifyChange(const Uri &uri, int32_t userId,
45         DataObsOption opt = DataObsOption()) override
46     {
47         onChangeCall_++;
48         return NO_ERROR;
49     }
50 
51     Status RegisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, bool isDescendants,
52         DataObsOption opt = DataObsOption()) override
53     {
54         onChangeCall_++;
55         return SUCCESS;
56     }
57 
58     Status UnregisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver,
59         DataObsOption opt = DataObsOption()) override
60     {
61         onChangeCall_++;
62         return SUCCESS;
63     }
64 
65     Status UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver,
66         DataObsOption opt = DataObsOption()) override
67     {
68         onChangeCall_++;
69         return SUCCESS;
70     }
71 
72     Status NotifyChangeExt(const ChangeInfo &changeInfo,
73         DataObsOption opt = DataObsOption()) override
74     {
75         onChangeCall_++;
76         return SUCCESS;
77     }
78 
79     Status NotifyProcessObserver(const std::string &key, const sptr<IRemoteObject> &observer,
80         DataObsOption opt = DataObsOption()) override
81     {
82         onChangeCall_++;
83         return SUCCESS;
84     }
85 
86     MOCK_METHOD4(RegisterObserverFromExtension, int(const Uri&, sptr<IDataAbilityObserver>,
87         int32_t userId, DataObsOption opt));
88     MOCK_METHOD3(NotifyChangeFromExtension, int(const Uri&, int32_t userId, DataObsOption opt));
89     MOCK_METHOD2(CheckTrusts, int(uint32_t consumerToken, uint32_t providerToken));
90 
OnStart()91     void OnStart() {}
OnStop()92     void OnStop() {}
93 
94 private:
95     std::atomic_int onChangeCall_ = 0;
96 };
97 }  // namespace AAFwk
98 }  // namespace OHOS
99 #endif  // UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_SERVICE_H
100