1 /*
2  * Copyright (c) 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 HISYSEVENT_MOCK_H
17 #define HISYSEVENT_MOCK_H
18 
19 #include <atomic>
20 #include <cstdint>
21 #include <gmock/gmock.h>
22 
23 #include "hisysevent_c.h"
24 
25 class HiSysEventInterface {
26 public:
27     virtual int MockHiSysEvent_Write(const char *func, int64_t line, const char *domain, const char *name,
28         HiSysEventEventType type, const HiSysEventParam params[], size_t size) = 0;
29 };
30 
31 class HiSysEventMock : public HiSysEventInterface {
32 public:
GetMock()33     static HiSysEventMock *GetMock()
34     {
35         return mock.load();
36     }
37 
38     HiSysEventMock();
39     ~HiSysEventMock();
40 
41     MOCK_METHOD7(HiSysEvent_Write,
42         int(const char *func, int64_t line, const char *domain, const char *name, HiSysEventEventType type,
43             const HiSysEventParam params[], size_t size));
44 
45     int MockHiSysEvent_Write(const char *func, int64_t line, const char *domain, const char *name,
46         HiSysEventEventType type, const HiSysEventParam params[], size_t size) override;
47 
48 private:
49     static inline std::atomic<HiSysEventMock *> mock = nullptr;
50 };
51 
52 #endif // HISYSEVENT_MOCK_H
53