commit c31791b79886dd697f02af78b86281ad6d5e407d Author: Ola Bini ola@olabini.se Date: Mon Oct 5 14:07:55 2015 -0500
Test behavior on success, and fix spaces --- src/test/log_test_helpers.c | 13 ++++++++----- src/test/log_test_helpers.h | 6 ++++-- src/test/test_util_process.c | 23 ++++++++++++++--------- 3 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c index 42778d4..7dae488 100644 --- a/src/test/log_test_helpers.c +++ b/src/test/log_test_helpers.c @@ -33,24 +33,25 @@ mock_clean_saved_logs(void) saved_logs = NULL; }
-char * +const char * mock_saved_log_at(int ix) { int saved_log_count = mock_saved_log_number(); - if(ix < 0) { + if (ix < 0) { ix = saved_log_count + ix; }
if (saved_log_count <= ix) return ""; - return ((mock_saved_log_entry_t *)smartlist_get(saved_logs, ix))->generated_msg; + return ((mock_saved_log_entry_t *) + smartlist_get(saved_logs, ix))->generated_msg; }
int mock_saved_severity_at(int ix) { int saved_log_count = mock_saved_log_number(); - if(ix < 0) { + if (ix < 0) { ix = saved_log_count + ix; }
@@ -74,8 +75,10 @@ mock_saved_logs(void) }
void -mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap) +mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, + const char *suffix, const char *format, va_list ap) { + (void)domain; char *buf = tor_malloc_zero(10240); int n; n = tor_vsnprintf(buf,10240,format,ap); diff --git a/src/test/log_test_helpers.h b/src/test/log_test_helpers.h index 789bfe4..58d14d9 100644 --- a/src/test/log_test_helpers.h +++ b/src/test/log_test_helpers.h @@ -15,12 +15,14 @@ typedef struct mock_saved_log_entry_t { struct mock_saved_log_entry_t *next; } mock_saved_log_entry_t;
-void mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap); +void mock_saving_logv(int severity, log_domain_mask_t domain, + const char *funcname, const char *suffix, + const char *format, va_list ap); void mock_clean_saved_logs(void); const smartlist_t *mock_saved_logs(void); int setup_capture_of_logs(int new_level); void teardown_capture_of_logs(int prev); -char *mock_saved_log_at(int ix); +const char *mock_saved_log_at(int ix); int mock_saved_severity_at(int ix); int mock_saved_log_number(void);
diff --git a/src/test/test_util_process.c b/src/test/test_util_process.c index 5d6c072..5d45b58 100644 --- a/src/test/test_util_process.c +++ b/src/test/test_util_process.c @@ -13,8 +13,8 @@
#define NS_MODULE util_process
-static -void temp_callback(int r, void *s) +static void +temp_callback(int r, void *s) { (void)r; (void)s; @@ -33,13 +33,14 @@ test_util_process_set_waitpid_callback(void *ignored)
res = set_waitpid_callback(pid, temp_callback, NULL); tt_assert(res); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Replaced a waitpid monitor on pid 42. That should be impossible.\n"); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Replaced a waitpid monitor on pid 42. That should be " + "impossible.\n");
done: teardown_capture_of_logs(previous_log); }
- static void test_util_process_clear_waitpid_callback(void *ignored) { @@ -52,16 +53,20 @@ test_util_process_clear_waitpid_callback(void *ignored)
res = set_waitpid_callback(pid, temp_callback, NULL); clear_waitpid_callback(res); + tt_int_op(mock_saved_log_number(), OP_EQ, 0); + clear_waitpid_callback(res); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Couldn't remove waitpid monitor for pid 43.\n");
- // done: + done: teardown_capture_of_logs(previous_log); }
- - struct testcase_t util_process_tests[] = { - { "set_waitpid_callback", test_util_process_set_waitpid_callback, 0, NULL, NULL }, - { "clear_waitpid_callback", test_util_process_clear_waitpid_callback, 0, NULL, NULL }, + { "set_waitpid_callback", test_util_process_set_waitpid_callback, 0, + NULL, NULL }, + { "clear_waitpid_callback", test_util_process_clear_waitpid_callback, 0, + NULL, NULL }, END_OF_TESTCASES };