• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 #define protected public
21 #endif
22 
23 #include "net_supplier.h"
24 #include <gtest/gtest.h>
25 #include <memory>
26 
27 
28 namespace OHOS {
29 namespace NetManagerStandard {
30 namespace {
31 using namespace testing::ext;
32 constexpr int32_t TEST_NETID = 12;
33 constexpr uint32_t TEST_SUPPLIERID = 214;
34 constexpr const char *TEST_IDENT = "testIdent";
35 }
36 
37 class NetSupplierTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp();
42     void TearDown();
43 
44     static inline sptr<NetSupplier> supplier = nullptr;
45 };
46 
SetUpTestCase()47 void NetSupplierTest::SetUpTestCase()
48 {
49     std::set<NetCap> netCaps;
50     netCaps.insert(NET_CAPABILITY_INTERNET);
51     supplier = new (std::nothrow) NetSupplier(NetBearType::BEARER_ETHERNET, TEST_IDENT, netCaps);
52 }
53 
TearDownTestCase()54 void NetSupplierTest::TearDownTestCase() {}
55 
SetUp()56 void NetSupplierTest::SetUp() {}
57 
TearDown()58 void NetSupplierTest::TearDown() {}
59 
60 
61 HWTEST_F(NetSupplierTest, ResumeNetworkInfoTest001, TestSize.Level1)
62 {
63     bool ret = supplier->ResumeNetworkInfo();
64     EXPECT_FALSE(ret);
65 
__anon382342640202(uint32_t supplierId, bool ifValid) 66     NetDetectionHandler detectionHandler = [](uint32_t supplierId, bool ifValid) {
67         std::cout << "supplierId:" << supplierId;
68         std::cout << " IfValid:" << ifValid << std::endl;
69     };
70 
71     std::shared_ptr<Network> network = std::make_shared<Network>(TEST_NETID, TEST_SUPPLIERID, detectionHandler,
72         NetBearType::BEARER_ETHERNET, nullptr);
73     supplier->SetNetwork(network);
74     ret = supplier->ResumeNetworkInfo();
75     EXPECT_TRUE(ret);
76 
77     supplier->ClearDefault();
78 
79     ret = supplier->IsConnecting();
80     EXPECT_FALSE(ret);
81 
82     ret = supplier->IsConnected();
83     EXPECT_FALSE(ret);
84 
85     std::string result = supplier->TechToType(NetSlotTech::SLOT_TYPE_GSM);
86     EXPECT_TRUE(result == "2G");
87 
88     result = supplier->TechToType(NetSlotTech::SLOT_TYPE_LTE);
89     EXPECT_TRUE(result == "4G");
90 
91     result = supplier->TechToType(NetSlotTech::SLOT_TYPE_LTE_CA);
92     EXPECT_TRUE(result == "4G");
93 
94     uint32_t invalidValue = 100;
95     result = supplier->TechToType(static_cast<NetSlotTech>(invalidValue));
96     EXPECT_TRUE(result == "3G");
97 }
98 } // namespace NetManagerStandard
99 } // namespace OHOS
100