Use test_eq et al in spawn_background unit tests

This commit is contained in:
Esteban Manchado Velázquez 2012-02-11 00:00:52 +01:00 committed by Nick Mathewson
parent 6b3854f8a3
commit 7b8a7556a8

View File

@ -1849,37 +1849,37 @@ run_util_spawn_background(const char *argv[], const char *expected_out,
status = tor_spawn_background(argv[0], argv, NULL, &process_handle); status = tor_spawn_background(argv[0], argv, NULL, &process_handle);
#endif #endif
tt_int_op(status, ==, expected_status); test_eq(expected_status, status);
if (status == PROCESS_STATUS_ERROR) if (status == PROCESS_STATUS_ERROR)
return; return;
tt_assert(process_handle != NULL); test_assert(process_handle != NULL);
tt_int_op(process_handle->status, ==, expected_status); test_eq(expected_status, process_handle->status);
tt_int_op(process_handle->stdout_pipe, >, 0); test_assert(process_handle->stdout_pipe > 0);
tt_int_op(process_handle->stderr_pipe, >, 0); test_assert(process_handle->stderr_pipe > 0);
/* Check stdout */ /* Check stdout */
pos = tor_read_all_from_process_stdout(process_handle, stdout_buf, pos = tor_read_all_from_process_stdout(process_handle, stdout_buf,
sizeof(stdout_buf) - 1); sizeof(stdout_buf) - 1);
tt_assert(pos >= 0); tt_assert(pos >= 0);
stdout_buf[pos] = '\0'; stdout_buf[pos] = '\0';
tt_str_op(stdout_buf, ==, expected_out); test_eq(strlen(expected_out), pos);
tt_int_op(pos, ==, strlen(expected_out)); test_streq(expected_out, stdout_buf);
/* Check it terminated correctly */ /* Check it terminated correctly */
retval = tor_get_exit_code(process_handle, 1, &exit_code); retval = tor_get_exit_code(process_handle, 1, &exit_code);
tt_int_op(retval, ==, PROCESS_EXIT_EXITED); test_eq(PROCESS_EXIT_EXITED, retval);
tt_int_op(exit_code, ==, expected_exit); test_eq(expected_exit, exit_code);
// TODO: Make test-child exit with something other than 0 // TODO: Make test-child exit with something other than 0
/* Check stderr */ /* Check stderr */
pos = tor_read_all_from_process_stderr(process_handle, stderr_buf, pos = tor_read_all_from_process_stderr(process_handle, stderr_buf,
sizeof(stderr_buf) - 1); sizeof(stderr_buf) - 1);
tt_assert(pos >= 0); test_assert(pos >= 0);
stderr_buf[pos] = '\0'; stderr_buf[pos] = '\0';
tt_str_op(stderr_buf, ==, expected_err); test_streq(expected_err, stderr_buf);
tt_int_op(pos, ==, strlen(expected_err)); test_eq(strlen(expected_err), pos);
done: done:
if (process_handle) if (process_handle)
@ -1969,9 +1969,9 @@ test_util_spawn_background_partial_read(void *ptr)
#else #else
status = tor_spawn_background(argv[0], argv, NULL, &process_handle); status = tor_spawn_background(argv[0], argv, NULL, &process_handle);
#endif #endif
tt_int_op(status, ==, expected_status); test_eq(expected_status, status);
tt_assert(process_handle); test_assert(process_handle);
tt_int_op(process_handle->status, ==, expected_status); test_eq(expected_status, process_handle->status);
/* Check stdout */ /* Check stdout */
for (expected_out_ctr = 0; expected_out[expected_out_ctr] != NULL;) { for (expected_out_ctr = 0; expected_out[expected_out_ctr] != NULL;) {
@ -1980,7 +1980,7 @@ test_util_spawn_background_partial_read(void *ptr)
sizeof(stdout_buf) - 1, NULL); sizeof(stdout_buf) - 1, NULL);
#else #else
/* Check that we didn't read the end of file last time */ /* Check that we didn't read the end of file last time */
tt_assert(!eof); test_assert(!eof);
pos = tor_read_all_handle(process_handle->stdout_handle, stdout_buf, pos = tor_read_all_handle(process_handle->stdout_handle, stdout_buf,
sizeof(stdout_buf) - 1, NULL, &eof); sizeof(stdout_buf) - 1, NULL, &eof);
#endif #endif
@ -1990,10 +1990,10 @@ test_util_spawn_background_partial_read(void *ptr)
if (0 == pos) if (0 == pos)
continue; continue;
tt_int_op(pos, >, 0); test_assert(pos > 0);
stdout_buf[pos] = '\0'; stdout_buf[pos] = '\0';
tt_str_op(stdout_buf, ==, expected_out[expected_out_ctr]); test_streq(expected_out[expected_out_ctr], stdout_buf);
tt_int_op(pos, ==, strlen(expected_out[expected_out_ctr])); test_eq(strlen(expected_out[expected_out_ctr]), pos);
expected_out_ctr++; expected_out_ctr++;
} }
@ -2002,33 +2002,33 @@ test_util_spawn_background_partial_read(void *ptr)
pos = tor_read_all_handle(process_handle->stdout_pipe, stdout_buf, pos = tor_read_all_handle(process_handle->stdout_pipe, stdout_buf,
sizeof(stdout_buf) - 1, sizeof(stdout_buf) - 1,
process_handle); process_handle);
tt_int_op(pos, ==, 0); test_eq(0, pos);
#else #else
if (!eof) { if (!eof) {
/* We should have got all the data, but maybe not the EOF flag */ /* We should have got all the data, but maybe not the EOF flag */
pos = tor_read_all_handle(process_handle->stdout_handle, stdout_buf, pos = tor_read_all_handle(process_handle->stdout_handle, stdout_buf,
sizeof(stdout_buf) - 1, sizeof(stdout_buf) - 1,
process_handle, &eof); process_handle, &eof);
tt_int_op(pos, ==, 0); test_eq(0, pos);
tt_assert(eof); test_assert(eof);
} }
/* Otherwise, we got the EOF on the last read */ /* Otherwise, we got the EOF on the last read */
#endif #endif
/* Check it terminated correctly */ /* Check it terminated correctly */
retval = tor_get_exit_code(process_handle, 1, &exit_code); retval = tor_get_exit_code(process_handle, 1, &exit_code);
tt_int_op(retval, ==, PROCESS_EXIT_EXITED); test_eq(PROCESS_EXIT_EXITED, retval);
tt_int_op(exit_code, ==, expected_exit); test_eq(expected_exit, exit_code);
// TODO: Make test-child exit with something other than 0 // TODO: Make test-child exit with something other than 0
/* Check stderr */ /* Check stderr */
pos = tor_read_all_from_process_stderr(process_handle, stderr_buf, pos = tor_read_all_from_process_stderr(process_handle, stderr_buf,
sizeof(stderr_buf) - 1); sizeof(stderr_buf) - 1);
tt_assert(pos >= 0); test_assert(pos >= 0);
stderr_buf[pos] = '\0'; stderr_buf[pos] = '\0';
tt_str_op(stderr_buf, ==, expected_err); test_streq(expected_err, stderr_buf);
tt_int_op(pos, ==, strlen(expected_err)); test_eq(strlen(expected_err), pos);
done: done:
tor_process_handle_destroy(process_handle, 1); tor_process_handle_destroy(process_handle, 1);