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 LNN_HICHAIN_MOCK_H 17 #define LNN_HICHAIN_MOCK_H 18 19 #include <gmock/gmock.h> 20 #include <mutex> 21 22 #include "device_auth.h" 23 #include "device_auth_defines.h" 24 #include "softbus_adapter_thread.h" 25 #include "softbus_errcode.h" 26 #include <map> 27 28 #define TEST_LEN 1 29 #define TEST_SEQ 2 30 31 namespace OHOS { 32 class LnnHichainInterface { 33 public: LnnHichainInterface()34 LnnHichainInterface() {}; ~LnnHichainInterface()35 virtual ~LnnHichainInterface() {}; 36 37 virtual int32_t InitDeviceAuthService() = 0; 38 virtual void DestroyDeviceAuthService() = 0; 39 virtual GroupAuthManager *GetGaInstance() = 0; 40 virtual DeviceGroupManager *GetGmInstance() = 0; 41 }; 42 43 class LnnHichainInterfaceMock : public LnnHichainInterface { 44 public: 45 LnnHichainInterfaceMock(); 46 ~LnnHichainInterfaceMock() override; 47 MOCK_METHOD0(InitDeviceAuthService, int32_t()); 48 MOCK_METHOD0(DestroyDeviceAuthService, void()); 49 MOCK_METHOD0(GetGaInstance, GroupAuthManager *()); 50 MOCK_METHOD0(GetGmInstance, DeviceGroupManager *()); 51 52 static int32_t InvokeAuthDevice( 53 int32_t osAccountId, int64_t authReqId, const char *authParams, const DeviceAuthCallback *gaCallback); 54 static int32_t InvokeDataChangeListener(const char *appId, const DataChangeListener *listener); 55 static int32_t InvokeGetJoinedGroups1( 56 int32_t osAccountId, const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum); 57 static int32_t InvokeGetJoinedGroups2( 58 int32_t osAccountId, const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum); 59 static int32_t InvokeGetJoinedGroups3( 60 int32_t osAccountId, const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum); 61 static int32_t ActionofunRegDataChangeListener(const char *appId); 62 static int32_t ActionOfProcessData( 63 int64_t authSeq, const uint8_t *data, uint32_t len, const DeviceAuthCallback *gaCallback); 64 static int32_t AuthDeviceConnSend( 65 int32_t osAccountId, int64_t authReqId, const char *authParams, const DeviceAuthCallback *gaCallback); 66 static inline std::map<const char *, const DataChangeListener *> g_datachangelistener; 67 static inline DeviceAuthCallback g_devAuthCb; 68 static inline SoftBusCond cond; 69 static inline SoftBusMutex mutex; 70 static int32_t getRelatedGroups( 71 int32_t accountId, const char *auth_appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum); 72 static int32_t getRelatedGroups1( 73 int32_t accountId, const char *auth_appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum); 74 static int32_t getTrustedDevices( 75 int32_t osAccountId, const char *appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum); 76 static int32_t getTrustedDevices1( 77 int32_t osAccountId, const char *appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum); 78 static void destroyInfo(char **returnDevInfoVec); 79 }; 80 81 } // namespace OHOS 82 #endif // AUTH_HICHAIN_MOCK_H