1 /* Copyright (c) 2015, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
5 #include "log_test_helpers.h"
7 static smartlist_t
*saved_logs
= NULL
;
10 setup_capture_of_logs(int new_level
)
12 int previous_log
= log_global_min_severity_
;
13 log_global_min_severity_
= new_level
;
14 mock_clean_saved_logs();
15 MOCK(logv
, mock_saving_logv
);
20 teardown_capture_of_logs(int prev
)
23 log_global_min_severity_
= prev
;
24 mock_clean_saved_logs();
28 mock_clean_saved_logs(void)
32 SMARTLIST_FOREACH(saved_logs
, mock_saved_log_entry_t
*, m
,
33 { tor_free(m
->generated_msg
); tor_free(m
); });
34 smartlist_free(saved_logs
);
38 static mock_saved_log_entry_t
*
39 mock_get_log_entry(int ix
)
41 int saved_log_count
= mock_saved_log_number();
43 ix
= saved_log_count
+ ix
;
46 if (saved_log_count
<= ix
)
49 return smartlist_get(saved_logs
, ix
);
53 mock_saved_log_at(int ix
)
55 mock_saved_log_entry_t
*ent
= mock_get_log_entry(ix
);
57 return ent
->generated_msg
;
63 mock_saved_severity_at(int ix
)
65 mock_saved_log_entry_t
*ent
= mock_get_log_entry(ix
);
73 mock_saved_log_number(void)
77 return smartlist_len(saved_logs
);
87 mock_saving_logv(int severity
, log_domain_mask_t domain
,
88 const char *funcname
, const char *suffix
,
89 const char *format
, va_list ap
)
92 char *buf
= tor_malloc_zero(10240);
94 n
= tor_vsnprintf(buf
,10240,format
,ap
);
95 tor_assert(n
< 10240-1);
99 mock_saved_log_entry_t
*e
= tor_malloc_zero(sizeof(mock_saved_log_entry_t
));
100 e
->severity
= severity
;
101 e
->funcname
= funcname
;
104 e
->generated_msg
= tor_strdup(buf
);
108 saved_logs
= smartlist_new();
109 smartlist_add(saved_logs
, e
);