• 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 
16 #ifndef DATA_COLLECTION_MOCK_H
17 #define DATA_COLLECTION_MOCK_H
18 
19 #include "gmock/gmock.h"
20 #include "parcel.h"
21 
22 #include <vector>
23 
24 #include "lib_loader.h"
25 #include "i_collector_fwk.h"
26 #include "security_event.h"
27 
28 namespace OHOS::Security::SecurityCollector {
29 class BaseDataCollection {
30 public:
31     virtual ~BaseDataCollection() = default;
32     virtual bool StartCollectors(const std::vector<int64_t>& eventIds, std::shared_ptr<ICollectorFwk> api) = 0;
33     virtual bool StopCollectors(const std::vector<int64_t>& eventIds) = 0;
34     virtual bool SubscribeCollectors(const std::vector<int64_t>& eventIds, std::shared_ptr<ICollectorFwk> api) = 0;
35     virtual bool UnsubscribeCollectors(const std::vector<int64_t>& eventIds) = 0;
36     virtual ErrorCode GetCollectorType(int64_t eventId, int32_t& collectorType) = 0;
37     virtual int32_t QuerySecurityEvent(const std::vector<SecurityEventRuler> rulers,
38         std::vector<SecurityEvent> &events) = 0;
39     virtual int32_t QuerySecurityEventConfig(std::string &result) = 0;
40     virtual int32_t AddFilter(const SecurityCollectorEventMuteFilter &filter) = 0;
41     virtual int32_t RemoveFilter(const SecurityCollectorEventMuteFilter &filter) = 0;
42     virtual bool SecurityGuardSubscribeCollector(const std::vector<int64_t>& eventIds) = 0;
43 };
44 
45 class DataCollection : public BaseDataCollection {
46 public:
GetInstance()47     static DataCollection &GetInstance()
48     {
49         static DataCollection instance;
50         return instance;
51     };
52     DataCollection() = default;
53     ~DataCollection() override = default;
54     MOCK_METHOD2(StartCollectors, bool(const std::vector<int64_t>& eventIds, std::shared_ptr<ICollectorFwk> api));
55     MOCK_METHOD1(StopCollectors, bool(const std::vector<int64_t>& eventIds));
56     MOCK_METHOD2(SubscribeCollectors, bool(const std::vector<int64_t>& eventIds, std::shared_ptr<ICollectorFwk> api));
57     MOCK_METHOD1(UnsubscribeCollectors, bool(const std::vector<int64_t>& eventIds));
58     MOCK_METHOD2(GetCollectorType, ErrorCode(int64_t eventId, int32_t& collectorType));
59     MOCK_METHOD2(QuerySecurityEvent, int32_t(const std::vector<SecurityEventRuler> rulers,
60         std::vector<SecurityEvent> &events));
61     MOCK_METHOD1(QuerySecurityEventConfig, int32_t(std::string &result));
62     MOCK_METHOD1(AddFilter, int32_t(const SecurityCollectorEventMuteFilter &filter));
63     MOCK_METHOD1(RemoveFilter, int32_t(const SecurityCollectorEventMuteFilter &filter));
64     MOCK_METHOD1(SecurityGuardSubscribeCollector, bool(const std::vector<int64_t>& eventIds));
CloseLib()65     void CloseLib() {};
66 };
67 }
68 #endif // DATA_COLLECTION_MOCK_H