1 /*
2 * Copyright (c) 2023 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 "common_mock_net_remote_object_test.h"
19 #include "notify_callback_proxy.h"
20
21 namespace OHOS {
22 namespace NetsysNative {
23 namespace {
24 using namespace testing::ext;
25 } // namespace
26
27 class NotifyCallbackProxyTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp();
32 void TearDown();
33
34 static inline std::shared_ptr<NotifyCallbackProxy> notifyProxy = nullptr;
35 };
36
SetUpTestCase()37 void NotifyCallbackProxyTest::SetUpTestCase()
38 {
39 sptr<IRemoteObject> impl = new (std::nothrow) NetManagerStandard::MockNetIRemoteObject();
40 notifyProxy = std::make_shared<NotifyCallbackProxy>(impl);
41 }
42
TearDownTestCase()43 void NotifyCallbackProxyTest::TearDownTestCase() {}
44
SetUp()45 void NotifyCallbackProxyTest::SetUp() {}
46
TearDown()47 void NotifyCallbackProxyTest::TearDown() {}
48
49 HWTEST_F(NotifyCallbackProxyTest, OnInterfaceAddressUpdated001, TestSize.Level1)
50 {
51 std::string addr = "192.161.0.5";
52 std::string ifName = "test0";
53 int flags = 1;
54 int scope = 2;
55 int32_t ret = notifyProxy->OnInterfaceAddressUpdated(addr, ifName, flags, scope);
56 EXPECT_EQ(ret, 0);
57 }
58
59 HWTEST_F(NotifyCallbackProxyTest, OnInterfaceAddressRemoved001, TestSize.Level1)
60 {
61 sptr<IRemoteObject> impl = new (std::nothrow) NetManagerStandard::MockNetIRemoteObject();
62 sptr<NotifyCallbackProxy> notifyProxy = new (std::nothrow) NotifyCallbackProxy(impl);
63 std::string addr = "192.161.0.5";
64 std::string ifName = "test0";
65 int flags = 1;
66 int scope = 2;
67 int32_t ret = notifyProxy->OnInterfaceAddressRemoved(addr, ifName, flags, scope);
68 EXPECT_EQ(ret, 0);
69 }
70
71 HWTEST_F(NotifyCallbackProxyTest, OnInterfaceAdded001, TestSize.Level1)
72 {
73 std::string ifName = "test0";
74 int32_t ret = notifyProxy->OnInterfaceAdded(ifName);
75 EXPECT_EQ(ret, 0);
76 }
77
78 HWTEST_F(NotifyCallbackProxyTest, OnInterfaceRemoved001, TestSize.Level1)
79 {
80 std::string ifName = "test0";
81 int32_t ret = notifyProxy->OnInterfaceRemoved(ifName);
82 EXPECT_EQ(ret, 0);
83 }
84
85 HWTEST_F(NotifyCallbackProxyTest, OnInterfaceChanged001, TestSize.Level1)
86 {
87 std::string ifName = "test0";
88 bool isUp = false;
89 int32_t ret = notifyProxy->OnInterfaceChanged(ifName, isUp);
90 EXPECT_EQ(ret, 0);
91 }
92
93 HWTEST_F(NotifyCallbackProxyTest, OnInterfaceLinkStateChanged001, TestSize.Level1)
94 {
95 std::string ifName = "test0";
96 bool isUp = false;
97 int32_t ret = notifyProxy->OnInterfaceLinkStateChanged(ifName, isUp);
98 EXPECT_EQ(ret, 0);
99 }
100
101 HWTEST_F(NotifyCallbackProxyTest, OnRouteChanged001, TestSize.Level1)
102 {
103 bool updated = false;
104 std::string route = "192.168.0.1";
105 std::string gateway = "192.168.0.1";
106 std::string ifName = "test0";
107 int32_t ret = notifyProxy->OnRouteChanged(updated, route, gateway, ifName);
108 EXPECT_EQ(ret, 0);
109 }
110
111 HWTEST_F(NotifyCallbackProxyTest, OnDhcpSuccess001, TestSize.Level1)
112 {
113 sptr<DhcpResultParcel> dhcpResult = new (std::nothrow) DhcpResultParcel;
114 dhcpResult->iface_ = "test0";
115 dhcpResult->ipAddr_ = "192.168.11.55";
116 dhcpResult->gateWay_ = "192.168.10.1";
117 dhcpResult->subNet_ = "255.255.255.0";
118 int32_t ret = notifyProxy->OnDhcpSuccess(dhcpResult);
119 EXPECT_EQ(ret, 0);
120 }
121
122 HWTEST_F(NotifyCallbackProxyTest, OnBandwidthReachedLimit001, TestSize.Level1)
123 {
124 std::string limitName = "limit";
125 std::string iface = "test0";
126 int32_t ret = notifyProxy->OnBandwidthReachedLimit(limitName, iface);
127 EXPECT_EQ(ret, 0);
128 }
129
130 HWTEST_F(NotifyCallbackProxyTest, OnBandwidthReachedLimit002, TestSize.Level1)
131 {
132 std::string limitName1 = "limit";
133 std::string iface1;
134 int32_t ret = notifyProxy->OnBandwidthReachedLimit(limitName1, iface1);
135 EXPECT_EQ(ret, 0);
136 }
137
138 HWTEST_F(NotifyCallbackProxyTest, OnBandwidthReachedLimit003, TestSize.Level1)
139 {
140 std::string limitName1;
141 std::string iface1;
142 int32_t ret = notifyProxy->OnBandwidthReachedLimit(limitName1, iface1);
143 EXPECT_EQ(ret, 0);
144 }
145 } // namespace nmd
146 } // namespace OHOS