Exemplo n.º 1
0
// Ensure perform_operation() succeeds given valid input parameters.
void test_perform_operation(void **state) {
	const OperatorFunction operator_functions[] = {
		{"+", binary_operator},
		{"*", binary_operator},
	};
	char *args[] = {
		"1", "+", "3", "*", "10",
	};
	int number_of_intermediate_values;
	int *intermediate_values;
	int error_occurred;

	// Setup return values of mock operator functions.
	// Addition.
	expect_value(binary_operator, a, 1);
	expect_value(binary_operator, b, 3);
	will_return(binary_operator, 4);

	// Multiplication.
	expect_value(binary_operator, a, 4);
	expect_value(binary_operator, b, 10);
	will_return(binary_operator, 40);

	assert_int_equal(perform_operation(
	    array_length(args), args, array_length(operator_functions),
	    operator_functions, &number_of_intermediate_values,
	    &intermediate_values, &error_occurred), 40);
	assert_int_equal(error_occurred, 0);

	assert_true(intermediate_values);
	assert_int_equal(intermediate_values[0], 4);
	assert_int_equal(intermediate_values[1], 40);
	test_free(intermediate_values);
}
Exemplo n.º 2
0
static void
test_send_then_message_requested_and_replied_callback_is_called() {
  init_messenger( "/tmp" );

  const char service_name[] = "Say HELLO";

  expect_value( callback_req_hello, tag, 43556 );
  expect_string( callback_req_hello, data, "HELLO" );
  expect_value( callback_req_hello, len, 6 );
  add_message_requested_callback( service_name, callback_req_hello );

  expect_value( callback_rep_hello_end, tag, 65534 );
  expect_string( callback_rep_hello_end, data, "OLLEH" );
  expect_value( callback_rep_hello_end, len, 6 );
  expect_value( callback_rep_hello_end, user_data, NULL );
  add_message_replied_callback( service_name, callback_rep_hello_end );

  send_request_message( service_name, service_name,  43556, "HELLO", strlen( "HELLO" ) + 1, NULL );

  start_messenger();
  start_event_handler();

  delete_message_replied_callback( service_name, callback_rep_hello_end );
  delete_message_requested_callback( service_name, callback_req_hello );
  delete_send_queue( lookup_hash_entry( send_queues, service_name ) );

  finalize_messenger();
}
static void
create_port_desc( void **state ) {
  UNUSED( state );

  int ret = init_port_manager( SELECT_TIMEOUT_USEC, MAX_SEND_QUEUE, MAX_RECV_QUEUE );
  if ( ret != OFDPE_SUCCESS ) {
   return;
  }

  expect_string( mock_create_ether_device, name, DEV_NAME );
  expect_value( mock_create_ether_device, max_send_queue, MAX_SEND_QUEUE );
  expect_value( mock_create_ether_device, max_recv_queue, MAX_RECV_QUEUE );
  switch_port *port = ( switch_port * ) xmalloc( sizeof( switch_port ) );
  port->device = ( ether_device * ) xmalloc( sizeof( ether_device ) );
  memcpy( port->device->name, DEV_NAME, sizeof( port->device->name ) );
  memcpy( port->device->hw_addr, HW_ADDR, sizeof( port->device->hw_addr ) );
  will_return( mock_create_ether_device, port->device );

  expect_value( mock_send_for_notify_port_config, port_no, PORT_NO );
  expect_value( mock_send_for_notify_port_config, reason, OFPPR_ADD );

  char *device_name = xstrdup( DEV_NAME );
  ret = add_port( PORT_NO, device_name );
  xfree( device_name );
}
Exemplo n.º 4
0
void
ui_current_print_formatted_line_expect(char show_char, int attrs, char *message)
{
    expect_value(_mock_ui_current_print_formatted_line, show_char, show_char);
    expect_value(_mock_ui_current_print_formatted_line, attrs, attrs);
    expect_string(_mock_ui_current_print_formatted_line, output, message);
}
Exemplo n.º 5
0
static void
test_handle_packet_in_lookup_failed() {
  setup();

  uint64_t datapath_id = 0x101;
  uint32_t transaction_id = 1234;
  uint32_t buffer_id = 0;
  uint16_t total_len = 0;
  uint32_t in_port32 = 1;
  uint8_t reason = 0;
  buffer *data;
  void *user_data = NULL;

  data = alloc_buffer();

  expect_not_value( mock_set_match_from_packet, match, NULL );
  expect_value( mock_set_match_from_packet, in_port32, in_port32 );
  expect_value( mock_set_match_from_packet, wildcards, 0 );
  expect_value( mock_set_match_from_packet, packet, data );
  will_return_void( mock_set_match_from_packet );

  expect_not_value( mock_lookup_match_entry, match, NULL );
  will_return( mock_lookup_match_entry, NULL );

  handle_packet_in( datapath_id, transaction_id, buffer_id, total_len,
    ( uint16_t ) in_port32, reason, data, user_data );

  free_buffer( data );

  teardown();
}
Exemplo n.º 6
0
void
presence_update_expect(resource_presence_t presence, char *msg, int idle)
{
    expect_value(_mock_presence_update, status, presence);
    expect_string(_mock_presence_update, msg, msg);
    expect_value(_mock_presence_update, idle, idle);
}
Exemplo n.º 7
0
/*
 * Test that the ExecWorkFile struct is allocated in TopMemoryContext
 */
