• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <errno.h>
17 #include <signal.h>
18 #include <pthread.h>
19 #include <sys/wait.h>
20 #include "stdio.h"
21 #include <pthread.h>
22 #include <limits.h>
23 #include <locale.h>
24 #include <wchar.h>
25 #include <stdlib.h>
26 #include <dirent.h>
27 #include <utime.h>
28 #include "functionalext.h"
29 
compare(const void * p,const void * q)30 int compare(const void *p, const void *q)
31 {
32     return (*(int *)p - *(int *)q);
33 }
34 /**
35  * @tc.name      : clearerr_0100
36  * @tc.desc      : Verify clearerr with invalid parameter
37  * @tc.level     : Level 2
38  */
clearerr_0100(void)39 void clearerr_0100(void)
40 {
41     pid_t pid = fork();
42     if (pid == -1) {
43         t_error("clearerr_0100: Error forking process");
44     } else if (pid == 0) {
45         clearerr(NULL);
46     } else {
47         int status;
48         waitpid(pid, &status, 0);
49         if (WIFSIGNALED(status)) {
50             int sig = WTERMSIG(status);
51             EXPECT_EQ("clearerr_0200", SIGABRT, sig);
52         }
53     }
54 }
55 
56 /**
57  * @tc.name      : feof_0100
58  * @tc.desc      : Verify clearerr with invalid parameter
59  * @tc.level     : Level 2
60  */
feof_0100(void)61 void feof_0100(void)
62 {
63     pid_t pid = fork();
64     if (pid == -1) {
65         t_error("feof_0100: Error forking process");
66     } else if (pid == 0) {
67         feof(NULL);
68     } else {
69         int status;
70         waitpid(pid, &status, 0);
71         if (WIFSIGNALED(status)) {
72             int sig = WTERMSIG(status);
73             EXPECT_EQ("feof_0100", SIGABRT, sig);
74         }
75     }
76 }
77 
78 /**
79  * @tc.name      : ferror_0100
80  * @tc.desc      : Verify clearerr with invalid parameter
81  * @tc.level     : Level 2
82  */
ferror_0100(void)83 void ferror_0100(void)
84 {
85     pid_t pid = fork();
86     if (pid == -1) {
87         t_error("ferror_0100: Error forking process");
88     } else if (pid == 0) {
89         ferror(NULL);
90     } else {
91         int status;
92         waitpid(pid, &status, 0);
93         if (WIFSIGNALED(status)) {
94             int sig = WTERMSIG(status);
95             EXPECT_EQ("ferror_0100", SIGABRT, sig);
96         }
97     }
98 }
99 
100 /**
101  * @tc.name      : fgetc_0100
102  * @tc.desc      : Verify clearerr with invalid parameter
103  * @tc.level     : Level 2
104  */
fgetc_0100(void)105 void fgetc_0100(void)
106 {
107     pid_t pid = fork();
108     if (pid == -1) {
109         t_error("fgetc_0100: Error forking process");
110     } else if (pid == 0) {
111         fgetc(NULL);
112     } else {
113         int status;
114         waitpid(pid, &status, 0);
115         if (WIFSIGNALED(status)) {
116             int sig = WTERMSIG(status);
117             EXPECT_EQ("fgetc_0100", SIGABRT, sig);
118         }
119     }
120 }
121 
122 /**
123  * @tc.name      : fgets_0100
124  * @tc.desc      : Verify clearerr with invalid parameter
125  * @tc.level     : Level 2
126  */
fgets_0100(void)127 void fgets_0100(void)
128 {
129     pid_t pid = fork();
130     if (pid == -1) {
131         t_error("fgets_0100: Error forking process");
132     } else if (pid == 0) {
133         char buffer[32];
134         fgets(buffer, sizeof(buffer), NULL);
135     } else {
136         int status;
137         waitpid(pid, &status, 0);
138         if (WIFSIGNALED(status)) {
139             int sig = WTERMSIG(status);
140             EXPECT_EQ("fgets_0100", SIGABRT, sig);
141         }
142     }
143 }
144 
145 /**
146  * @tc.name      : fprintf_0100
147  * @tc.desc      : Verify clearerr with invalid parameter
148  * @tc.level     : Level 2
149  */
fprintf_0100(void)150 void fprintf_0100(void)
151 {
152     pid_t pid = fork();
153     if (pid == -1) {
154         t_error("fprintf_0100: Error forking process");
155     } else if (pid == 0) {
156         char str[] = "test";
157         fprintf(NULL, "%s", str);
158     } else {
159         int status;
160         waitpid(pid, &status, 0);
161         if (WIFSIGNALED(status)) {
162             int sig = WTERMSIG(status);
163             EXPECT_EQ("fprintf_0100", SIGABRT, sig);
164         }
165     }
166 }
167 
168 /**
169  * @tc.name      : fputc_0100
170  * @tc.desc      : Verify clearerr with invalid parameter
171  * @tc.level     : Level 2
172  */
fputc_0100(void)173 void fputc_0100(void)
174 {
175     pid_t pid = fork();
176     if (pid == -1) {
177         t_error("fputc_0100: Error forking process");
178     } else if (pid == 0) {
179         fputc('a', NULL);
180     } else {
181         int status;
182         waitpid(pid, &status, 0);
183         if (WIFSIGNALED(status)) {
184             int sig = WTERMSIG(status);
185             EXPECT_EQ("fputc_0100", SIGABRT, sig);
186         }
187     }
188 }
189 
190 /**
191  * @tc.name      : fputs_0100
192  * @tc.desc      : Verify clearerr with invalid parameter
193  * @tc.level     : Level 2
194  */
fputs_0100(void)195 void fputs_0100(void)
196 {
197     pid_t pid = fork();
198     if (pid == -1) {
199         t_error("fputs_0100: Error forking process");
200     } else if (pid == 0) {
201         fputs("", NULL);
202     } else {
203         int status;
204         waitpid(pid, &status, 0);
205         if (WIFSIGNALED(status)) {
206             int sig = WTERMSIG(status);
207             EXPECT_EQ("fputs_0100", SIGABRT, sig);
208         }
209     }
210 }
211 
212 /**
213  * @tc.name      : fread_0600
214  * @tc.desc      : Verify clearerr with invalid parameter
215  * @tc.level     : Level 2
216  */
fread_0600(void)217 void fread_0600(void)
218 {
219     pid_t pid = fork();
220     if (pid == -1) {
221         t_error("fread_0600: Error forking process");
222     } else if (pid == 0) {
223         char buffer[1024];
224         fread(buffer, sizeof(char), sizeof(buffer), NULL);
225     } else {
226         int status;
227         waitpid(pid, &status, 0);
228         if (WIFSIGNALED(status)) {
229             int sig = WTERMSIG(status);
230             EXPECT_EQ("fread_0600", SIGABRT, sig);
231         }
232     }
233 }
234 
235 /**
236  * @tc.name      : fscanf_0100
237  * @tc.desc      : Verify clearerr with invalid parameter
238  * @tc.level     : Level 2
239  */
fscanf_0100(void)240 void fscanf_0100(void)
241 {
242     pid_t pid = fork();
243     if (pid == -1) {
244         t_error("fscanf_0100: Error forking process");
245     } else if (pid == 0) {
246         char buffer[1024];
247         fscanf(NULL, "%s", buffer);
248     } else {
249         int status;
250         waitpid(pid, &status, 0);
251         if (WIFSIGNALED(status)) {
252             int sig = WTERMSIG(status);
253             EXPECT_EQ("fscanf_0100", SIGABRT, sig);
254         }
255     }
256 }
257 
258 /**
259  * @tc.name      : fseek_0100
260  * @tc.desc      : Verify clearerr with invalid parameter
261  * @tc.level     : Level 2
262  */
fseek_0100(void)263 void fseek_0100(void)
264 {
265     pid_t pid = fork();
266     if (pid == -1) {
267         t_error("fseek_0100: Error forking process");
268     } else if (pid == 0) {
269         char buffer[1024];
270         fseek(NULL, 0L, SEEK_END);
271     } else {
272         int status;
273         waitpid(pid, &status, 0);
274         if (WIFSIGNALED(status)) {
275             int sig = WTERMSIG(status);
276             EXPECT_EQ("fseek_0100", SIGABRT, sig);
277         }
278     }
279 }
280 
281 /**
282  * @tc.name      : fseeko_0100
283  * @tc.desc      : Verify clearerr with invalid parameter
284  * @tc.level     : Level 2
285  */
fseeko_0100(void)286 void fseeko_0100(void)
287 {
288     pid_t pid = fork();
289     if (pid == -1) {
290         t_error("fseeko_0100: Error forking process");
291     } else if (pid == 0) {
292         fseeko(NULL, 0L, SEEK_END);
293     } else {
294         int status;
295         waitpid(pid, &status, 0);
296         if (WIFSIGNALED(status)) {
297             int sig = WTERMSIG(status);
298             EXPECT_EQ("fseeko_0100", SIGABRT, sig);
299         }
300     }
301 }
302 
main(int argc,char * argv[])303 int main(int argc, char *argv[])
304 {
305     clearerr_0100();
306     feof_0100();
307     ferror_0100();
308     fgetc_0100();
309     fgets_0100();
310     fprintf_0100();
311     fputc_0100();
312     fputs_0100();
313     fread_0600();
314     fscanf_0100();
315     fseek_0100();
316     fseeko_0100();
317 
318     return t_status;
319 }