• 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: SetTypesTest
90  * @tc.desc: Test NetSpecifier::SetTypes
91  * @tc.type: FUNC
92  */
93 HWTEST_F(NetSpecifierTest, SetTypesTest, TestSize.Level1)
94 {
95     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
96     ASSERT_NE(specifier, nullptr);
97     std::set<NetBearType> bearerTypes;
98     NetBearType bearerType = NetBearType::BEARER_WIFI;
99     bearerTypes.insert(bearerType);
100     specifier->SetTypes(bearerTypes);
101 }
102 
103 /**
104  * @tc.name: SetTypeTest
105  * @tc.desc: Test NetSpecifier::SetType
106  * @tc.type: FUNC
107  */
108 HWTEST_F(NetSpecifierTest, SetTypeTest, TestSize.Level1)
109 {
110     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
111     ASSERT_NE(specifier, nullptr);
112     NetBearType bearerType = NetBearType::BEARER_WIFI;
113     specifier->SetType(bearerType);
114 }
115 
116 /**
117  * @tc.name: MarshallingTest01
118  * @tc.desc: Test NetSpecifier::Marshalling
119  * @tc.type: FUNC
120  */
121 HWTEST_F(NetSpecifierTest, MarshallingTest01, TestSize.Level1)
122 {
123     MessageParcel dataParcel;
124     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
125     ASSERT_NE(specifier, nullptr);
126     bool bRet = specifier->Marshalling(dataParcel);
127     ASSERT_TRUE(bRet);
128 }
129 
130 /**
131  * @tc.name: MarshallingTest02
132  * @tc.desc: Test static NetSpecifier::Marshalling
133  * @tc.type: FUNC
134  */
135 HWTEST_F(NetSpecifierTest, MarshallingTest02, TestSize.Level1)
136 {
137     MessageParcel dataParcel;
138     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
139     ASSERT_NE(specifier, nullptr);
140     bool bRet = NetSpecifier::Marshalling(dataParcel, specifier);
141     ASSERT_TRUE(bRet);
142 }
143 
144 /**
145  * @tc.name: MarshallingTest03
146  * @tc.desc: Test static NetSpecifier::Marshalling
147  * @tc.type: FUNC
148  */
149 HWTEST_F(NetSpecifierTest, MarshallingTest03, TestSize.Level1)
150 {
151     MessageParcel dataParcel;
152     sptr<NetSpecifier> specifier = nullptr;
153     ASSERT_EQ(specifier, nullptr);
154     bool bRet = NetSpecifier::Marshalling(dataParcel, specifier);
155     ASSERT_FALSE(bRet);
156 }
157 
158 /**
159  * @tc.name: UnmarshallingTest
160  * @tc.desc: Test NetSpecifier::Unmarshalling
161  * @tc.type: FUNC
162  */
163 HWTEST_F(NetSpecifierTest, UnmarshallingTest, TestSize.Level1)
164 {
165     MessageParcel dataParcel;
166     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
167     bool bRet = NetSpecifier::Marshalling(dataParcel, specifier);
168     ASSERT_TRUE(bRet);
169     sptr<NetSpecifier> specifierUnMarshalling = NetSpecifier::Unmarshalling(dataParcel);
170     ASSERT_NE(specifierUnMarshalling, nullptr);
171 }
172 
173 /**
174  * @tc.name: ToStringTest
175  * @tc.desc: Test NetSpecifier::ToString
176  * @tc.type: FUNC
177  */
178 HWTEST_F(NetSpecifierTest, ToStringTest, TestSize.Level1)
179 {
180     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier;
181     ASSERT_NE(specifier, nullptr);
182     std::string str = specifier->ToString("testTab");
183     NETMGR_LOG_D("netLinkInfo.ToString string is : [%{public}s]", str.c_str());
184 }
185 } // namespace NetManagerStandard
186 } // namespace OHOS
187