void
test__ExecWorkFile_Create__InTopMemContext(void **state)
{
	char *test_filename = "foo";

	will_return(WorkfileQueryspace_AddWorkfile, true);

	expect_value(BufFileCreateFile, fileName, test_filename);
	expect_value(BufFileCreateFile, delOnClose, true);
	expect_value(BufFileCreateFile, interXact, false);
	will_return(BufFileCreateFile, NULL);

	expect_value(BufFileSetWorkfile, buffile, NULL);
	will_be_called(BufFileSetWorkfile);
	/*
	 * Create a new memory context, so that we can distinguish it from
	 * TopMemoryContext.
	 */
	CurrentMemoryContext =
	  AllocSetContextCreate(TopMemoryContext,
				"mock test context",
				ALLOCSET_DEFAULT_MINSIZE,
				ALLOCSET_DEFAULT_INITSIZE,
				ALLOCSET_DEFAULT_MAXSIZE);

	/*
	 * ExecWorkFile_Create will call our mocked palloc0 function execWorkfile__palloc0_mock
	 * and our mocked pstrdup function execWorkfile_pstrdup_mock.
	 * These functions will assert that the allocation of the result happens
	 * in the TopMemoryContext.
	 */
	ExecWorkFile *ewf = ExecWorkFile_Create(test_filename, BUFFILE, true /* delOnClose */, 0 /* compressType */);

}
Exemplo n.º 8
0
/*
 * Test failure to allocate bitmap buffer for child
 */
void test_cbt_util_coalesce_child_bitmap_malloc_failure(void **state)
{
	int result;
	uint64_t disk_size, file_size;
	char* args[] = { "cbt-util", "coalesce", "-p", "test_parent.log", "-c" , "test_child.log"};
	void *log_meta;

  	disk_size = 2199023255552; //2TB
	file_size = bitmap_size(disk_size) + sizeof(struct cbt_log_metadata);
	log_meta = malloc(file_size);
	((struct cbt_log_metadata*)log_meta)->size = disk_size;
	FILE *parent_log = fmemopen((void*)log_meta, file_size, "r");
	FILE *child_log = fmemopen((void*)log_meta, file_size, "r+");

	will_return(__wrap_fopen, parent_log);
	expect_value(__wrap_fclose, fp, parent_log);
	will_return(__wrap_fopen, child_log);
	expect_value(__wrap_fclose, fp, child_log);

	malloc_succeeds(true);
	malloc_succeeds(true);
	malloc_succeeds(true);
	malloc_succeeds(false);

	result = cbt_util_coalesce(6, args);
	assert_int_equal(result, -ENOMEM);

	disable_malloc_mock();
	free(log_meta);
}
Exemplo n.º 9
0
/*
 * Test failure to read bitmap from child log file
 */
