• 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 "functionalext.h"
18 
19 typedef void (*TEST_FUN)();
20 
21 /**
22  * @tc.name      : inet_addr_0100
23  * @tc.desc      : The parameter is valid and converts an IP address string into a network binary number
24  * @tc.level     : Level 0
25  */
inet_addr_0100()26 void inet_addr_0100()
27 {
28     char buff[] = "127.0.0.1";
29     int result = inet_addr(buff);
30     EXPECT_NE("inet_addr_0100", result, INADDR_NONE);
31 }
32 
33 /**
34  * @tc.name      : inet_addr_0200
35  * @tc.desc      : The p argument is invalid and has a negative number. An IP address string cannot
36  *                 be converted to a network binary number
37  * @tc.level     : Level 2
38  */
inet_addr_0200()39 void inet_addr_0200()
40 {
41     char buff[] = "-127.0.0.1";
42     int result = inet_addr(buff);
43     EXPECT_EQ("inet_addr_0200", result, INADDR_NONE);
44 }
45 
46 /**
47  * @tc.name      : inet_addr_0300
48  * @tc.desc      : The p argument is invalid. A number greater than 255 exists. An IP address string cannot be
49  *                 converted to a network binary number
50  * @tc.level     : Level 2
51  */
inet_addr_0300()52 void inet_addr_0300()
53 {
54     char buff[] = "127.0.256.1";
55     int result = inet_addr(buff);
56     EXPECT_EQ("inet_addr_0300", result, INADDR_NONE);
57 }
58 
59 TEST_FUN G_Fun_Array[] = {
60     inet_addr_0100,
61     inet_addr_0200,
62     inet_addr_0300,
63 };
64 
main(int argc,char * argv[])65 int main(int argc, char *argv[])
66 {
67     int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
68     for (int pos = 0; pos < num; ++pos) {
69         G_Fun_Array[pos]();
70     }
71 
72     return t_status;
73 }