diff options
author | teor (Tim Wilson-Brown) <teor2345@gmail.com> | 2016-02-01 10:02:04 +1100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-02-01 09:50:43 -0500 |
commit | f7b2ae91e9e6c9d4c3d5c993cd146829d3f1f3d7 (patch) | |
tree | 868a192841930239a9c598590fe01cc8d5cf34d2 /src/test/log_test_helpers.c | |
parent | dbb5819e96e6f31a9ed5c46cda7d7ba1265a362c (diff) | |
download | tor-f7b2ae91e9e6c9d4c3d5c993cd146829d3f1f3d7.tar.gz tor-f7b2ae91e9e6c9d4c3d5c993cd146829d3f1f3d7.zip |
Make all unit tests independent of log message order and count
Diffstat (limited to 'src/test/log_test_helpers.c')
-rw-r--r-- | src/test/log_test_helpers.c | 69 |
1 files changed, 27 insertions, 42 deletions
diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c index 88d28e1cc0..bcf73a8437 100644 --- a/src/test/log_test_helpers.c +++ b/src/test/log_test_helpers.c @@ -35,48 +35,6 @@ mock_clean_saved_logs(void) saved_logs = NULL; } -static mock_saved_log_entry_t * -mock_get_log_entry(int ix) -{ - int saved_log_count = mock_saved_log_number(); - if (ix < 0) { - ix = saved_log_count + ix; - } - - if (saved_log_count <= ix) - return NULL; - - return smartlist_get(saved_logs, ix); -} - -const char * -mock_saved_log_at(int ix) -{ - mock_saved_log_entry_t *ent = mock_get_log_entry(ix); - if (ent) - return ent->generated_msg; - else - return ""; -} - -int -mock_saved_severity_at(int ix) -{ - mock_saved_log_entry_t *ent = mock_get_log_entry(ix); - if (ent) - return ent->severity; - else - return -1; -} - -int -mock_saved_log_number(void) -{ - if (!saved_logs) - return 0; - return smartlist_len(saved_logs); -} - const smartlist_t * mock_saved_logs(void) { @@ -100,6 +58,33 @@ mock_saved_log_has_message(const char *msg) return has_msg; } +/* Do the saved logs have any messages with severity? */ +int +mock_saved_log_has_severity(int severity) +{ + int has_sev = 0; + if (saved_logs) { + SMARTLIST_FOREACH(saved_logs, mock_saved_log_entry_t *, m, + { + if (m->severity == severity) { + has_sev = 1; + } + }); + } + + return has_sev; +} + +/* Do the saved logs have any messages? */ +int +mock_saved_log_has_entry(void) +{ + if (saved_logs) { + return smartlist_len(saved_logs) > 0; + } + return 0; +} + void mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, |