1 /*
2 * Copyright (c) 2022-2024 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 #include <thread>
18
19 #ifdef GTEST_API_
20 #define private public
21 #define protected public
22 #endif
23
24 #include "common_net_diag_callback_test.h"
25 #include "net_diag_callback_stub.h"
26 #include "net_diag_wrapper.h"
27 #include "net_manager_constants.h"
28 #include "netnative_log_wrapper.h"
29 #include "netsys_ipc_interface_code.h"
30 #include "netsys_net_diag_data.h"
31 #include "thread"
32
33 namespace OHOS {
34 namespace NetsysNative {
35 using namespace testing::ext;
36 using namespace OHOS::nmd;
37
38 const std::string PING_DESTINATION_IP1 = "127.0.0.1";
39 const std::string PING_SOURCE_IP = "127.0.0.1";
40 const uint32_t PING_INTERVAL = 3;
41 const uint16_t PING_COUNT = 10;
42 const uint16_t PING_DATASIZE = 256;
43 const uint16_t PING_MARK = 1;
44 const uint16_t PING_TTL = 240;
45 const uint16_t PING_TIMEOUT = 1;
46 const uint16_t PING_DURATION = 10;
47 const bool PING_FLOOD = false;
48 const uint32_t PING_WAIT_MS = 1;
49 const std::string IFACENAME1 = "eth0";
50 const std::string IFACENAME2 = "eth1";
51 const std::string IFACENAME3 = "wlan0";
52 const std::string TEST_STRING_VALUE = "test";
53 const uint16_t TEST_UINT16_VALUE = 1;
54 const uint32_t TEST_UINT32_VALUE = 2;
55 const uint32_t PING_TIMEOUT_EXIT = 10;
56
57 class NetDiagWrapperTest : public testing::Test {
58 public:
59 NetDiagWrapperTest();
60 static void SetUpTestCase();
61 static void TearDownTestCase();
62 void SetUp();
63 void TearDown();
64
65 sptr<NetDiagCallbackStubTest> ptrCallback = new NetDiagCallbackStubTest();
66 };
67
NetDiagWrapperTest()68 NetDiagWrapperTest::NetDiagWrapperTest()
69 {
70 NETNATIVE_LOGI("NetDiagWrapperTest create");
71 }
72
SetUpTestCase()73 void NetDiagWrapperTest::SetUpTestCase() {}
74
TearDownTestCase()75 void NetDiagWrapperTest::TearDownTestCase() {}
76
SetUp()77 void NetDiagWrapperTest::SetUp() {}
78
TearDown()79 void NetDiagWrapperTest::TearDown() {}
80
81 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest001, TestSize.Level1)
82 {
83 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest001 enter");
84 auto netDiagWrapper = NetDiagWrapper::GetInstance();
85 NetDiagPingOption pingOption;
86 pingOption.destination_ = PING_DESTINATION_IP1;
87
88 g_waitPingSync = true;
89 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
90 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest001 enter ret = %{public}d %{public}d", ret,
91 NetManagerStandard::NETMANAGER_SUCCESS);
92 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
93
94 while (g_waitPingSync) {
95 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
96 }
97 }
98
99 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest002, TestSize.Level1)
100 {
101 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest002 enter");
102 auto netDiagWrapper = NetDiagWrapper::GetInstance();
103 NetDiagPingOption pingOption;
104 pingOption.destination_ = PING_DESTINATION_IP1;
105 pingOption.count_ = PING_COUNT;
106 g_waitPingSync = true;
107 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
108 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest002 enter ret = %{public}d %{public}d", ret,
109 NetManagerStandard::NETMANAGER_SUCCESS);
110 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
111
112 while (g_waitPingSync) {
113 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
114 }
115 }
116
117 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest003, TestSize.Level1)
118 {
119 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest003 enter");
120 auto netDiagWrapper = NetDiagWrapper::GetInstance();
121 NetDiagPingOption pingOption;
122 pingOption.destination_ = PING_DESTINATION_IP1;
123 pingOption.count_ = PING_COUNT;
124 pingOption.dataSize_ = PING_DATASIZE;
125 g_waitPingSync = true;
126 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
127 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest003 enter ret = %{public}d %{public}d", ret,
128 NetManagerStandard::NETMANAGER_SUCCESS);
129 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
130
131 while (g_waitPingSync) {
132 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
133 }
134 }
135
136 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest004, TestSize.Level1)
137 {
138 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest004 enter");
139 auto netDiagWrapper = NetDiagWrapper::GetInstance();
140 NetDiagPingOption pingOption;
141 pingOption.destination_ = PING_DESTINATION_IP1;
142 pingOption.count_ = PING_COUNT;
143 g_waitPingSync = true;
144 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
145 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest004 enter ret = %{public}d %{public}d", ret,
146 NetManagerStandard::NETMANAGER_SUCCESS);
147 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
148
149 while (g_waitPingSync) {
150 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
151 }
152 }
153
154 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest005, TestSize.Level1)
155 {
156 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest005 enter");
157 std::cout << "NetDiagWrapperTest RunPingCommandTest005 enter" << std::endl;
158 auto netDiagWrapper = NetDiagWrapper::GetInstance();
159 NetDiagPingOption pingOption;
160 pingOption.destination_ = PING_DESTINATION_IP1;
161 pingOption.count_ = PING_COUNT;
162 pingOption.duration_ = PING_DURATION;
163 g_waitPingSync = true;
164 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
165 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest005 enter ret = %{public}d %{public}d", ret,
166 NetManagerStandard::NETMANAGER_SUCCESS);
167 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
168
169 while (g_waitPingSync) {
170 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
171 }
172 }
173
174 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest006, TestSize.Level1)
175 {
176 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest006 enter");
177 auto netDiagWrapper = NetDiagWrapper::GetInstance();
178 NetDiagPingOption pingOption;
179 pingOption.destination_ = PING_DESTINATION_IP1;
180 pingOption.count_ = PING_COUNT;
181 pingOption.duration_ = PING_DURATION;
182 pingOption.flood_ = PING_FLOOD;
183 g_waitPingSync = true;
184 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
185 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest006 enter ret = %{public}d %{public}d", ret,
186 NetManagerStandard::NETMANAGER_SUCCESS);
187 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
188
189 while (g_waitPingSync) {
190 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
191 }
192 }
193
194 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest007, TestSize.Level1)
195 {
196 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest007 enter");
197 auto netDiagWrapper = NetDiagWrapper::GetInstance();
198 NetDiagPingOption pingOption;
199 pingOption.destination_ = PING_DESTINATION_IP1;
200 pingOption.count_ = PING_COUNT;
201 pingOption.duration_ = PING_DURATION;
202 pingOption.flood_ = PING_FLOOD;
203 pingOption.interval_ = PING_INTERVAL;
204 g_waitPingSync = true;
205 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
206 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest007 enter ret = %{public}d %{public}d", ret,
207 NetManagerStandard::NETMANAGER_SUCCESS);
208 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
209
210 while (g_waitPingSync) {
211 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
212 }
213 }
214
215 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest008, TestSize.Level1)
216 {
217 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest008 enter");
218 auto netDiagWrapper = NetDiagWrapper::GetInstance();
219 NetDiagPingOption pingOption;
220 pingOption.destination_ = PING_DESTINATION_IP1;
221 pingOption.count_ = PING_COUNT;
222 pingOption.duration_ = PING_DURATION;
223 pingOption.flood_ = PING_FLOOD;
224 pingOption.interval_ = PING_INTERVAL;
225 pingOption.mark_ = PING_MARK;
226 g_waitPingSync = true;
227 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
228 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest008 enter ret = %{public}d %{public}d", ret,
229 NetManagerStandard::NETMANAGER_SUCCESS);
230 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
231
232 while (g_waitPingSync) {
233 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
234 }
235 }
236
237 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest009, TestSize.Level1)
238 {
239 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest009 enter");
240 auto netDiagWrapper = NetDiagWrapper::GetInstance();
241 NetDiagPingOption pingOption;
242 pingOption.destination_ = PING_DESTINATION_IP1;
243 pingOption.count_ = PING_COUNT;
244 pingOption.duration_ = PING_DURATION;
245 pingOption.flood_ = PING_FLOOD;
246 pingOption.interval_ = PING_INTERVAL;
247 pingOption.mark_ = PING_MARK;
248 pingOption.source_ = PING_SOURCE_IP;
249 g_waitPingSync = true;
250 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
251 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest009 enter ret = %{public}d %{public}d", ret,
252 NetManagerStandard::NETMANAGER_SUCCESS);
253 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
254
255 int32_t times = PING_TIMEOUT_EXIT;
256 while (g_waitPingSync) {
257 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
258 times--;
259 if (times == 0) {
260 break;
261 }
262 }
263 }
264
265 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest010, TestSize.Level1)
266 {
267 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest010 enter");
268 auto netDiagWrapper = NetDiagWrapper::GetInstance();
269 NetDiagPingOption pingOption;
270 pingOption.destination_ = PING_DESTINATION_IP1;
271 pingOption.count_ = PING_COUNT;
272 pingOption.duration_ = PING_DURATION;
273 pingOption.flood_ = PING_FLOOD;
274 pingOption.interval_ = PING_INTERVAL;
275 pingOption.mark_ = PING_MARK;
276 pingOption.source_ = PING_SOURCE_IP;
277 pingOption.timeOut_ = PING_TIMEOUT;
278 g_waitPingSync = true;
279 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
280 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest010 enter ret = %{public}d %{public}d", ret,
281 NetManagerStandard::NETMANAGER_SUCCESS);
282 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
283
284 int32_t times = PING_TIMEOUT_EXIT;
285 while (g_waitPingSync) {
286 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
287 times--;
288 if (times == 0) {
289 break;
290 }
291 }
292 }
293
294 HWTEST_F(NetDiagWrapperTest, RunPingCommandTest011, TestSize.Level1)
295 {
296 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest011 enter");
297 auto netDiagWrapper = NetDiagWrapper::GetInstance();
298 NetDiagPingOption pingOption;
299 pingOption.destination_ = PING_DESTINATION_IP1;
300
301 pingOption.count_ = PING_COUNT;
302 pingOption.duration_ = PING_DURATION;
303 pingOption.flood_ = PING_FLOOD;
304 pingOption.interval_ = PING_INTERVAL;
305 pingOption.mark_ = PING_MARK;
306 pingOption.source_ = PING_SOURCE_IP;
307 pingOption.timeOut_ = PING_TIMEOUT;
308 pingOption.ttl_ = PING_TTL;
309 g_waitPingSync = true;
310 auto ret = netDiagWrapper->PingHost(pingOption, ptrCallback);
311 NETNATIVE_LOGI("NetDiagWrapperTest RunPingCommandTest011 enter ret = %{public}d %{public}d", ret,
312 NetManagerStandard::NETMANAGER_SUCCESS);
313 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
314
315 int32_t times = PING_TIMEOUT_EXIT;
316 while (g_waitPingSync) {
317 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
318 times--;
319 if (times == 0) {
320 break;
321 }
322 }
323 }
324
325 HWTEST_F(NetDiagWrapperTest, RunGetRouteTableCommandTest001, TestSize.Level1)
326 {
327 NETNATIVE_LOGI("NetDiagWrapperTest RunGetRouteTableCommandTest001 enter");
328 auto netDiagWrapper = NetDiagWrapper::GetInstance();
329
330 std::list<NetDiagRouteTable> routeTables;
331 auto ret = netDiagWrapper->GetRouteTable(routeTables);
332
333 for (auto const &rtable : routeTables) {
334 NETNATIVE_LOGI(
335 "NetDiagWrapperTest RunGetRouteTableCommandTest001 enter destination_:%{public}s gateway_:%{public}s "
336 "mask_:%{public}s iface_:%{public}s flags_: %{public}s metric_:%{public}d ref_:%{public}d use_:%{public}d ",
337 rtable.destination_.c_str(), rtable.gateway_.c_str(), rtable.mask_.c_str(), rtable.iface_.c_str(),
338 rtable.flags_.c_str(), rtable.metric_, rtable.ref_, rtable.use_);
339 }
340 NETNATIVE_LOGI("NetDiagWrapperTest RunGetRouteTableCommandTest001 enter ret = %{public}d %{public}d", ret,
341 NetManagerStandard::NETMANAGER_SUCCESS);
342 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
343 }
344
ShowSocketInfo(NetDiagSocketsInfo & info)345 void ShowSocketInfo(NetDiagSocketsInfo &info)
346 {
347 for (const auto < : info.netProtoSocketsInfo_) {
348 NETNATIVE_LOGI(
349 "ShowSocketInfo NeyDiagNetProtoSocketInfo protocol_:%{public}s"
350 "state_:%{public}s user_:%{public}s programName_:%{public}s recvQueue_:%{public}d "
351 "sendQueue_:%{public}d inode_:%{public}d",
352 lt.protocol_.c_str(), lt.state_.c_str(), lt.user_.c_str(),
353 lt.programName_.c_str(), lt.recvQueue_, lt.sendQueue_, lt.inode_);
354 }
355
356 for (const auto < : info.unixSocketsInfo_) {
357 NETNATIVE_LOGI(
358 "ShowSocketInfo unixSocketsInfo_ refCnt_:%{public}d inode_:%{public}d protocol_:%{public}s \
359 flags_:%{public}s type_:%{public}s state_:%{public}s path_:%{public}s",
360 lt.refCnt_, lt.inode_, lt.protocol_.c_str(), lt.flags_.c_str(), lt.type_.c_str(), lt.state_.c_str(),
361 lt.path_.c_str());
362 }
363 }
364
365 HWTEST_F(NetDiagWrapperTest, RunGetRouteTableCommandTest002, TestSize.Level1)
366 {
367 NETNATIVE_LOGI("NetDiagWrapperTest RunGetRouteTableCommandTest002 enter");
368 auto netDiagWrapper = NetDiagWrapper::GetInstance();
369
370 NetDiagSocketsInfo socketInfo;
371 NetDiagProtocolType socketType = NetDiagProtocolType::PROTOCOL_TYPE_ALL;
372 auto ret = netDiagWrapper->GetSocketsInfo(socketType, socketInfo);
373 ShowSocketInfo(socketInfo);
374 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
375
376 socketType = NetDiagProtocolType::PROTOCOL_TYPE_TCP;
377 ret = netDiagWrapper->GetSocketsInfo(socketType, socketInfo);
378 ShowSocketInfo(socketInfo);
379 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
380
381 socketType = NetDiagProtocolType::PROTOCOL_TYPE_UDP;
382 ret = netDiagWrapper->GetSocketsInfo(socketType, socketInfo);
383 ShowSocketInfo(socketInfo);
384 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
385
386 socketType = NetDiagProtocolType::PROTOCOL_TYPE_UNIX;
387 ret = netDiagWrapper->GetSocketsInfo(socketType, socketInfo);
388 ShowSocketInfo(socketInfo);
389 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
390
391 socketType = NetDiagProtocolType::PROTOCOL_TYPE_RAW;
392 ret = netDiagWrapper->GetSocketsInfo(socketType, socketInfo);
393 ShowSocketInfo(socketInfo);
394 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
395
396 std::this_thread::sleep_for(std::chrono::seconds(PING_WAIT_MS));
397 }
398
399 HWTEST_F(NetDiagWrapperTest, RunInterFaceConfigCommandTest001, TestSize.Level1)
400 {
401 NETNATIVE_LOGI("NetDiagWrapperTest RunInterFaceConfigCommandTest001 ");
402 auto netDiagWrapper = NetDiagWrapper::GetInstance();
403
404 std::list<NetDiagIfaceConfig> configs;
405
406 auto ret = netDiagWrapper->GetInterfaceConfig(configs, IFACENAME1);
407 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
408
409 ret = netDiagWrapper->GetInterfaceConfig(configs, IFACENAME2);
410 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
411
412 ret = netDiagWrapper->GetInterfaceConfig(configs, IFACENAME3);
413 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
414 }
415
416 HWTEST_F(NetDiagWrapperTest, RunInterFaceConfigCommandTest002, TestSize.Level1)
417 {
418 NETNATIVE_LOGI("NetDiagWrapperTest RunInterFaceConfigCommandTest002 ");
419 auto netDiagWrapper = NetDiagWrapper::GetInstance();
420
421 std::list<NetDiagIfaceConfig> configs;
422
423 NetDiagIfaceConfig config;
424 config.ifaceName_ = IFACENAME1;
425 const std::string ifaceName = IFACENAME1;
426 config.ipv4Addr_ = "192.168.222.234";
427 config.mtu_ = 1000;
428 config.ipv4Mask_ = "255.255.255.0";
429 config.ipv4Bcast_ = "255.255.255.0";
430 config.txQueueLen_ = 1000;
431 bool add = true;
432
433 auto ret = netDiagWrapper->UpdateInterfaceConfig(config, IFACENAME1, add);
434 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
435
436 ret = netDiagWrapper->UpdateInterfaceConfig(config, IFACENAME1, false);
437 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
438 }
439
440 HWTEST_F(NetDiagWrapperTest, RunInterFaceConfigCommandTest003, TestSize.Level1)
441 {
442 NETNATIVE_LOGI("NetDiagWrapperTest RunInterFaceConfigCommandTest003 ");
443 auto netDiagWrapper = NetDiagWrapper::GetInstance();
444
445 auto ret = netDiagWrapper->SetInterfaceActiveState(IFACENAME1, true);
446 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
447
448 ret = netDiagWrapper->SetInterfaceActiveState(IFACENAME1, false);
449 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
450
451 ret = netDiagWrapper->SetInterfaceActiveState(IFACENAME2, false);
452 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
453
454 ret = netDiagWrapper->SetInterfaceActiveState(IFACENAME2, true);
455 EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
456 }
457
458 HWTEST_F(NetDiagWrapperTest, NetDiagWrapperBranchTest001, TestSize.Level1)
459 {
460 PingIcmpResponseInfo responseInfo;
461 responseInfo.bytes_ = TEST_UINT16_VALUE;
462 responseInfo.icmpSeq_ = TEST_UINT16_VALUE;
463 responseInfo.ttl_ = TEST_UINT16_VALUE;
464 responseInfo.costTime_ = TEST_UINT32_VALUE;
465 responseInfo.from_ = TEST_STRING_VALUE;
466 Parcel parcel;
467 auto ret = responseInfo.Marshalling(parcel);
468 EXPECT_TRUE(ret);
469 ret = responseInfo.Unmarshalling(parcel, responseInfo);
470 EXPECT_TRUE(ret);
471 }
472
473 HWTEST_F(NetDiagWrapperTest, NetDiagWrapperBranchTest002, TestSize.Level1)
474 {
475 NetDiagPingResult pingResult;
476 pingResult.host_ = TEST_STRING_VALUE;
477 pingResult.ipAddr_ = TEST_STRING_VALUE;
478 pingResult.dateSize_ = TEST_UINT16_VALUE;
479 pingResult.payloadSize_ = TEST_UINT16_VALUE;
480 pingResult.transCount_ = TEST_UINT16_VALUE;
481 pingResult.recvCount_ = TEST_UINT16_VALUE;
482 Parcel parcel;
483 auto ret = pingResult.Marshalling(parcel);
484 EXPECT_TRUE(ret);
485 ret = pingResult.Unmarshalling(parcel, pingResult);
486 EXPECT_TRUE(ret);
487 }
488
489 HWTEST_F(NetDiagWrapperTest, NetDiagWrapperBranchTest003, TestSize.Level1)
490 {
491 NetDiagRouteTable routeTable;
492 routeTable.destination_ = TEST_STRING_VALUE;
493 routeTable.gateway_ = TEST_STRING_VALUE;
494 routeTable.mask_ = TEST_STRING_VALUE;
495 routeTable.iface_ = TEST_STRING_VALUE;
496 routeTable.flags_ = TEST_STRING_VALUE;
497 routeTable.metric_ = TEST_UINT32_VALUE;
498 routeTable.ref_ = TEST_UINT32_VALUE;
499 routeTable.use_ = TEST_UINT32_VALUE;
500 Parcel parcel;
501 auto ret = routeTable.Marshalling(parcel);
502 EXPECT_TRUE(ret);
503 ret = routeTable.Unmarshalling(parcel, routeTable);
504 EXPECT_TRUE(ret);
505 }
506
507 HWTEST_F(NetDiagWrapperTest, NetDiagWrapperBranchTest004, TestSize.Level1)
508 {
509 NetDiagUnixSocketInfo socketInfo;
510 socketInfo.refCnt_ = TEST_UINT16_VALUE;
511 socketInfo.inode_ = TEST_UINT32_VALUE;
512 socketInfo.protocol_ = TEST_STRING_VALUE;
513 socketInfo.flags_ = TEST_STRING_VALUE;
514 socketInfo.type_ = TEST_STRING_VALUE;
515 socketInfo.state_ = TEST_STRING_VALUE;
516 socketInfo.path_ = TEST_STRING_VALUE;
517 Parcel parcel;
518 auto ret = socketInfo.Marshalling(parcel);
519 EXPECT_TRUE(ret);
520 ret = socketInfo.Unmarshalling(parcel, socketInfo);
521 EXPECT_TRUE(ret);
522 }
523
524 HWTEST_F(NetDiagWrapperTest, NetDiagWrapperBranchTest005, TestSize.Level1)
525 {
526 NeyDiagNetProtoSocketInfo protoSocketInfo;
527 protoSocketInfo.protocol_ = TEST_STRING_VALUE;
528 protoSocketInfo.localAddr_ = TEST_STRING_VALUE;
529 protoSocketInfo.foreignAddr_ = TEST_STRING_VALUE;
530 protoSocketInfo.state_ = TEST_STRING_VALUE;
531 protoSocketInfo.user_ = TEST_STRING_VALUE;
532 protoSocketInfo.programName_ = TEST_STRING_VALUE;
533 protoSocketInfo.recvQueue_ = TEST_UINT16_VALUE;
534 protoSocketInfo.sendQueue_ = TEST_UINT16_VALUE;
535 protoSocketInfo.inode_ = TEST_UINT32_VALUE;
536 Parcel parcel;
537 auto ret = protoSocketInfo.Marshalling(parcel);
538 EXPECT_TRUE(ret);
539 ret = protoSocketInfo.Unmarshalling(parcel, protoSocketInfo);
540 EXPECT_TRUE(ret);
541 }
542 } // namespace NetsysNative
543 } // namespace OHOS
544