void test_cbt_util_coalesce_child_no_bitmap_data_failure(void **state)
{
	int result;
	char* args[] = { "cbt-util", "coalesce", "-p", "test_parent.log", "-c" , "test_child.log"};
	void *parent_meta;
	void *child_meta;
	uint64_t disk_size, file_size;

	disk_size = 2199023255552; //2TB
	file_size = bitmap_size(disk_size) + sizeof(struct cbt_log_metadata);

	parent_meta = malloc(file_size);
	child_meta = malloc(sizeof(struct cbt_log_metadata));
	//Intialise size in metadata file
	((struct cbt_log_metadata*)parent_meta)->size = disk_size; 
	((struct cbt_log_metadata*)child_meta)->size = disk_size;
	FILE *parent_log = fmemopen((void*)parent_meta, file_size, "r");
	FILE *child_log = fmemopen((void*)child_meta,
							sizeof(struct cbt_log_metadata), "r+");

	will_return(__wrap_fopen, parent_log);
	expect_value(__wrap_fclose, fp, parent_log);
	will_return(__wrap_fopen, child_log);
	expect_value(__wrap_fclose, fp, child_log);

	result = cbt_util_coalesce(6, args);
	assert_int_equal(result, -EIO);

	free(parent_meta);
	free(child_meta);
}
Exemplo n.º 10
0
/*
 * Test failure when parent bitmap is larger than child bitmap
 */
void test_cbt_util_coalesce_larger_parent_bitmap_failure(void **state)
{
	int result;
	char* args[] = { "cbt-util", "coalesce", "-p", "test_parent.log", "-c" , "test_child.log"};
	void *parent_meta;
	void *child_meta;

	parent_meta = malloc(sizeof(struct cbt_log_metadata));
	child_meta  = malloc(sizeof(struct cbt_log_metadata));

	((struct cbt_log_metadata *)parent_meta)->size = 1310720;
	((struct cbt_log_metadata *)child_meta)->size = 655360;

	FILE *parent_log = fmemopen((void*)parent_meta,
								sizeof(struct cbt_log_metadata), "r");
	FILE *child_log = fmemopen((void*)child_meta,
								sizeof(struct cbt_log_metadata), "r");

	will_return(__wrap_fopen, parent_log);
	expect_value(__wrap_fclose, fp, parent_log);
	will_return(__wrap_fopen, child_log);
	expect_value(__wrap_fclose, fp, child_log);

	result = cbt_util_coalesce(6, args);
	assert_int_equal(result, -EINVAL);

	free(parent_meta);
	free(child_meta);
}
Exemplo n.º 11
0
/*
 * Test failure to malloc cbt_log_metadata structure for child
 */
