• 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 
16 #include <gtest/gtest.h>
17 
18 #include "message_parcel.h"
19 #include "net_all_capabilities.h"
20 #include "net_mgr_log_wrapper.h"
21 #include "net_specifier.h"
22 
23 namespace OHOS {
24 namespace NetManagerStandard {
25 using namespace testing::ext;
26 class NetSpecifierTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase()34 void NetSpecifierTest::SetUpTestCase() {}
35 
TearDownTestCase()36 void NetSpecifierTest::TearDownTestCase() {}
37 
SetUp()38 void NetSpecifierTest::SetUp() {}
39 
TearDown()40 void NetSpecifierTest::TearDown() {}
41 
42 /**
43  * @tc.name: SpecifierIsValidTest001
44  * @tc.desc: Test NetSpecifier::SpecifierIsValid
45  * @tc.type: FUNC
46  */
47 HWTEST_F(NetSpecifierTest, SpecifierIsValidTest001, TestSize.Level1)
48 {
49     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier();
50     ASSERT_NE(specifier, nullptr);
51     specifier->netCapabilities_.netCaps_.insert(NET_CAPABILITY_INTERNET);
52     specifier->netCapabilities_.bearerTypes_.insert(BEARER_CELLULAR);
53     bool bValid = specifier->SpecifierIsValid();
54     ASSERT_TRUE(bValid);
55 }
56 
57 /**
58  * @tc.name: SpecifierIsValidTest002
59  * @tc.desc: Test NetSpecifier::SpecifierIsValid
60  * @tc.type: FUNC
61  */
62 HWTEST_F(NetSpecifierTest, SpecifierIsValidTest002, TestSize.Level1)
63 {
64     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
65     ASSERT_NE(specifier, nullptr);
66     bool ret = specifier->SpecifierIsValid();
67     ASSERT_FALSE(ret);
68 }
69 
70 /**
71  * @tc.name: SpecifierIsValidTest003
72  * @tc.desc: Test NetSpecifier::SpecifierIsValid
73  * @tc.type: FUNC
74  */
75 HWTEST_F(NetSpecifierTest, SpecifierIsValidTest003, TestSize.Level1)
76 {
77     std::set<NetCap> caps;
78     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
79     ASSERT_NE(specifier, nullptr);
80     specifier->ident_ = "testIdent";
81     bool ret = specifier->SpecifierIsValid();
82     ASSERT_TRUE(ret);
83     specifier->SetCapabilities(caps);
84     NetCap cap = NET_CAPABILITY_NOT_METERED;
85     specifier->SetCapability(cap);
86 }
87 
88 /**
89  * @tc.name: SpecifierIsValidTest004
90  * @tc.desc: Test NetSpecifier::SpecifierIsValid
91  * @tc.type: FUNC
92  */
93 HWTEST_F(NetSpecifierTest, SpecifierIsValidTest004, TestSize.Level1)
94 {
95     std::set<NetCap> caps;
96     NetSpecifier specifier;
97     specifier.ident_ = "";
98     specifier.SetCapabilities(caps);
99     bool ret = specifier.SpecifierIsValid();
100     ASSERT_FALSE(ret);
101 }
102 
103 /**
104  * @tc.name: SetTypesTest
105  * @tc.desc: Test NetSpecifier::SetTypes
106  * @tc.type: FUNC
107  */
108 HWTEST_F(NetSpecifierTest, SetTypesTest, TestSize.Level1)
109 {
110     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
111     ASSERT_NE(specifier, nullptr);
112     std::set<NetBearType> bearerTypes;
113     NetBearType bearerType = NetBearType::BEARER_WIFI;
114     bearerTypes.insert(bearerType);
115     specifier->SetTypes(bearerTypes);
116 }
117 
118 /**
119  * @tc.name: SetTypeTest
120  * @tc.desc: Test NetSpecifier::SetType
121  * @tc.type: FUNC
122  */
123 HWTEST_F(NetSpecifierTest, SetTypeTest, TestSize.Level1)
124 {
125     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
126     ASSERT_NE(specifier, nullptr);
127     NetBearType bearerType = NetBearType::BEARER_WIFI;
128     specifier->SetType(bearerType);
129     std::set<NetBearType> bearerTypes;
130     bearerTypes.insert(bearerType);
131     specifier->SetTypes(bearerTypes);
132 }
133 
134 /**
135  * @tc.name: MarshallingTest01
136  * @tc.desc: Test NetSpecifier::Marshalling
137  * @tc.type: FUNC
138  */
139 HWTEST_F(NetSpecifierTest, MarshallingTest01, TestSize.Level1)
140 {
141     MessageParcel dataParcel;
142     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
143     ASSERT_NE(specifier, nullptr);
144     bool bRet = specifier->Marshalling(dataParcel);
145     ASSERT_TRUE(bRet);
146 }
147 
148 /**
149  * @tc.name: MarshallingTest02
150  * @tc.desc: Test static NetSpecifier::Marshalling
151  * @tc.type: FUNC
152  */
153 HWTEST_F(NetSpecifierTest, MarshallingTest02, TestSize.Level1)
154 {
155     MessageParcel dataParcel;
156     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
157     ASSERT_NE(specifier, nullptr);
158     bool bRet = NetSpecifier::Marshalling(dataParcel, specifier);
159     ASSERT_TRUE(bRet);
160 }
161 
162 /**
163  * @tc.name: MarshallingTest03
164  * @tc.desc: Test static NetSpecifier::Marshalling
165  * @tc.type: FUNC
166  */
167 HWTEST_F(NetSpecifierTest, MarshallingTest03, TestSize.Level1)
168 {
169     MessageParcel dataParcel;
170     NetSpecifier specifier;
171     sptr<NetSpecifier> object = nullptr;
172     bool bRet = specifier.Marshalling(dataParcel, object);
173     ASSERT_FALSE(bRet);
174 }
175 
176 /**
177  * @tc.name: MarshallingTest04
178  * @tc.desc: Test static NetSpecifier::Marshalling
179  * @tc.type: FUNC
180  */
181 HWTEST_F(NetSpecifierTest, MarshallingTest04, TestSize.Level1)
182 {
183     MessageParcel dataParcel;
184     sptr<NetSpecifier> specifier = nullptr;
185     ASSERT_EQ(specifier, nullptr);
186     bool bRet = NetSpecifier::Marshalling(dataParcel, specifier);
187     ASSERT_FALSE(bRet);
188 }
189 
190 /**
191  * @tc.name: UnmarshallingTest
192  * @tc.desc: Test NetSpecifier::Unmarshalling
193  * @tc.type: FUNC
194  */
195 HWTEST_F(NetSpecifierTest, UnmarshallingTest, TestSize.Level1)
196 {
197     MessageParcel dataParcel;
198     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
199     bool bRet = NetSpecifier::Marshalling(dataParcel, specifier);
200     ASSERT_TRUE(bRet);
201     sptr<NetSpecifier> specifierUnMarshalling = NetSpecifier::Unmarshalling(dataParcel);
202     ASSERT_NE(specifierUnMarshalling, nullptr);
203 }
204 
205 /**
206  * @tc.name: ToStringTest
207  * @tc.desc: Test NetSpecifier::ToString
208  * @tc.type: FUNC
209  */
210 HWTEST_F(NetSpecifierTest, ToStringTest, TestSize.Level1)
211 {
212     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
213     ASSERT_NE(specifier, nullptr);
214     std::string str = specifier->ToString("testTab");
215     NETMGR_LOG_D("netLinkInfo.ToString string is : [%{public}s]", str.c_str());
216 }
217 } // namespace NetManagerStandard
218 } // namespace OHOS
219