Update pt/configure_proxy until it stops segfaulting

This commit is contained in:
Nick Mathewson 2013-07-29 11:37:39 -04:00
parent 99bb6d2937
commit 22a074caa7
3 changed files with 28 additions and 10 deletions

View File

@ -117,8 +117,8 @@ static const config_format_t state_format = {
static or_state_t *global_state = NULL;
/** Return the persistent state struct for this Tor. */
or_state_t *
get_or_state(void)
MOCK_IMPL(or_state_t *,
get_or_state, (void))
{
tor_assert(global_state);
return global_state;

View File

@ -7,7 +7,7 @@
#ifndef TOR_STATEFILE_H
#define TOR_STATEFILE_H
or_state_t *get_or_state(void);
MOCK_DECL(or_state_t *,get_or_state,(void));
int did_last_state_file_write_fail(void);
int or_state_save(time_t now);

View File

@ -10,6 +10,7 @@
#include "transports.h"
#include "circuitbuild.h"
#include "util.h"
#include "statefile.h"
#include "test.h"
static void
@ -156,14 +157,14 @@ test_pt_protocol(void)
}
#ifdef _WIN32
static smartlist_t *
tor_get_lines_from_handle_replacement(HANDLE *handle,
enum stream_status *stream_status_out)
#define STDIN_HANDLE HANDLE
#else
static smartlist_t *
tor_get_lines_from_handle_replacement(FILE *handle,
enum stream_status *stream_status_out)
#define STDIN_HANDLE FILE
#endif
static smartlist_t *
tor_get_lines_from_handle_replacement(STDIN_HANDLE *handle,
enum stream_status *stream_status_out)
{
(void) handle;
(void) stream_status_out;
@ -188,7 +189,16 @@ static void
tor_process_handle_destroy_replacement(process_handle_t *process_handle,
int also_terminate_process)
{
return;
(void) process_handle;
(void) also_terminate_process;
}
static or_state_t *dummy_state = NULL;
static or_state_t *
get_or_state_replacement(void)
{
return dummy_state;
}
/* Test the configure_proxy() function. */
@ -199,16 +209,22 @@ test_pt_configure_proxy(void *arg)
int i;
managed_proxy_t *mp = NULL;
dummy_state = tor_malloc_zero(sizeof(or_state_t));
MOCK(tor_get_lines_from_handle,
tor_get_lines_from_handle_replacement);
MOCK(tor_process_handle_destroy,
tor_process_handle_destroy_replacement);
MOCK(get_or_state,
get_or_state_replacement);
mp = tor_malloc(sizeof(managed_proxy_t));
mp->conf_state = PT_PROTO_ACCEPTING_METHODS;
mp->transports = smartlist_new();
mp->transports_to_launch = smartlist_new();
mp->process_handle = tor_malloc_zero(sizeof(process_handle_t));
mp->argv = tor_malloc_zero(sizeof(char*)*2);
mp->argv[0] = tor_strdup("<testcase>");
/* Test the return value of configure_proxy() by calling it some
times while it is uninitialized and then finally finalizing its
@ -219,9 +235,11 @@ test_pt_configure_proxy(void *arg)
test_assert(configure_proxy(mp) == 1);
done:
tor_free(dummy_state);
UNMOCK(tor_get_lines_from_handle);
UNMOCK(tor_process_handle_destroy);
}
#define PT_LEGACY(name) \
{ #name, legacy_test_helper, 0, &legacy_setup, test_pt_ ## name }