1 #include <stdio.h>
2 #include <string.h>
3
fputs_entry(void)4 static int fputs_entry(void)
5 {
6 FILE *stream;
7 char test_data[] = "1a2bxx";
8 char gets[sizeof(test_data)] = {0};
9 size_t size = 0;
10 int ret = 0;
11
12 stream = fopen("fopen_file.txt","w");
13 if (stream == NULL)
14 {
15 perror("fopen fail");
16 ret = -1;
17 goto __exit;
18 }
19 fputs(test_data, stream);
20 fclose(stream);
21
22 stream = fopen("fopen_file.txt","r");
23 fgets(gets, sizeof(gets), stream);
24
25 if(strcmp(test_data, gets))
26 {
27 printf("%s\n",gets);
28 ret = -1;
29 }
30 __exit:
31 fclose(stream);
32 return ret;
33 }
34
35 #include <utest.h>
test_fputs(void)36 static void test_fputs(void)
37 {
38 uassert_int_equal(fputs_entry(), 0);
39 }
testcase(void)40 static void testcase(void)
41 {
42 UTEST_UNIT_RUN(test_fputs);
43 }
44 UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
45
46