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 #include "dm_constants.h"
16 #include "device_manager_impl.h"
17
18 namespace {
19 bool g_mockInitDeviceManager = true;
20 bool g_mockRegisterDevStateCallback = true;
21 bool g_mockGetLocalDeviceRet = true;
22 bool g_mockGetTrustedDeviceList = true;
23 }
24
MockInitDeviceManager(bool mockRet)25 void MockInitDeviceManager(bool mockRet)
26 {
27 g_mockInitDeviceManager = mockRet;
28 }
29
MockRegisterDevStateCallback(bool mockRet)30 void MockRegisterDevStateCallback(bool mockRet)
31 {
32 g_mockRegisterDevStateCallback = mockRet;
33 }
34
MockGetLocalDevice(bool mockRet)35 void MockGetLocalDevice(bool mockRet)
36 {
37 g_mockGetLocalDeviceRet = mockRet;
38 }
39
MockGetTrustedDeviceList(bool mockRet)40 void MockGetTrustedDeviceList(bool mockRet)
41 {
42 g_mockGetTrustedDeviceList = mockRet;
43 }
44
45 namespace OHOS {
46 namespace DistributedHardware {
InitDeviceManager(const std::string & pkgName,std::shared_ptr<DmInitCallback> dmInitCallback)47 int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback)
48 {
49 if (false == g_mockInitDeviceManager) {
50 return DM_OK;
51 }
52 return ERR_DM_INPUT_PARA_INVALID;
53 }
54
RegisterDevStateCallback(const std::string & pkgName,const std::string & extra,std::shared_ptr<DeviceStateCallback> callback)55 int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, const std::string &extra,
56 std::shared_ptr<DeviceStateCallback> callback)
57 {
58 if (false == g_mockRegisterDevStateCallback) {
59 return DM_OK;
60 }
61 return ERR_DM_INPUT_PARA_INVALID;
62 }
63
GetLocalDeviceInfo(const std::string & pkgName,DmDeviceInfo & info)64 int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info)
65 {
66 if (false == g_mockGetLocalDeviceRet) {
67 return DM_OK;
68 }
69 return ERR_DM_INPUT_PARA_INVALID;
70 }
71
GetTrustedDeviceList(const std::string & pkgName,const std::string & extra,std::vector<DmDeviceInfo> & deviceList)72 int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
73 std::vector<DmDeviceInfo> &deviceList)
74 {
75 if (false == g_mockGetTrustedDeviceList) {
76 return DM_OK;
77 }
78 return ERR_DM_INPUT_PARA_INVALID;
79 }
80 } // namespace DistributedHardware
81 } // namespace OHOS
82