• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <gtest/gtest.h>
17 
18 #ifdef GTEST_API_
19 #define private public
20 #endif
21 
22 #include "net_conn_types.h"
23 #include "net_mgr_log_wrapper.h"
24 #include "net_supplier.h"
25 
26 namespace OHOS {
27 namespace NetManagerStandard {
28 using namespace testing::ext;
29 class NetScoreTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp();
34     void TearDown();
35 };
36 
SetUpTestCase()37 void NetScoreTest::SetUpTestCase() {}
38 
TearDownTestCase()39 void NetScoreTest::TearDownTestCase() {}
40 
SetUp()41 void NetScoreTest::SetUp() {}
42 
TearDown()43 void NetScoreTest::TearDown() {}
44 
45 HWTEST_F(NetScoreTest, NetSupplierBranchTest, TestSize.Level1)
46 {
47     std::set<NetCap> netCaps{NET_CAPABILITY_MMS, NET_CAPABILITY_INTERNET};
48     std::string ident = "ident";
49     NetBearType bearerType = BEARER_CELLULAR;
50     sptr<NetSupplier> supplier = (std::make_unique<NetSupplier>(bearerType, ident, netCaps)).release();
51 
52     HttpProxy httpProxy;
53     supplier->ClearDefault();
54     supplier->UpdateGlobalHttpProxy(httpProxy);
55     uint32_t reqId = 0;
56     supplier->RemoveBestRequest(reqId);
57     supplier->IsConnecting();
58 
59     NetSupplierInfo netSupplierInfo = {};
60     supplier->network_ = nullptr;
61     supplier->UpdateNetSupplierInfo(netSupplierInfo);
62 
63     NetLinkInfo netLinkInfo = {};
64     supplier->UpdateNetLinkInfo(netLinkInfo);
65     supplier->GetHttpProxy(httpProxy);
66     supplier->ClearDefault();
67     supplier->UpdateGlobalHttpProxy(httpProxy);
68 
69     std::set<NetCap> caps;
70     bool ret = supplier->CompareNetCaps(caps);
71     ASSERT_TRUE(ret);
72 
73     ret = supplier->HasNetCaps(caps);
74     ASSERT_TRUE(ret);
75 
76     ret = supplier->IsConnecting();
77     ASSERT_FALSE(ret);
78 
79     supplier->netController_ = nullptr;
80     supplier->netSupplierInfo_.isAvailable_ = true;
81     ret = supplier->SupplierDisconnection(caps);
82     ASSERT_FALSE(ret);
83 
84     int32_t result = supplier->GetNetId();
85     EXPECT_EQ(result, INVALID_NET_ID);
86 }
87 } // namespace NetManagerStandard
88 } // namespace OHOS