• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "net_conn_client_test_mock.h"
17 
18 #include <map>
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 
23 HttpProxy defaultHttpProxy_;
24 HttpProxy appHttpProxy_("", 0, {});
25 uint32_t appId_;
26 std::map<int, int> appMap;
27 
GetDefaultHttpProxy(HttpProxy & httpProxy)28 int32_t NetConnClient::GetDefaultHttpProxy(HttpProxy& httpProxy)
29 {
30     httpProxy = defaultHttpProxy_;
31     return 0;
32 }
33 
RegisterAppHttpProxyCallback(std::function<void (const HttpProxy & httpProxy)> callback,uint32_t & callbackid)34 void NetConnClient::RegisterAppHttpProxyCallback(std::function<void(const HttpProxy &httpProxy)> callback,
35                                                  uint32_t &callbackid)
36 {
37     callbackid = appId_;
38     appMap[callbackid] = callbackid;
39     callback(appHttpProxy_);
40 }
41 
UnregisterAppHttpProxyCallback(uint32_t callbackid)42 void NetConnClient::UnregisterAppHttpProxyCallback(uint32_t callbackid)
43 {
44     appMap.erase(callbackid);
45 }
46 
SetDefaultHttpProxy(HttpProxy httpProxy)47 void NetConnClientMock::SetDefaultHttpProxy(HttpProxy httpProxy)
48 {
49     defaultHttpProxy_ = httpProxy;
50 }
51 
SetAppId(uint32_t appId)52 void NetConnClientMock::SetAppId(uint32_t appId)
53 {
54     appId_ = appId;
55 }
56 
IsAppExist(uint32_t appId)57 bool NetConnClientMock::IsAppExist(uint32_t appId)
58 {
59     return appMap.find(appId) != appMap.end();
60 }
61 
62 }
63 
64 }