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_CAPTIVE_PORTAL,
57 NetCap::NET_CAPABILITY_INTERNAL_DEFAULT
58 };
59 allCap->netCaps_ = caps;
60 EXPECT_FALSE(allCap->CapsIsNull());
61 std::set<NetBearType> bearType = {
62 NetBearType::BEARER_CELLULAR,
63 NetBearType::BEARER_WIFI,
64 NetBearType::BEARER_BLUETOOTH,
65 NetBearType::BEARER_ETHERNET,
66 NetBearType::BEARER_VPN,
67 NetBearType::BEARER_WIFI_AWARE,
68 NetBearType::BEARER_DEFAULT
69 };
70 allCap->bearerTypes_ = bearType;
71 result = allCap->ToString(tab);
72 EXPECT_FALSE(result.empty());
73 ret = allCap->CapsIsValid();
74 EXPECT_FALSE(ret);
75 allCap->netCaps_.clear();
76 EXPECT_FALSE(allCap->CapsIsNull());
77 allCap->bearerTypes_.clear();
78 allCap->linkUpBandwidthKbps_ = 1;
79 EXPECT_FALSE(allCap->CapsIsNull());
80 allCap->linkUpBandwidthKbps_ = 0;
81 allCap->linkDownBandwidthKbps_ = 1;
82 EXPECT_FALSE(allCap->CapsIsNull());
83 }
84
85 HWTEST_F(NetAllCapabilitiesTest, ParcelTest, TestSize.Level1)
86 {
87 auto allCap = std::make_shared<NetAllCapabilities>();
88 std::set<NetCap> caps = {
89 NetCap::NET_CAPABILITY_MMS,
90 NetCap::NET_CAPABILITY_NOT_METERED,
91 NetCap::NET_CAPABILITY_INTERNET,
92 NetCap::NET_CAPABILITY_NOT_VPN,
93 NetCap::NET_CAPABILITY_VALIDATED,
94 NetCap::NET_CAPABILITY_CAPTIVE_PORTAL,
95 NetCap::NET_CAPABILITY_INTERNAL_DEFAULT
96 };
97 allCap->netCaps_ = caps;
98 std::set<NetBearType> bearType = {
99 NetBearType::BEARER_CELLULAR,
100 NetBearType::BEARER_WIFI,
101 NetBearType::BEARER_BLUETOOTH,
102 NetBearType::BEARER_ETHERNET,
103 NetBearType::BEARER_VPN,
104 NetBearType::BEARER_WIFI_AWARE,
105 NetBearType::BEARER_DEFAULT
106 };
107 allCap->bearerTypes_ = bearType;
108 allCap->linkUpBandwidthKbps_ = allCap->linkDownBandwidthKbps_ = 1;
109 Parcel other1;
110 allCap->Marshalling(other1);
111 NetAllCapabilities other;
112 other.Unmarshalling(other1);
113 EXPECT_EQ(other.netCaps_.size(), caps.size() - 1);
114 }
115 } // namespace NetManagerStandard
116 } // namespace OHOS