@@ -17,12 +17,6 @@ FILE *mock_fopen(const char *filename, const char *mode) {
17
17
return MOCK_FILE_PTR;
18
18
}
19
19
20
- int mock_fopen_s (FILE **f, const char *filename, const char *mode) {
21
- *f = mock_fopen (filename, mode);
22
-
23
- return 0 ;
24
- }
25
-
26
20
std::string expected_message = " " ;
27
21
FILE *expected_stream;
28
22
int expect_fput_count = 0 ;
@@ -50,7 +44,6 @@ extern "C" {
50
44
51
45
const char *env_variable = " " ;
52
46
#define fopen (A, B ) mock_fopen(A, B)
53
- #define fopen_s (A, B, C ) mock_fopen_s(A, B, C)
54
47
#define fputs (A, B ) mock_fputs(A, B)
55
48
#define fflush (A ) mock_fflush(A)
56
49
#define util_env_var (A, B, C ) mock_util_env_var(A, B, C)
@@ -83,6 +76,7 @@ void helper_checkConfig(util_log_config_t *expected, util_log_config_t *is) {
83
76
}
84
77
85
78
TEST_F (test, parseEnv_errors) {
79
+ expected_message = " " ;
86
80
loggerConfig = {0 , 0 , LOG_ERROR, LOG_ERROR, NULL };
87
81
expect_fput_count = 0 ;
88
82
expected_stream = stderr;
@@ -98,6 +92,9 @@ TEST_F(test, parseEnv_errors) {
98
92
helper_checkConfig (&b, &loggerConfig);
99
93
helper_log_init (" _level:debug" );
100
94
helper_checkConfig (&b, &loggerConfig);
95
+ expect_fput_count = 1 ;
96
+ expected_message = " [ERROR UMF] Cannot open output file - path too long\n " ;
97
+ helper_log_init ((" output:file," + std::string (300 , ' x' )).c_str ());
101
98
}
102
99
103
100
TEST_F (test, parseEnv) {
@@ -141,17 +138,20 @@ TEST_F(test, parseEnv) {
141
138
output.first + " ;" +
142
139
timestamp.first + " ;" + pid.first ;
143
140
b = loggerConfig = {0 , 0 , LOG_ERROR, LOG_ERROR, NULL };
141
+ expect_fput_count = 0 ;
142
+ expect_fopen_count = 0 ;
143
+ expected_stream = stderr;
144
+ expected_message = " " ;
145
+ expected_filename = " " ;
146
+ auto n = output.first .find (' ,' );
147
+ if (n != std::string::npos) {
148
+ expected_filename = output.first .substr (n + 1 );
149
+ }
150
+
144
151
if (output.second != NULL ) {
145
152
b.output = output.second ;
146
153
if (output.second == MOCK_FILE_PTR) {
147
154
expect_fopen_count = 1 ;
148
- } else {
149
- expect_fopen_count = 0 ;
150
- }
151
- auto n = output.first .find (' ,' );
152
- if (n != std::string::npos) {
153
- expected_filename =
154
- output.first .substr (n + 1 ).c_str ();
155
155
}
156
156
expected_stream = output.second ;
157
157
b.timestamp = timestamp.second ;
@@ -161,13 +161,14 @@ TEST_F(test, parseEnv) {
161
161
b.level = (util_log_level_t )logLevel.second ;
162
162
if (logLevel.second <= LOG_INFO) {
163
163
expect_fput_count = 1 ;
164
- } else {
165
- expect_fput_count = 0 ;
166
164
}
167
165
} else {
168
166
expect_fput_count = 1 ;
169
- expect_fopen_count = 0 ;
170
- expected_stream = stderr;
167
+ if (expected_filename.size () > MAX_FILE_PATH) {
168
+ expected_message =
169
+ " [ERROR UMF] Cannot open output file - "
170
+ " path too long\n " ;
171
+ }
171
172
}
172
173
helper_log_init (envVar.c_str ());
173
174
helper_checkConfig (&b, &loggerConfig);
0 commit comments