1 #include <stdio.h>
2 #include <string.h>
3
fgetc_entry(void)4 static int fgetc_entry(void)
5 {
6 FILE *stream;
7 char data[] = "test fgetc";
8 char getc[sizeof(data)] = {0};
9 size_t size = 0;
10 int ret = 0;
11 int i=0;
12
13 stream = fopen("fopen_file.txt","w+");
14 if (stream == NULL)
15 {
16 perror("fopen fail");
17 ret = -1;
18 goto __exit;
19 }
20
21 fwrite(data, sizeof(data), 1, stream);
22 fclose(stream);
23
24 stream = fopen("fopen_file.txt","r");
25 while(1)
26 {
27 getc[i] = fgetc(stream);
28 i++;
29 if( feof(stream) )
30 {
31 break ;
32 }
33 }
34
35 if(strcmp(getc, data))
36 {
37 return -1;
38 }
39 fclose(stream);
40 __exit:
41 return ret;
42 }
43
44 #include <utest.h>
test_fgetc(void)45 static void test_fgetc(void)
46 {
47 uassert_int_equal(fgetc_entry(), 0);
48 }
testcase(void)49 static void testcase(void)
50 {
51 UTEST_UNIT_RUN(test_fgetc);
52 }
53 UTEST_TC_EXPORT(testcase, "posix.stdio_h.fgetc.c", RT_NULL, RT_NULL, 10);
54
55