Exemple #1
0
void cmd_account_show_message_for_invalid_otr_policy(void **state)
{
    gchar *args[] = { "set", "a_account", "otr", "bad_otr_policy", NULL };

    expect_any(accounts_account_exists, account_name);
    will_return(accounts_account_exists, TRUE);

    expect_cons_show("OTR policy must be one of: manual, opportunistic or always.");

    gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
Exemple #2
0
void cmd_account_set_eval_password_sets_eval_password(void **state)
{
    gchar *args[] = { "set", "a_account", "eval_password", "a_password", NULL };
    ProfAccount *account = account_new("a_account", NULL, NULL, NULL,
    TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

    expect_any(accounts_account_exists, account_name);
    will_return(accounts_account_exists, TRUE);

    expect_string(accounts_get_account, name, "a_account");
    will_return(accounts_get_account, account);

    expect_string(accounts_set_eval_password, account_name, "a_account");
    expect_string(accounts_set_eval_password, value, "a_password");

    expect_cons_show("Updated eval_password for account a_account");
    expect_cons_show("");

    gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
Exemple #3
0
void cmd_account_set_jid_shows_message_for_malformed_jid(void **state)
{
    gchar *args[] = { "set", "a_account", "jid", "@malformed", NULL };

    expect_any(accounts_account_exists, account_name);
    will_return(accounts_account_exists, TRUE);

    expect_cons_show("Malformed jid: @malformed");

    gboolean result = cmd_account(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
Exemple #4
0
static void
test_read_pid_fail_if_access_fail() {
  // Test if correctly access.
  char path[] = "/home/yasuhito/trema/tmp/chess.pid";
  expect_string( mock_access, pathname, path );
  expect_value( mock_access, mode, R_OK );
  will_return( mock_access, -1 );

  // Go
  pid_t pid = read_pid( "/home/yasuhito/trema/tmp", "chess" );
  assert_true( pid == -1 );
}
Exemple #5
0
static void
test_write_pid_fail_if_lockf_fail() {
  will_return( mock_open, 1111 );
  will_return( mock_lockf, -1 );

  // Test if correctly locked.
  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 );

  // Test if correctly locked.
  expect_value( mock_lockf, fd, 1111 );
  expect_value( mock_lockf, cmd, F_TLOCK );
  expect_value( mock_lockf, len, 0 );

  // lockf_return_value = -1;
  expect_string( mock_die, message, "Could not acquire a lock on a PID file: /home/yasuhito/trema/tmp/chess.pid" );

  expect_assert_failure( write_pid( "/home/yasuhito/trema/tmp", "chess" ) );
}
void cmd_account_set_status_shows_message_when_invalid_status(void **state)
{
    gchar *args[] = { "set", "a_account", "status", "bad_status", NULL };

    expect_any(accounts_account_exists, account_name);
    will_return(accounts_account_exists, TRUE);

    expect_cons_show("Invalid status: bad_status");
    expect_cons_show("");

    gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state)
{
    gchar *args[] = { "disable", "account_name", NULL };

    expect_any(accounts_disable, name);
    will_return(accounts_disable, FALSE);

    expect_cons_show("No such account: account_name");
    expect_cons_show("");

    gboolean result = cmd_account_disable(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
void cmd_account_disable_disables_account(void **state)
{
    gchar *args[] = { "disable", "account_name", NULL };

    expect_string(accounts_disable, name, "account_name");
    will_return(accounts_disable, TRUE);

    expect_cons_show("Account disabled.");
    expect_cons_show("");

    gboolean result = cmd_account_disable(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
/*
 * Test failure to set file pointer to start of bitmap area
 */
void test_cbt_util_coalesce_set_file_pointer_failure(void **state)
{
	int result;
	int file_size;
	char* args[] = { "cbt-util", "coalesce", "-p", "test_parent.log", "-c" , "test_child.log"};
	void *parent_data;
	void *child_data;
	uint64_t size = 4194304;

	uint64_t bmsize = bitmap_size(size);
	file_size = sizeof(struct cbt_log_metadata) + bmsize;
	parent_data = malloc(file_size);
	child_data = malloc(file_size);

	//Intialise size in metadata file
	((struct cbt_log_metadata*)parent_data)->size = size;
	//Fill bitmap with random bytes
	memcpy(parent_data + sizeof(struct cbt_log_metadata), (void*)memcpy, bmsize );
	FILE *parent_log = fmemopen((void*)parent_data, file_size, "w+");

	//Intialise size in metadata file
	((struct cbt_log_metadata*)child_data)->size = size;
	//Fill bitmap with random bytes
	memcpy(child_data + sizeof(struct cbt_log_metadata), (void*)memcpy, bmsize );
	FILE *child_log = fmemopen((void*)child_data, file_size, "w+");

	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);
	
	fail_fseek(EIO);

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

	free(parent_data);
	free(child_data);
}
/*
 * Test failure to read log metadata for child
 */
void test_cbt_util_coalesce_no_child_meta_failure(void **state)
{
	int result;
	char* args[] = { "cbt-util", "coalesce", "-p", "test_parent.log", "-c" , "test_child.log"};
	void *parent_meta;
	void *child_meta[1];

	parent_meta = malloc(sizeof(struct cbt_log_metadata));
	FILE *parent_log = fmemopen((void*)parent_meta,
								sizeof(struct cbt_log_metadata), "r");
	FILE *child_log = fmemopen((void*)child_meta, 1, "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);
}
Exemple #11
0
/*
 * Mocked object initializations required for dispatchPlan.
 */
void
_init_cdbdisp_dispatchPlan(QueryDesc *queryDesc)
{
	queryDesc->estate = (struct EState *)palloc0(sizeof(struct EState));
	queryDesc->estate->es_sliceTable =
		(struct SliceTable *) palloc0(sizeof(struct SliceTable));
	queryDesc->operation = CMD_NOTHING;
	queryDesc->plannedstmt = (PlannedStmt *)palloc0(sizeof(PlannedStmt));

	will_be_called(clear_relsize_cache);
	expect_any(RootSliceIndex, estate);
	will_return(RootSliceIndex,0);
}
void cmd_account_clear_shows_message_when_account_doesnt_exist(void **state)
{
    gchar *args[] = { "clear", "a_account", "a_property", NULL };

    expect_string(accounts_account_exists, account_name, "a_account");
    will_return(accounts_account_exists, FALSE);

    expect_cons_show("Account a_account doesn't exist");
    expect_cons_show("");

    gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
Exemple #13
0
void 
test__AOSegmentFilePathNameLen(void **state) 
{
	RelationData reldata;
	char* basepath = "base/21381/123";

	expect_any(relpath, &rnode);
	will_return(relpath, strdup(basepath));

	int r = AOSegmentFilePathNameLen(&reldata);

	assert_in_range(r, strlen(basepath) + 3, strlen(basepath) + 10);
}
Exemple #14
0
static void test_with_connection_status(jabber_conn_status_t status)
{
    CommandHelp *help = malloc(sizeof(CommandHelp));

    will_return(jabber_get_connection_status, status);

    expect_cons_show("You are not currently connected.");

    gboolean result = cmd_rooms(NULL, NULL, *help);
    assert_true(result);

    free(help);
}
Exemple #15
0
static void test_with_connection_status(jabber_conn_status_t status)
{
    CommandHelp *help = malloc(sizeof(CommandHelp));

    will_return(jabber_get_connection_status, status);

    expect_cons_show("You are either connected already, or a login is in process.");

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

    free(help);
}
void cmd_account_show_shows_message_when_account_does_not_exist(void **state)
{
    gchar *args[] = { "show", "account_name", NULL };

    expect_any(accounts_get_account, name);
    will_return(accounts_get_account, NULL);

    expect_cons_show("No such account.");
    expect_cons_show("");

    gboolean result = cmd_account_show(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
Exemple #17
0
void cmd_connect_connects_with_account(void **state)
{
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "jabber_org", NULL };
    ProfAccount *account = account_new("jabber_org", "*****@*****.**", "password", NULL,
        TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);

    expect_any(accounts_get_account, name);
    will_return(accounts_get_account, account);

    expect_cons_show("Connecting with account jabber_org as [email protected]");

    expect_memory(jabber_connect_with_account, account, account, sizeof(account));
    will_return(jabber_connect_with_account, JABBER_CONNECTING);

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

    free(help);
}
void cmd_account_clear_shows_message_when_invalid_property(void **state)
{
    gchar *args[] = { "clear", "a_account", "badproperty", NULL };

    expect_any(accounts_account_exists, account_name);
    will_return(accounts_account_exists, TRUE);

    expect_cons_show("Invalid property: badproperty");
    expect_cons_show("");

    gboolean result = cmd_account_clear(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
void cmd_account_set_last_priority_shows_message(void **state)
{
    gchar *args[] = { "set", "a_account", "last", "10", NULL };

    expect_any(accounts_account_exists, account_name);
    will_return(accounts_account_exists, TRUE);

    expect_cons_show("Invalid property: last");
    expect_cons_show("");

    gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
    assert_true(result);
}
/**
 * Tests the function coco_suite_get_next_problem_index.
 */
static void test_coco_suite_get_next_problem_index(void **state) {

  long prob_index;

  expect_string(__wrap_suite_bbob2009_get_next_problem_index, problem_index, -1);
  will_return(__wrap_suite_bbob2009_get_next_problem_index, 2);

  prob_index = coco_suite_get_next_problem_index("suite_bbob2009", -1, NULL);

  assert_true(prob_index == 2);

  (void)state; /* unused */
}
Exemple #21
0
static void
test_absolute_path_access_failed() {
  setup();

  char *path;

  will_return( mock_access, -1 );

  path = absolute_path( "/tmp", "/file" );
  assert_true( path == NULL );

  teardown();
}
Exemple #22
0
static void
test_wait_child_wait3_signaled() {
  setup();

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

  mock_wait3_status = 3;

  will_return( mock_wait3, 4444 );

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

  will_return( mock_wait3, 0 );

  wait_child();

  teardown();
}
Exemple #23
0
static void
test_wait_child_wait3_coredump() {
  setup();

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

  mock_wait3_status = 0x80 | 11;

  will_return( mock_wait3, 5678 );

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

  will_return( mock_wait3, 0 );

  wait_child();

  teardown();
}
Exemple #24
0
void cmd_otr_start_shows_message_when_no_key(void **state)
{
    char *recipient = "*****@*****.**";
    gchar *args[] = { "start", NULL };

    will_return(jabber_get_connection_status, JABBER_CONNECTED);
    will_return(otr_key_loaded, FALSE);

    ProfWin window;
    window.type = WIN_CHAT;
    ProfChatWin chatwin;
    chatwin.window = window;
    chatwin.barejid = recipient;
    chatwin.memcheck = PROFCHATWIN_MEMCHECK;
    chatwin.pgp_send = FALSE;
    chatwin.is_otr = FALSE;

    expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");

    gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args);
    assert_true(result);
}
/*
 * This test exercises the success path through the
 * access_broker_send_command function.
 */
static void
access_broker_send_command_success (void **state)
{
    test_data_t *data = (test_data_t*)*state;
    TSS2_RC rc;
    Connection *connection;

    will_return (__wrap_tcti_echo_transmit, TSS2_RC_SUCCESS);
    will_return (__wrap_tcti_echo_receive,  TSS2_RC_SUCCESS);
    data->response = access_broker_send_command (data->broker, data->command, &rc);
    /* the response code should be the one we passed to __wrap_tcti_echo_receive */
    assert_int_equal (rc, TSS2_RC_SUCCESS);
    /* the Tpm2Response object we get back should have the same RC */
    assert_int_equal (tpm2_response_get_code (data->response), TSS2_RC_SUCCESS);
    /**
     * the Tpm2Response object we get back should have the same connection as
     * the Tpm2Command we tried to send.
     */
    connection = tpm2_response_get_connection (data->response);
    assert_int_equal (connection, data->connection);
    g_object_unref (connection);
}
Exemple #26
0
/*
 * Test that the ExecWorkFile struct is allocated in TopMemoryContext
 */
void
test__ExecWorkFile_Open__InTopMemContext(void **state)
{
	char *test_filename = "foo";
	BufFile *bfile = (BufFile *) 0xbffffffe;

	expect_value(BufFileOpenFile, fileName, test_filename);
	expect_value(BufFileOpenFile, create, false);
	expect_value(BufFileOpenFile, delOnClose, false);
	expect_value(BufFileOpenFile, interXact, true);
	will_return(BufFileOpenFile, bfile);

	expect_value(BufFileSetWorkfile, buffile, bfile);
	will_be_called(BufFileSetWorkfile);

	expect_value(BufFileGetSize, buffile, bfile);
	will_return(BufFileGetSize, 0);

	/*
	 * 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_Open 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_Open(test_filename, BUFFILE, false /* delOnClose */, 0 /* compressType */);

}
Exemple #27
0
static void
test_read_pid_fail_if_kill_fail_with_EPERM() {
  // Test if correctly access.
  char path[] = "/home/yasuhito/trema/tmp/chess.pid";
  expect_string( mock_access, pathname, path );
  expect_value( mock_access, mode, R_OK );
  will_return( mock_access, 0 );

  // Test if correctly opened.
  int pid_file_fd = 111;
  expect_string( mock_open, pathname, path );
  expect_value( mock_open, flags, O_RDONLY );
  expect_value( mock_open, mode, 0 );
  will_return( mock_open, pid_file_fd );

  // Test if correctly read.
  expect_value( mock_read, fd, pid_file_fd );
  expect_not_value( mock_read, buf, NULL );
  expect_value( mock_read, count, 10 - 1 );
  char valid_pid_string[] = "123\n";
  pid_t valid_pid = 123;
  read_buffer = valid_pid_string;
  read_length = strlen( valid_pid_string );
  will_return( mock_read, read_length );

  // Test if correctly read.
  expect_value( mock_kill, pid, valid_pid );
  expect_value( mock_kill, sig, 0 );
  errno = EPERM;
  will_return( mock_kill, -1 );

  // Test if correctly close.
  expect_value( mock_close, fd, pid_file_fd );

  // Go
  pid_t pid = read_pid( "/home/yasuhito/trema/tmp", "chess" );
  assert_true( pid == -1 );
}
Exemple #28
0
static void
test_secure_channel_accept_parent_succeeded() {
  setup();

  int listen_fd = 0;
  int accept_fd = 1;
  int pid = 1;	/* parent */

  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, accept_fd );

  will_return( mock_fork, pid );

  expect_value( mock_close, fd, accept_fd );
  will_return_void( mock_close );

  secure_channel_accept( &listener_info );
}
Exemple #29
0
static void
test_switch_manager_main_and_port_option_failed() {
  setup();

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

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

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

  assert_true( ret == EXIT_FAILURE );

  teardown();
}
Exemple #30
0
static void
test_absolute_path_absolute() {
  setup();

  char *path;

  will_return( mock_access, 0 );

  path = absolute_path( "/tmp", "/file" );
  assert_string_equal( path, "/file" );
  xfree( path );

  teardown();
}