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 <netdb.h>
17 #include "functionalext.h"
18
19 /*
20 * @tc.name : gai_strerror_0100
21 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_BADFLAGS)
22 * @tc.level : Level 0
23 */
gai_strerror_0100(void)24 void gai_strerror_0100(void)
25 {
26 const char *result = gai_strerror(EAI_BADFLAGS);
27 EXPECT_TRUE(gai_strerror_0100, strcmp(result, "Invalid flags\0") == 0);
28 }
29
30 /*
31 * @tc.name : gai_strerror_0200
32 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_NONAME)
33 * @tc.level : Level 0
34 */
gai_strerror_0200(void)35 void gai_strerror_0200(void)
36 {
37 const char *result = gai_strerror(EAI_NONAME);
38 EXPECT_TRUE(gai_strerror_0200, strcmp(result, "Name does not resolve\0") == 0);
39 }
40
41 /*
42 * @tc.name : gai_strerror_0300
43 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_AGAIN)
44 * @tc.level : Level 0
45 */
gai_strerror_0300(void)46 void gai_strerror_0300(void)
47 {
48 const char *result = gai_strerror(EAI_AGAIN);
49 EXPECT_TRUE(gai_strerror_0300, strcmp(result, "Try again\0") == 0);
50 }
51
52 /*
53 * @tc.name : gai_strerror_0400
54 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_FAIL)
55 * @tc.level : Level 0
56 */
gai_strerror_0400(void)57 void gai_strerror_0400(void)
58 {
59 const char *result = gai_strerror(EAI_FAIL);
60 EXPECT_TRUE(gai_strerror_0400, strcmp(result, "Non-recoverable error\0") == 0);
61 }
62
63 /*
64 * @tc.name : gai_strerror_0500
65 * @tc.desc : Verify that the corresponding error message can be returned (parameter is -5)
66 * @tc.level : Level 1
67 */
gai_strerror_0500(void)68 void gai_strerror_0500(void)
69 {
70 const char *result = gai_strerror(-5);
71 EXPECT_TRUE(gai_strerror_0500, strcmp(result, "Unknown error\0") == 0);
72 }
73
74 /*
75 * @tc.name : gai_strerror_0600
76 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_FAMILY)
77 * @tc.level : Level 0
78 */
gai_strerror_0600(void)79 void gai_strerror_0600(void)
80 {
81 const char *result = gai_strerror(EAI_FAMILY);
82 EXPECT_TRUE(gai_strerror_0600, strcmp(result, "Unrecognized address family or invalid length\0") == 0);
83 }
84
85 /*
86 * @tc.name : gai_strerror_0700
87 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_SOCKTYPE)
88 * @tc.level : Level 0
89 */
gai_strerror_0700(void)90 void gai_strerror_0700(void)
91 {
92 const char *result = gai_strerror(EAI_SOCKTYPE);
93 EXPECT_TRUE(gai_strerror_0700, strcmp(result, "Unrecognized socket type\0") == 0);
94 }
95
96 /*
97 * @tc.name : gai_strerror_0800
98 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_SERVICE)
99 * @tc.level : Level 0
100 */
gai_strerror_0800(void)101 void gai_strerror_0800(void)
102 {
103 const char *result = gai_strerror(EAI_SERVICE);
104 EXPECT_TRUE(gai_strerror_0800, strcmp(result, "Unrecognized service\0") == 0);
105 }
106
107 /*
108 * @tc.name : gai_strerror_0900
109 * @tc.desc : Verify that the corresponding error message can be returned (parameter is -9)
110 * @tc.level : Level 1
111 */
gai_strerror_0900(void)112 void gai_strerror_0900(void)
113 {
114 const char *result = gai_strerror(-9);
115 EXPECT_TRUE(gai_strerror_0900, strcmp(result, "Unknown error\0") == 0);
116 }
117
118 /*
119 * @tc.name : gai_strerror_1000
120 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_MEMORY)
121 * @tc.level : Level 0
122 */
gai_strerror_1000(void)123 void gai_strerror_1000(void)
124 {
125 const char *result = gai_strerror(EAI_MEMORY);
126 EXPECT_TRUE(gai_strerror_1000, strcmp(result, "Out of memory\0") == 0);
127 }
128
129 /*
130 * @tc.name : gai_strerror_1100
131 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_SYSTEM)
132 * @tc.level : Level 0
133 */
gai_strerror_1100(void)134 void gai_strerror_1100(void)
135 {
136 const char *result = gai_strerror(EAI_SYSTEM);
137 EXPECT_TRUE(gai_strerror_1100, strcmp(result, "System error\0") == 0);
138 }
139
140 /*
141 * @tc.name : gai_strerror_1200
142 * @tc.desc : Verify that the corresponding error message can be returned (parameter is EAI_OVERFLOW)
143 * @tc.level : Level 0
144 */
gai_strerror_1200(void)145 void gai_strerror_1200(void)
146 {
147 const char *result = gai_strerror(EAI_OVERFLOW);
148 EXPECT_TRUE(gai_strerror_1200, strcmp(result, "Overflow\0") == 0);
149 }
150
151 /*
152 * @tc.name : gai_strerror_1300
153 * @tc.desc : Verify that the corresponding error message can be returned (parameter is -13)
154 * @tc.level : Level 1
155 */
gai_strerror_1300(void)156 void gai_strerror_1300(void)
157 {
158 const char *result = gai_strerror(-13);
159 EXPECT_TRUE(gai_strerror_1300, strcmp(result, "Unknown error\0") == 0);
160 }
161
main(int argc,char * argv[])162 int main(int argc, char *argv[])
163 {
164 gai_strerror_0100();
165 gai_strerror_0200();
166 gai_strerror_0300();
167 gai_strerror_0400();
168 gai_strerror_0500();
169 gai_strerror_0600();
170 gai_strerror_0700();
171 gai_strerror_0800();
172 gai_strerror_0900();
173 gai_strerror_1000();
174 gai_strerror_1100();
175 gai_strerror_1200();
176 gai_strerror_1300();
177
178 return t_status;
179 }