void test_cbt_util_coalesce_child_log_malloc_failure(void **state)
{
	int result;
	char* args[] = { "cbt-util", "coalesce", "-p", "test_parent.log", "-c" , "test_child.log"};
	
	void *log_meta;

	log_meta = malloc(sizeof(struct cbt_log_metadata));
	FILE *parent_log = fmemopen((void*)log_meta,
								sizeof(struct cbt_log_metadata), "r");
	FILE *child_log = fmemopen((void*)log_meta,
								sizeof(struct cbt_log_metadata), "r");

	will_return(__wrap_fopen, parent_log);
	expect_value(__wrap_fclose, fp, parent_log);

	will_return(__wrap_fopen, child_log);
	expect_value(__wrap_fclose, fp, child_log);

	malloc_succeeds(true);
	malloc_succeeds(false);

	result = cbt_util_coalesce(6, args);

	assert_int_equal(result, -ENOMEM);

	disable_malloc_mock();
	free(log_meta);
}
Exemplo n.º 12
0
void cmd_connect_with_port_when_provided(void **state)
{
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "*****@*****.**", "port", "5432", NULL };

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_string(accounts_get_account, name, "*****@*****.**");
    will_return(accounts_get_account, NULL);

    will_return(ui_ask_password, strdup("password"));

    expect_cons_show("Connecting as [email protected]");

    expect_string(jabber_connect_with_details, jid, "*****@*****.**");
    expect_string(jabber_connect_with_details, passwd, "password");
    expect_value(jabber_connect_with_details, altdomain, NULL);
    expect_value(jabber_connect_with_details, port, 5432);
    will_return(jabber_connect_with_details, JABBER_CONNECTING);

    gboolean result = cmd_connect(NULL, args, *help);
    assert_true(result);

    free(help);
}
Exemplo n.º 13
0
void
test_init_log_opens_syslog() {
  const char *ident = "tetris";
  expect_string( mock_openlog, ident, ident );
  expect_value( mock_openlog, option, LOG_NDELAY );
  expect_value( mock_openlog, facility, LOG_USER );
  init_log( ident, get_trema_tmp(), LOGGING_TYPE_SYSLOG );
  assert_true( syslog_initialized );
}
Exemplo n.º 14
0
static void
setup_logger_syslog() {
  setup();
  const char *ident = "log_test.c";
  expect_string( mock_openlog, ident, ident );
  expect_value( mock_openlog, option, LOG_NDELAY );
  expect_value( mock_openlog, facility, LOG_USER );
  init_log( ident, get_trema_tmp(), LOGGING_TYPE_SYSLOG );
}
Exemplo n.º 15
0
static void
expect_lwlock(LWLockMode lockmode)
{
	expect_value(LWLockAcquire, l, SyncRepLock);
	expect_value(LWLockAcquire, mode, lockmode);
	will_return(LWLockAcquire, true);

	expect_value(LWLockRelease, l, SyncRepLock);
	will_be_called(LWLockRelease);
}
Exemplo n.º 16
0
static void
test_handle_packet_in_send_failed() {
  setup();

  uint64_t datapath_id = 0x101;
  uint32_t transaction_id = 1234;
  uint32_t buffer_id = 0;
  uint32_t total_len32 = 0;
  uint32_t in_port32 = 1;
  uint32_t reason32 = 0;
  buffer *data;
  void *user_data = NULL;

  match_entry match_entry;
  buffer *buf;

  data = alloc_buffer();
  expect_not_value( mock_set_match_from_packet, match, NULL );
  expect_value( mock_set_match_from_packet, in_port32, in_port32 );
  expect_value( mock_set_match_from_packet, wildcards, 0 );
  expect_value( mock_set_match_from_packet, packet, data );
  will_return_void( mock_set_match_from_packet );

  memset( &match_entry, 0, sizeof( match_entry ) );
  match_entry.service_name = ( char * ) ( uintptr_t ) ( "service_name" );
  match_entry.entry_name = ( char * ) ( uintptr_t ) ( "entry_name" );
  expect_not_value( mock_lookup_match_entry, match, NULL );
  will_return( mock_lookup_match_entry, &match_entry );

  buf = alloc_buffer();
  expect_value( mock_create_packet_in, transaction_id, transaction_id );
  expect_value( mock_create_packet_in, buffer_id, buffer_id );
  expect_value( mock_create_packet_in, total_len32, total_len32 );
  expect_value( mock_create_packet_in, in_port32, in_port32 );
  expect_value( mock_create_packet_in, reason32, reason32 );
  expect_value( mock_create_packet_in, data, data );
  will_return( mock_create_packet_in, buf );

  expect_string( mock_send_message, service_name, match_entry.service_name );
  expect_value( mock_send_message, tag32, MESSENGER_OPENFLOW_MESSAGE );
  expect_not_value( mock_send_message, data, NULL );
  expect_not_value( mock_send_message, len, 0 );
  will_return( mock_send_message, false );

  expect_string( mock_error, buffer, "Failed to send a message to service_name ( entry_name = entry_name, match = wildcards = 0, in_port = 1, dl_src = 00:00:00:00:00:00, dl_dst = 00:00:00:00:00:00, dl_vlan = 0, dl_vlan_pcp = 0, dl_type = 0, nw_tos = 0, nw_proto = 0, nw_src = 0.0.0.0, nw_dst = 0.0.0.0, tp_src = 0, tp_dst = 0 )." );
  will_return_void( mock_error );

  handle_packet_in( datapath_id, transaction_id, buffer_id, ( uint16_t ) total_len32,
                    ( uint16_t ) in_port32, ( uint8_t ) reason32, data, user_data );

  free_buffer( data );

  teardown();
}
Exemplo n.º 17
0
void
test_build_http_headers_empty_user_error(void **state) {

	/* setup mock data and expectations */
	PxfInputData *input = (PxfInputData *) palloc0(sizeof(PxfInputData));
	CHURL_HEADERS headers = (CHURL_HEADERS) palloc0(sizeof(CHURL_HEADERS));
	GPHDUri *gphd_uri = (GPHDUri *) palloc0(sizeof(GPHDUri));
	Relation rel = (Relation) palloc0(sizeof(RelationData));

	ExtTableEntry ext_tbl;
	struct tupleDesc tuple;

	input->headers = headers;
	input->gphduri = gphd_uri;
	input->rel = NULL;

	gphd_uri->uri = "testuri";

	expect_any(external_set_env_vars, extvar);
	expect_string(external_set_env_vars, uri, gphd_uri->uri);
	expect_value(external_set_env_vars, csv, false);
	expect_value(external_set_env_vars, escape, NULL);
	expect_value(external_set_env_vars, quote, NULL);
	expect_value(external_set_env_vars, header, false);
	expect_value(external_set_env_vars, scancounter, 0);

	struct extvar_t mock_extvar;
	mock_extvar.GP_USER = "";
	snprintf(mock_extvar.GP_SEGMENT_ID, sizeof(mock_extvar.GP_SEGMENT_ID), "SegId");
	snprintf(mock_extvar.GP_SEGMENT_COUNT, sizeof(mock_extvar.GP_SEGMENT_COUNT), "10");
	snprintf(mock_extvar.GP_XID, sizeof(mock_extvar.GP_XID), "20");
	will_assign_memory(external_set_env_vars, extvar, &mock_extvar, sizeof(extvar_t));
	will_be_called(external_set_env_vars);

	MemoryContext old_context = CurrentMemoryContext;
	PG_TRY();
	{
		build_http_headers(input);
		assert_false("Expected Exception");
	}
	PG_CATCH();
	{
		MemoryContextSwitchTo(old_context);
		ErrorData  *edata = CopyErrorData();

		assert_true(edata->elevel == ERROR);
		char	   *expected_message = pstrdup("User identity is unknown");

		assert_string_equal(edata->message, expected_message);
		pfree(expected_message);
	}
	PG_END_TRY();
}
Exemplo n.º 18
0
void expect_external_vars()
{
	expect_any(external_set_env_vars, extvar);
	expect_string(external_set_env_vars, uri, gphd_uri->uri);
	expect_value(external_set_env_vars, csv, false);
	expect_value(external_set_env_vars, escape, NULL);
	expect_value(external_set_env_vars, quote, NULL);
	expect_value(external_set_env_vars, header, false);
	expect_value(external_set_env_vars, scancounter, 0);
	will_assign_memory(external_set_env_vars, extvar, mock_extvar, sizeof(extvar_t));
	will_be_called(external_set_env_vars);
}
Exemplo n.º 19
0
void cmd_account_add_adds_account(void **state)
{
    gchar *args[] = { "add", "new_account", NULL };

    expect_string(accounts_add, jid, "new_account");
    expect_value(accounts_add, altdomain, NULL);
    expect_value(accounts_add, port, 0);
    expect_cons_show("Account created.");
    expect_cons_show("");

    gboolean result = cmd_account_add(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
Exemplo n.º 20
0
void
jabber_connect_with_details_expect_and_return(char *jid,
    char *password, char *altdomain, int port, jabber_conn_status_t result)
{
    expect_string(_mock_jabber_connect_with_details, jid, jid);
    expect_string(_mock_jabber_connect_with_details, passwd, password);
    if (altdomain == NULL) {
        expect_value(_mock_jabber_connect_with_details, altdomain, NULL);
    } else {
        expect_string(_mock_jabber_connect_with_details, altdomain, altdomain);
    }
    expect_value(_mock_jabber_connect_with_details, port, port);
    will_return(_mock_jabber_connect_with_details, result);
}
Exemplo n.º 21
0
static void
test_daemonize_succeed() {
  will_return( mock_chdir, 0 );
  will_return( mock_fork, 1234 );
  will_return( mock_setsid, 4321 );

  expect_value( mock_exit, status, EXIT_SUCCESS );
  expect_value( mock_umask, mode, 0 );
  expect_value( mock_close, fd, STDIN_FILENO );
  expect_value( mock_close, fd, STDOUT_FILENO );
  expect_value( mock_close, fd, STDERR_FILENO );

  daemonize( "/" );
}
Exemplo n.º 22
0
static void
test_write_pid_fail_if_open_fail() {
  will_return( mock_open, -1 );

  // Test if correctly opened.
  char path[] = "/home/yasuhito/trema/tmp/chess.pid";
  expect_string( mock_open, pathname, path );
  expect_value( mock_open, flags, ( O_RDWR | O_CREAT ) );
  expect_value( mock_open, mode, 0600 );

  expect_string( mock_die, message, "Could not create a PID file: /home/yasuhito/trema/tmp/chess.pid" );

  expect_assert_failure( write_pid( "/home/yasuhito/trema/tmp", "chess" ) );
}
Exemplo n.º 23
0
void cmd_join_uses_account_mucservice_when_no_service_specified(void **state)
{
    char *account_name = "an_account";
    char *room = "room";
    char *nick = "bob";
    char *account_service = "conference.server.org";
    char *expected_room = "*****@*****.**";
    gchar *args[] = { room, "nick", nick, NULL };
    ProfAccount *account = account_new(account_name, "*****@*****.**", NULL, NULL,
        TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

    muc_init();

    will_return(connection_get_status, JABBER_CONNECTED);
    will_return(session_get_account_name, account_name);

    expect_string(accounts_get_account, name, account_name);
    will_return(accounts_get_account, account);

    expect_string(presence_join_room, room, expected_room);
    expect_string(presence_join_room, nick, nick);
    expect_value(presence_join_room, passwd, NULL);

    gboolean result = cmd_join(NULL, CMD_JOIN, args);
    assert_true(result);
}
Exemplo n.º 24
0
static void
test_secure_channel_accept_accept_failed() {
  int listen_fd = 0;

  listener_info.listen_fd = listen_fd;

  expect_value( mock_accept, sockfd, listen_fd );
  expect_not_value( mock_accept, addr, NULL );
  expect_not_value( mock_accept, addrlen, NULL );
  expect_value( mock_accept, *addrlen, sizeof( struct sockaddr_in ) );
  will_return( mock_accept, -1 );

  secure_channel_accept( &listener_info );

  teardown();
}
Exemplo n.º 25
0
static void
test_switch_manager_main_help_and_exit() {
  setup();

  char *argv[] = {
      ( char * )( uintptr_t )"switch_manager",
      ( char * )( uintptr_t )"-x",
      NULL,
    };
  int argc = ARRAY_SIZE( argv ) - 1;
  int ret;

  will_return( mock_printf2, 1 );
  will_return( mock_get_current_dir_name, strdup( "/tmp" ) );
  will_return_void( mock_init_trema );
  will_return( mock_get_trema_home, strdup( "/tmp" ) );

  expect_value( mock_exit, status, EXIT_SUCCESS );
  will_return_void( mock_exit );

  optind = 1;
  ret = switch_manager_main( argc, argv );

  assert_true( ret == EXIT_FAILURE );

  teardown();
}
Exemplo n.º 26
0
static void
test_wait_child_wait3_zero_return() {
  setup();

  expect_not_value( mock_wait3, status, NULL );
  expect_value( mock_wait3, options, WNOHANG );
  expect_value( mock_wait3, rusage, NULL );

  mock_wait3_status = 0;

  will_return( mock_wait3, 0 );

  wait_child();

  teardown();
}
Exemplo n.º 27
0
void
ui_switch_win_expect_and_return(int given_i, gboolean result)
{
    ui_switch_win = _mock_ui_switch_win;
    expect_value(_mock_ui_switch_win, i, given_i);
    will_return(_mock_ui_switch_win, result);
}
Exemplo n.º 28
0
void
ui_room_join_expect(char *room, gboolean focus)
{
    ui_room_join = _mock_ui_room_join;
    expect_string(_mock_ui_room_join, room, room);
    expect_value(_mock_ui_room_join, focus, focus);
}
Exemplo n.º 29
0
static void torture_log_callback(void **state)
{
    struct test_mock_state t = {
        .executed = 0,
    };

    (void)state; /* unused */

    ssh_set_log_callback(test_mock_ssh_logging_callback);
    ssh_set_log_userdata(&t);
    ssh_set_log_level(1);

    expect_value(test_mock_ssh_logging_callback, priority, 1);
    expect_string(test_mock_ssh_logging_callback, function, "torture_log_callback");
    expect_string(test_mock_ssh_logging_callback, buffer, "torture_log_callback: test");

    SSH_LOG(SSH_LOG_WARN, "test");

    assert_int_equal(t.executed, 1);
}

int torture_run_tests(void) {
    int rc;
    UnitTest tests[] = {
        unit_test_setup_teardown(torture_callbacks_size, setup, teardown),
        unit_test_setup_teardown(torture_callbacks_exists, setup, teardown),
        unit_test(torture_log_callback),
    };

    ssh_init();
    torture_filter_tests(tests);
    rc=run_tests(tests);
    ssh_finalize();
    return rc;
}
Exemplo n.º 30
0
/*
 * Test that the spill_file->file_info->wfile field is allocated
 * and initialized during normal execution (no exception thrown).
 */
void
test__getSpillFile__Initialize_wfile_success(void **state)
{
	int alloc_size = 0;
	int file_no = 0;
	int branching_factor = 32;
	ExecWorkFile *ewfile = (ExecWorkFile *) palloc0(sizeof(ExecWorkFile));
	workfile_set *work_set = (workfile_set *) palloc0(sizeof(workfile_set));
	SpillSet *spill_set = (SpillSet *) palloc0(sizeof(SpillSet) + (branching_factor-1) * sizeof (SpillFile));

	SpillFile *spill_file = &spill_set->spill_files[file_no];
	spill_file->file_info = NULL;

	expect_value(workfile_mgr_create_file, work_set, work_set);
	will_return(workfile_mgr_create_file, ewfile);

	getSpillFile(work_set, spill_set, file_no, &alloc_size);

	assert_true(spill_file->file_info != NULL);
	assert_int_equal(spill_file->file_info->total_bytes, 0);
	assert_int_equal(spill_file->file_info->ntuples, 0);
	assert_int_equal(alloc_size, BATCHFILE_METADATA);

	/*
	 * During normal execution, wfile should be initialized with
	 * the result of workfile_mgr_create_wfile, a valid ExecWorkFile pointer
	 */
	assert_true(spill_file->file_info->wfile == ewfile);
}