• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <arpa/inet.h>
17 #include <netinet/in.h>
18 #include "functionalext.h"
19 
20 const uint32_t NET = 0x0000007f;
21 const uint32_t HOST = 0x00000001;
22 const uint32_t IP = 0x7f000001;
23 
24 /**
25  * @tc.name      : inet_makeaddr_0100
26  * @tc.desc      : Verify inet_makeaddr process success
27  * @tc.level     : Level 0
28  */
inet_makeaddr_0100(void)29 void inet_makeaddr_0100(void)
30 {
31     struct in_addr a = inet_makeaddr(NET, HOST);
32     EXPECT_EQ("inet_makeaddr_0100", htonl(IP), a.s_addr);
33 }
34 
35 /**
36  * @tc.name      : inet_makeaddr_0200
37  * @tc.desc      : Test the function of inet_makeaddr, n is 512.(n < 65536)
38  * @tc.level     : Level 0
39  */
inet_makeaddr_0200(void)40 void inet_makeaddr_0200(void)
41 {
42     const uint32_t net = 0x00000200;
43     const uint32_t ip = 0x02000001;
44     struct in_addr a = inet_makeaddr(net, HOST);
45     EXPECT_EQ("inet_makeaddr_0200", htonl(ip), a.s_addr);
46 }
47 
48 /**
49  * @tc.name      : inet_makeaddr_0300
50  * @tc.desc      : Test the function of inet_makeaddr, n is 131072.(n > 65536)
51  * @tc.level     : Level 0
52  */
inet_makeaddr_0300(void)53 void inet_makeaddr_0300(void)
54 {
55     const uint32_t net = 0x00020000;
56     const uint32_t ip = 0x02000001;
57     struct in_addr a = inet_makeaddr(net, HOST);
58     EXPECT_EQ("inet_makeaddr_0200", htonl(ip), a.s_addr);
59 }
60 
main(void)61 int main(void)
62 {
63     inet_makeaddr_0100();
64     inet_makeaddr_0200();
65     inet_makeaddr_0300();
66     return t_status;
67 }
68