• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 DISC_COAP_MOCK_H
17 #define DISC_COAP_MOCK_H
18 
19 #include <atomic>
20 #include <gmock/gmock.h>
21 #include "bus_center_info_key.h"
22 #include "bus_center_manager.h"
23 #include "nstackx.h"
24 #include "softbus_config_type.h"
25 
26 class DiscCoapInterface {
27 public:
28     virtual int32_t NSTACKX_RegisterServiceDataV2(const struct NSTACKX_ServiceData *param, uint32_t cnt) = 0;
29     virtual int32_t LnnGetLocalNumInfo(InfoKey key, int32_t *info) = 0;
30     virtual int32_t LnnGetLocalNum64Info(InfoKey key, int64_t *info) = 0;
31     virtual int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len) = 0;
32     virtual int32_t LnnGetLocalNumInfoByIfnameIdx(InfoKey key, int32_t *info, int32_t ifIdx) = 0;
33     virtual int32_t LnnGetLocalStrInfoByIfnameIdx(InfoKey key, char *info, uint32_t len, int32_t ifIdx) = 0;
34 };
35 
36 class DiscCoapMock : public DiscCoapInterface {
37 public:
GetMock()38     static DiscCoapMock* GetMock()
39     {
40         return mock.load();
41     }
42 
43     DiscCoapMock();
44     ~DiscCoapMock();
45 
46     void SetupSuccessStub();
47 
48     MOCK_METHOD(int32_t, NSTACKX_RegisterServiceDataV2,
49         (const struct NSTACKX_ServiceData *param, uint32_t cnt), (override));
50     MOCK_METHOD(int32_t, LnnGetLocalNumInfo, (InfoKey key, int32_t *info), (override));
51     MOCK_METHOD(int32_t, LnnGetLocalNum64Info, (InfoKey key, int64_t *info), (override));
52     MOCK_METHOD(int32_t, LnnGetLocalStrInfo, (InfoKey key, char *info, uint32_t len), (override));
53     MOCK_METHOD(int32_t, LnnGetLocalNumInfoByIfnameIdx, (InfoKey key, int32_t *info, int32_t ifIdx), (override));
54     MOCK_METHOD(int32_t, LnnGetLocalStrInfoByIfnameIdx,
55         (InfoKey key, char *info, uint32_t len, int32_t ifIdx), (override));
56 
57     static int32_t ActionOfNstackInit(const NSTACKX_Parameter *parameter);
58     static int32_t ActionOfRegisterServiceDataV2(const struct NSTACKX_ServiceData *param, uint32_t cnt);
59     static int32_t ActionOfLnnGetLocalNumInfo(InfoKey key, int32_t *info);
60     static int32_t ActionOfLnnGetLocalNum64Info(InfoKey key, int64_t *info);
61     static int32_t ActionOfLnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len);
62     static int32_t ActionOfLnnGetLocalNumInfoByIfnameIdx(InfoKey key, int32_t *info, int32_t ifIdx);
63     static int32_t ActionOfLnnGetLocalStrInfoByIfnameIdx(InfoKey key, char *info, uint32_t len, int32_t ifIdx);
64 
65 private:
66     static inline std::atomic<DiscCoapMock*> mock = nullptr;
67 };
68 
69 #endif