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 "inet_addr.h"
19
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 using namespace testing::ext;
24 constexpr uint8_t FAMILY = 0x00;
25 constexpr uint8_t PRE_FIX_LEN = 0;
26 const std::string ADDRESS = "127.0.0.1";
27 const std::string NET_MASK = "0x80000000";
28 const std::string HOST_NAME = "127.0.0.1";
29 constexpr uint8_t PORT = 0;
GetINetAddrData()30 INetAddr GetINetAddrData()
31 {
32 typedef enum {
33 UNKNOWN = 0x00,
34 IPV4 = 0x01,
35 IPV6 = 0x02,
36 } IpType;
37
38 INetAddr info;
39 info.type_ = IpType::UNKNOWN;
40 info.family_ = FAMILY;
41 info.prefixlen_ = PRE_FIX_LEN;
42 info.address_ = ADDRESS;
43 info.netMask_ = NET_MASK;
44 info.hostName_ = HOST_NAME;
45 info.port_ = PORT;
46 return info;
47 }
48 } // namespace
49
50 class INetAddrTest : public testing::Test {
51 public:
52 static void SetUpTestCase();
53
54 static void TearDownTestCase();
55
56 void SetUp();
57
58 void TearDown();
59 };
60
SetUpTestCase()61 void INetAddrTest::SetUpTestCase() {}
62
TearDownTestCase()63 void INetAddrTest::TearDownTestCase() {}
64
SetUp()65 void INetAddrTest::SetUp() {}
66
TearDown()67 void INetAddrTest::TearDown() {}
68
69 HWTEST_F(INetAddrTest, INetAddrTest001, TestSize.Level1)
70 {
71 Parcel parcel;
72 INetAddr addr = GetINetAddrData();
73 EXPECT_TRUE(addr.Marshalling(parcel));
74
75 INetAddr result;
76 sptr<INetAddr> iNetAddr = INetAddr::Unmarshalling(parcel);
77 EXPECT_NE(iNetAddr, nullptr);
78 }
79 } // namespace NetManagerStandard
80 } // namespace OHOS