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 "dhcp_result_parcel.h"
19 
20 namespace OHOS {
21 namespace NetsysNative {
22 namespace {
23 using namespace testing::ext;
24 const std::string IFACE = "iface0";
25 const std::string IP_ADDR = "127.0.0.1";
26 const std::string GATE_WAY = "255.255.255.128";
27 const std::string SUB_NET = "127.0.0.1";
28 const std::string ROUTE_1 = "route";
29 const std::string ROUTE_2 = "route";
30 const std::string DNS_1 = "0.0.0.0";
31 const std::string DNS_2 = "8.8.8.8";
GetDhcpResultParcelData()32 DhcpResultParcel GetDhcpResultParcelData()
33 {
34     DhcpResultParcel info;
35     info.iface_ = IFACE;
36     info.ipAddr_ = IP_ADDR;
37     info.gateWay_ = GATE_WAY;
38     info.subNet_ = SUB_NET;
39     info.route1_ = ROUTE_1;
40     info.route2_ = ROUTE_2;
41     info.dns1_ = DNS_1;
42     info.dns2_ = DNS_2;
43     return info;
44 }
45 } // namespace
46 
47 class DhcpResultParcelTest : public testing::Test {
48 public:
49     static void SetUpTestCase();
50     static void TearDownTestCase();
51     void SetUp();
52     void TearDown();
53 };
54 
SetUpTestCase()55 void DhcpResultParcelTest::SetUpTestCase() {}
56 
TearDownTestCase()57 void DhcpResultParcelTest::TearDownTestCase() {}
58 
SetUp()59 void DhcpResultParcelTest::SetUp() {}
60 
TearDown()61 void DhcpResultParcelTest::TearDown() {}
62 
63 HWTEST_F(DhcpResultParcelTest, InterfaceTest001, TestSize.Level1)
64 {
65     DhcpResultParcel dhcpResultParcel = GetDhcpResultParcelData();
66     Parcel parcel;
67     bool isMarshlling = dhcpResultParcel.Marshalling(parcel);
68     EXPECT_TRUE(isMarshlling);
69 
70     sptr<DhcpResultParcel> resultParcel = DhcpResultParcel::Unmarshalling(parcel);
71     EXPECT_NE(resultParcel, nullptr);
72 }
73 } // namespace nmd
74 } // namespace OHOS
75