utest: rename the ut to the utests
[platform/core/uifw/libtdm.git] / utests / stubs / stub_stdio.h
1 #ifndef STUB_STDIO_H
2 #define STUB_STDIO_H
3
4 #include <stdio.h>
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 static struct _open_close_stub_ctrl {
11         int fopen_fd_returned;
12         int fclose_error;
13         int fclose_colled;
14         int close_error;
15         int close_colled;
16 } open_close_stub_ctrl;
17
18 static int SSCANF_ERROR;
19
20 static void stub_stdio_init()
21 {
22         SSCANF_ERROR = 0;
23         open_close_stub_ctrl.fopen_fd_returned = 1;
24         open_close_stub_ctrl.fclose_error = 0;
25         open_close_stub_ctrl.fclose_colled = 0;
26         open_close_stub_ctrl.close_error = 0;
27         open_close_stub_ctrl.close_colled = 0;
28 }
29
30 static int stub_sscanf(const char *buf, const char *format, ...)
31 {
32         (void)buf;
33         (void)format;
34
35         if (SSCANF_ERROR) {
36                 return -1;
37         }
38
39         return 0;
40 }
41
42 #ifndef O_RDWR
43 #define O_RDWR          02                      /* copy from <bits/fcntl-linux.h>*/
44 #endif
45 #ifndef O_
46 #define O_CLOEXEC       02000000        /* copy from <bits/fcntl-linux.h>*/
47 #endif
48
49 static FILE *stub_fopen (const char *filename, const char *modes)
50 {
51         if (filename == NULL)
52                 return NULL;
53         static FILE f;
54         return &f;
55 }
56
57 static int stub_fclose (FILE *__stream)
58 {
59         if (open_close_stub_ctrl.fclose_error)
60                 return -1;
61         if (__stream == NULL)
62                 return -1;
63
64         open_close_stub_ctrl.fclose_colled = 1;
65         return 1;
66 }
67
68 static int stub_fflush (FILE *__stream)
69 {
70         return 1;
71 }
72
73 static int stub_fileno (FILE *__stream)
74 {
75         return 1;
76 }
77
78 static int stub_setvbuf (FILE *__restrict __stream, char *__restrict __buf, int __modes, size_t __n)
79 {
80         return 1;
81 }
82
83 static size_t stub_fwrite (const void * ptr, size_t size,
84                       size_t n, FILE *s)
85 {
86         return size;
87 }
88
89 #ifdef open
90         #undef open
91 #endif
92 #define fopen stub_fopen
93 #define fclose stub_fclose
94 #define fflush stub_fflush
95 #define fileno stub_fileno
96 #define setvbuf stub_setvbuf
97 #define sscanf stub_sscanf
98 #define fwrite stub_fwrite
99
100 #ifdef __cplusplus
101 }
102 #endif
103
104
105 #endif // STUB_STDIO_H