Test behavior on success, and fix spaces

This commit is contained in:
Ola Bini 2015-10-05 14:07:55 -05:00
parent cf4f50f943
commit c31791b798
No known key found for this signature in database
GPG Key ID: 465757AF3914B4B7
3 changed files with 27 additions and 17 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
clear_waitpid_callback(res);
tt_int_op(mock_saved_log_number(), OP_EQ, 0);
// done:
clear_waitpid_callback(res);
tt_str_op(mock_saved_log_at(0), OP_EQ,
"Couldn't remove waitpid monitor for pid 43.\n");
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
};