• 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 "net_all_capabilities.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 using namespace testing::ext;
24 } // namespace
25 
26 class NetAllCapabilitiesTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase()34 void NetAllCapabilitiesTest::SetUpTestCase() {}
35 
TearDownTestCase()36 void NetAllCapabilitiesTest::TearDownTestCase() {}
37 
SetUp()38 void NetAllCapabilitiesTest::SetUp() {}
39 
TearDown()40 void NetAllCapabilitiesTest::TearDown() {}
41 
42 HWTEST_F(NetAllCapabilitiesTest, ToStringTest, TestSize.Level1)
43 {
44     auto allCap = std::make_shared<NetAllCapabilities>();
45     std::string tab = "tab";
46     std::string result = allCap->ToString(tab);
47     EXPECT_FALSE(result.empty());
48     bool ret = allCap->CapsIsValid();
49     EXPECT_TRUE(allCap->CapsIsNull());
50     std::set<NetCap> caps = {
51         NetCap::NET_CAPABILITY_MMS,
52         NetCap::NET_CAPABILITY_NOT_METERED,
53         NetCap::NET_CAPABILITY_INTERNET,
54         NetCap::NET_CAPABILITY_NOT_VPN,
55         NetCap::NET_CAPABILITY_VALIDATED,
56         NetCap::NET_CAPABILITY_PORTAL,
57         NetCap::NET_CAPABILITY_INTERNAL_DEFAULT,
58         NetCap::NET_CAPABILITY_END
59     };
60     allCap->netCaps_ = caps;
61     EXPECT_FALSE(allCap->CapsIsNull());
62     std::set<NetBearType> bearType = {
63         NetBearType::BEARER_CELLULAR,
64         NetBearType::BEARER_WIFI,
65         NetBearType::BEARER_BLUETOOTH,
66         NetBearType::BEARER_ETHERNET,
67         NetBearType::BEARER_VPN,
68         NetBearType::BEARER_WIFI_AWARE,
69         NetBearType::BEARER_DEFAULT
70     };
71     allCap->bearerTypes_ = bearType;
72     result = allCap->ToString(tab);
73     EXPECT_FALSE(result.empty());
74     ret = allCap->CapsIsValid();
75     EXPECT_FALSE(ret);
76     allCap->netCaps_.clear();
77     EXPECT_FALSE(allCap->CapsIsNull());
78     allCap->bearerTypes_.clear();
79     allCap->linkUpBandwidthKbps_ = 1;
80     EXPECT_FALSE(allCap->CapsIsNull());
81     allCap->linkUpBandwidthKbps_ = 0;
82     allCap->linkDownBandwidthKbps_ = 1;
83     EXPECT_FALSE(allCap->CapsIsNull());
84 }
85 
86 HWTEST_F(NetAllCapabilitiesTest, ParcelTest, TestSize.Level1)
87 {
88     auto allCap = std::make_shared<NetAllCapabilities>();
89     std::set<NetCap> caps = {
90         NetCap::NET_CAPABILITY_MMS,
91         NetCap::NET_CAPABILITY_NOT_METERED,
92         NetCap::NET_CAPABILITY_INTERNET,
93         NetCap::NET_CAPABILITY_NOT_VPN,
94         NetCap::NET_CAPABILITY_VALIDATED,
95         NetCap::NET_CAPABILITY_PORTAL,
96         NetCap::NET_CAPABILITY_INTERNAL_DEFAULT,
97         NetCap::NET_CAPABILITY_END
98     };
99     allCap->netCaps_ = caps;
100     std::set<NetBearType> bearType = {
101         NetBearType::BEARER_CELLULAR,
102         NetBearType::BEARER_WIFI,
103         NetBearType::BEARER_BLUETOOTH,
104         NetBearType::BEARER_ETHERNET,
105         NetBearType::BEARER_VPN,
106         NetBearType::BEARER_WIFI_AWARE,
107         NetBearType::BEARER_DEFAULT
108     };
109     allCap->bearerTypes_ = bearType;
110     allCap->linkUpBandwidthKbps_ = allCap->linkDownBandwidthKbps_ = 1;
111     Parcel other1;
112     allCap->Marshalling(other1);
113     NetAllCapabilities other;
114     other.Unmarshalling(other1);
115     EXPECT_EQ(other.netCaps_.size(), caps.size() - 1);
116 }
117 } // namespace NetManagerStandard
118 } // namespace OHOS