• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <vector>
16 #include <unordered_map>
17 #include <gtest/gtest.h>
18 #define private public
19 #include "net_connect_utils.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS::NWeb {
25 using namespace OHOS::NetManagerStandard;
26 using namespace OHOS::Telephony;
27 class NetConnectAdapterTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase(void)35 void NetConnectAdapterTest::SetUpTestCase(void)
36 {}
37 
TearDownTestCase(void)38 void NetConnectAdapterTest::TearDownTestCase(void)
39 {}
40 
SetUp(void)41 void NetConnectAdapterTest::SetUp(void)
42 {}
43 
TearDown(void)44 void NetConnectAdapterTest::TearDown(void)
45 {}
46 
47 /**
48  * @tc.name: NetConnectAdapterTest_001.
49  * @tc.desc: test lock type.
50  * @tc.type: FUNC
51  * @tc.require:issueI5ORNO
52  */
53 HWTEST_F(NetConnectAdapterTest, NetConnectAdapterTest_001, TestSize.Level1)
54 {
55     std::unordered_map<RadioTech, NetConnectType> typeMap;
56     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_UNKNOWN, NetConnectType::CONNECTION_UNKNOWN));
57     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_IWLAN, NetConnectType::CONNECTION_UNKNOWN));
58     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_GSM, NetConnectType::CONNECTION_2G));
59     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_1XRTT, NetConnectType::CONNECTION_2G));
60     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_WCDMA, NetConnectType::CONNECTION_3G));
61     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_HSPA, NetConnectType::CONNECTION_3G));
62     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_HSPAP, NetConnectType::CONNECTION_3G));
63     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_TD_SCDMA, NetConnectType::CONNECTION_3G));
64     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_EVDO, NetConnectType::CONNECTION_3G));
65     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_EHRPD, NetConnectType::CONNECTION_3G));
66     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_LTE, NetConnectType::CONNECTION_4G));
67     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_LTE_CA, NetConnectType::CONNECTION_4G));
68     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_NR, NetConnectType::CONNECTION_5G));
69 
70     for (auto iter : typeMap) {
71         NetConnectType exceptType = iter.second;
72         RadioTech type = iter.first;
73         NetConnectType actualType = OHOS::NWeb::NetConnectUtils::ConvertToConnectTypeInner(type);
74         EXPECT_EQ(exceptType, actualType);
75     }
76     EXPECT_EQ(NetConnectType::CONNECTION_UNKNOWN,
77         OHOS::NWeb::NetConnectUtils::ConvertToConnectTypeInner(static_cast<RadioTech>(-1)));
78 }
79 
80 /**
81  * @tc.name: NetConnectAdapterTest_002.
82  * @tc.desc: test lock type.
83  * @tc.type: FUNC
84  * @tc.require:
85  */
86 HWTEST_F(NetConnectAdapterTest, NetConnectAdapterTest_002, TestSize.Level1)
87 {
88     std::unordered_map<RadioTech, NetConnectSubtype> typeMap;
89     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_UNKNOWN, NetConnectSubtype::SUBTYPE_UNKNOWN));
90     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_IWLAN, NetConnectSubtype::SUBTYPE_UNKNOWN));
91     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_WCDMA, NetConnectSubtype::SUBTYPE_UNKNOWN));
92     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_TD_SCDMA, NetConnectSubtype::SUBTYPE_UNKNOWN));
93     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_EVDO, NetConnectSubtype::SUBTYPE_UNKNOWN));
94     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_NR, NetConnectSubtype::SUBTYPE_UNKNOWN));
95     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_GSM, NetConnectSubtype::SUBTYPE_GSM));
96     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_1XRTT, NetConnectSubtype::SUBTYPE_1XRTT));
97     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_HSPA, NetConnectSubtype::SUBTYPE_HSPA));
98     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_HSPAP, NetConnectSubtype::SUBTYPE_HSPAP));
99     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_EHRPD, NetConnectSubtype::SUBTYPE_EHRPD));
100     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_LTE, NetConnectSubtype::SUBTYPE_LTE));
101     typeMap.insert(std::make_pair(RadioTech::RADIO_TECHNOLOGY_LTE_CA, NetConnectSubtype::SUBTYPE_LTE_ADVANCED));
102     for (auto iter : typeMap) {
103         NetConnectSubtype exceptType = iter.second;
104         RadioTech type = iter.first;
105         NetConnectSubtype actualType = OHOS::NWeb::NetConnectUtils::ConvertToConnectsubtype(type);
106         EXPECT_EQ(exceptType, actualType);
107     }
108     EXPECT_EQ(NetConnectSubtype::SUBTYPE_UNKNOWN, OHOS::NWeb::NetConnectUtils::ConvertToConnectsubtype(
109         static_cast<RadioTech>(-1)));
110 }
111 
112 /**
113  * @tc.name: NetConnectAdapterTest_002.
114  * @tc.desc: test lock type.
115  * @tc.type: FUNC
116  * @tc.require:
117  */
118 HWTEST_F(NetConnectAdapterTest, NetConnectAdapterTest_003, TestSize.Level1)
119 {
120     std::unordered_map<NetBearType, OHOS::NWeb::NetConnectType> typeMap;
121     typeMap.insert(std::make_pair(NetBearType::BEARER_CELLULAR, NetConnectType::CONNECTION_UNKNOWN));
122     typeMap.insert(std::make_pair(NetBearType::BEARER_WIFI, NetConnectType::CONNECTION_WIFI));
123     typeMap.insert(std::make_pair(NetBearType::BEARER_BLUETOOTH, NetConnectType::CONNECTION_BLUETOOTH));
124     typeMap.insert(std::make_pair(NetBearType::BEARER_ETHERNET, NetConnectType::CONNECTION_ETHERNET));
125     typeMap.insert(std::make_pair(NetBearType::BEARER_VPN, NetConnectType::CONNECTION_UNKNOWN));
126     typeMap.insert(std::make_pair(NetBearType::BEARER_WIFI_AWARE, NetConnectType::CONNECTION_UNKNOWN));
127     typeMap.insert(std::make_pair(NetBearType::BEARER_DEFAULT, NetConnectType::CONNECTION_UNKNOWN));
128     for (auto iter : typeMap) {
129         NetBearType netBearType = iter.first;
130         NetConnectType exceptType = iter.second;
131         NetConnectType actualType = OHOS::NWeb::NetConnectUtils::ConvertToConnectType(
132             netBearType, RadioTech::RADIO_TECHNOLOGY_UNKNOWN);
133         EXPECT_EQ(exceptType, actualType);
134     }
135     const uint32_t BEARER_ELSE = 7;
136     EXPECT_EQ(NetConnectType::CONNECTION_UNKNOWN, OHOS::NWeb::NetConnectUtils::ConvertToConnectType(
137         static_cast<NetBearType>(BEARER_ELSE), RadioTech::RADIO_TECHNOLOGY_UNKNOWN));
138 }
139 
140 /**
141  * @tc.name: NetConnectAdapterTest_002.
142  * @tc.desc: test lock type.
143  * @tc.type: FUNC
144  * @tc.require:
145  */
146 HWTEST_F(NetConnectAdapterTest, NetConnectAdapterTest_004, TestSize.Level1)
147 {
148     std::unordered_map<OHOS::NWeb::NetConnectType, std::string> typeMap;
149     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_UNKNOWN, "unknown"));
150     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_ETHERNET, "ethernet"));
151     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_WIFI, "wifi"));
152     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_2G, "2g"));
153     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_3G, "3g"));
154     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_4G, "4g"));
155     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_NONE, "none"));
156     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_BLUETOOTH, "bluetooth"));
157     typeMap.insert(std::make_pair(NetConnectType::CONNECTION_5G, "5g"));
158     for (auto iter : typeMap) {
159         OHOS::NWeb::NetConnectType connectType = iter.first;
160         std::string exceptStr = iter.second;
161         std::string actualStr = OHOS::NWeb::NetConnectUtils::ConnectTypeToString(connectType);
162         EXPECT_STREQ(actualStr.c_str(), exceptStr.c_str());
163     }
164 }
165 }