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); }
void cmd_account_set_otr_sets_otr(void **state) { gchar *args[] = { "set", "a_account", "otr", "opportunistic", NULL }; expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); expect_string(accounts_set_otr_policy, account_name, "a_account"); expect_string(accounts_set_otr_policy, value, "opportunistic"); expect_cons_show("Updated OTR policy for account a_account: opportunistic"); expect_cons_show(""); gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); }
void cmd_account_set_status_sets_status_when_last(void **state) { gchar *args[] = { "set", "a_account", "status", "last", NULL }; expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); expect_string(accounts_set_login_presence, account_name, "a_account"); expect_string(accounts_set_login_presence, value, "last"); expect_cons_show("Updated login status for account a_account: last"); expect_cons_show(""); gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); }
void cmd_account_set_nick_sets_nick(void **state) { gchar *args[] = { "set", "a_account", "nick", "a_nick", NULL }; expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); expect_string(accounts_set_muc_nick, account_name, "a_account"); expect_string(accounts_set_muc_nick, value, "a_nick"); expect_cons_show("Updated muc nick for account a_account: a_nick"); expect_cons_show(""); gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); }
void cmd_account_set_jid_sets_barejid(void **state) { gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain", NULL }; expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); expect_string(accounts_set_jid, account_name, "a_account"); expect_string(accounts_set_jid, value, "a_local@a_domain"); expect_cons_show("Updated jid for account a_account: a_local@a_domain"); expect_cons_show(""); gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); }
void cmd_rooms_uses_account_default_when_no_arg(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); account->name = NULL; account->jid = NULL; account->password = NULL; account->eval_password = NULL; account->resource = NULL; account->server = NULL; account->last_presence = NULL; account->login_presence = NULL; account->muc_nick = NULL; account->otr_policy = NULL; account->otr_manual = NULL; account->otr_opportunistic = NULL; account->otr_always = NULL; account->pgp_keyid = NULL; account->muc_service = strdup("default_conf_server"); will_return(jabber_get_connection_status, JABBER_CONNECTED); will_return(jabber_get_account_name, "account_name"); expect_any(accounts_get_account, name); will_return(accounts_get_account, account); expect_string(iq_room_list_request, conferencejid, "default_conf_server"); gboolean result = cmd_rooms(NULL, args, *help); assert_true(result); free(help); }
void expect_and_return_bookmark_remove(char *expected_jid, gboolean removed) { expect_string(_mock_bookmark_remove, jid, expected_jid); will_return(_mock_bookmark_remove, removed); }
void cmd_connect_lowercases_argument(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "*****@*****.**", 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_any(jabber_connect_with_details, jid); expect_any(jabber_connect_with_details, passwd); expect_any(jabber_connect_with_details, altdomain); expect_any(jabber_connect_with_details, port); will_return(jabber_connect_with_details, JABBER_CONNECTING); gboolean result = cmd_connect(NULL, args, *help); assert_true(result); free(help); }
void cmd_otr_theirfp_shows_fingerprint(void **state) { char *recipient = "*****@*****.**"; char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE"; gchar *args[] = { "theirfp", NULL }; GString *message = g_string_new(recipient); g_string_append(message, "'s OTR fingerprint: "); g_string_append(message, fingerprint); 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 = TRUE; will_return(jabber_get_connection_status, JABBER_CONNECTED); expect_string(otr_get_their_fingerprint, recipient, recipient); will_return(otr_get_their_fingerprint, strdup(fingerprint)); expect_ui_current_print_formatted_line('!', 0, message->str); gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args); assert_true(result); g_string_free(message, TRUE); }
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); }
void expect_ui_current_print_formatted_line(char show_char, int attrs, char *message) { expect_value(ui_current_print_formatted_line, show_char, show_char); expect_value(ui_current_print_formatted_line, attrs, attrs); expect_string(ui_current_print_formatted_line, output, message); }
static void test_imap_receive_partial_line(void **state) { struct imap_connection *imap = malloc(sizeof(struct imap_connection)); imap_init(imap); imap->mode = RECV_LINE; const char *buffer = "a001 FOOB"; set_ab_recv_result((void *)buffer, strlen(buffer)); will_return(__wrap_ab_recv, strlen(buffer)); will_return(__wrap_poll, 0); will_return(__wrap_poll, 0); imap->poll[0].revents = POLLIN; imap_receive(imap); expect_string(__wrap_hashtable_get, key, "FOOBAR"); will_return(__wrap_hashtable_get, test_handler); const char *remaining_buffer = "AR\r\n"; set_ab_recv_result((void *)remaining_buffer, strlen(remaining_buffer)); will_return(__wrap_ab_recv, strlen(remaining_buffer)); imap_receive(imap); assert_int_equal(handler_called, 1); imap_close(imap); }
static void line(void) { #line 99 expect(99, __LINE__); #line 199 "foo" expect(199, __LINE__); expect_string("foo", __FILE__); }
/* This test will fail since the mock connect_to_database() will attempt to * retrieve a value for the parameter port which isn't specified by this * test function. */ static void test_connect_to_product_database_missing_parameter(void **state) { (void) state; /* unused */ expect_string(connect_to_database, url, "products.abcd.org"); will_return(connect_to_database, 0xDA7ABA53); assert_int_equal((size_t)connect_to_product_database(), 0xDA7ABA53); }
static void test_imap_receive_full_buffer(void **state) { struct imap_connection *imap = malloc(sizeof(struct imap_connection)); imap_init(imap); imap->mode = RECV_LINE; char buffer[4096]; memset(buffer, 'a', 4096); const char *cmd_1 = "a001 FOOBAR "; memcpy(buffer, cmd_1, strlen(cmd_1)); const char *cmd_2 = "\r\na002 FOOBAZ "; memcpy(buffer + 2048 + 128, cmd_2, strlen(cmd_2)); buffer[4094] = '\r'; buffer[4095] = '\n'; will_return(__wrap_poll, 0); will_return(__wrap_poll, 0); will_return(__wrap_poll, 0); will_return(__wrap_poll, 0); imap->poll[0].revents = POLLIN; set_ab_recv_result((void *)buffer, 1024); will_return(__wrap_ab_recv, 1024); imap_receive(imap); // First command (incomplete) set_ab_recv_result((void *)(buffer + 1024), 1024); will_return(__wrap_ab_recv, 1024); imap_receive(imap); // First command (incomplete) expect_string(__wrap_hashtable_get, key, "FOOBAR"); will_return(__wrap_hashtable_get, test_handler); set_ab_recv_result((void *)(buffer + 2048), 1024); will_return(__wrap_ab_recv, 1024); imap_receive(imap); // First command (complete), second command (incomplete) assert_int_equal(handler_called, 1); expect_string(__wrap_hashtable_get, key, "FOOBAZ"); will_return(__wrap_hashtable_get, test_handler); set_ab_recv_result((void *)(buffer + 2048), 1024); will_return(__wrap_ab_recv, 1024); imap_receive(imap); // Second command (complete) assert_int_equal(handler_called, 2); imap_close(imap); }
static void test_init_packetin_filter_interface_fails_if_already_initialized() { expect_string( mock_add_message_replied_callback, service_name, CLIENT_SERVICE_NAME ); will_return( mock_add_message_replied_callback, true ); init_packetin_filter_interface(); assert_false( init_packetin_filter_interface() ); }
void test_set_property( void** state ) { char* values[] = { "avalue" }; char buffer[ strlen( *values ) + sizeof( key ) + 1 ]; sprintf( buffer, "%s=%s", key, *values ); expect_string( dladm_parse_flow_props, str, buffer ); will_return( dladm_parse_flow_props, NULL ); will_return( dladm_parse_flow_props, DLADM_STATUS_OK ); expect_string( dladm_set_flowprop, flow, flow ); expect_string( dladm_set_flowprop, key, key ); will_return( dladm_set_flowprop, DLADM_STATUS_OK ); assert_int_equal( XBOW_STATUS_OK, set_property( flow, key, values, 1, temporary ) ); }
void test_reset_property_invalid_key( void** state ) { expect_string( dladm_parse_flow_props, str, key ); will_return( dladm_parse_flow_props, NULL ); will_return( dladm_parse_flow_props, ( int )( DLADM_STATUS_OK + 1 ) ); assert_int_not_equal( XBOW_STATUS_OK, reset_property( flow, key, temporary ) ); }
static void test_register_dl_type_filter() { setup(); uint32_t dl_type32 = 1; uint32_t priority32 = 2; expect_not_value( mock_insert_match_entry, ofp_match, NULL ); expect_value( mock_insert_match_entry, priority32, priority32 ); expect_string( mock_insert_match_entry, service_name, "service_name" ); expect_string( mock_insert_match_entry, entry_name, "entry_name" ); will_return_void( mock_insert_match_entry ); register_dl_type_filter( ( uint16_t ) dl_type32, ( uint16_t ) priority32, "service_name", "entry_name" ); teardown(); }
void test_removing_flow( void** state ) { expect_string( dladm_flow_remove, flow, flow ); expect_value( dladm_flow_remove, temporary, temporary ); will_return( dladm_flow_remove, DLADM_STATUS_OK ); assert_true( XBOW_STATUS_OK == remove_flow( flow, temporary ) ); }
/* This test will fail since the expected URL is different to the URL that is * passed to connect_to_database() by connect_to_product_database(). */ static void test_connect_to_product_database_bad_url(void **state) { (void) state; /* unused */ expect_string(connect_to_database, url, "products.abcd.com"); expect_value(connect_to_database, port, 322); will_return(connect_to_database, 0xDA7ABA53); assert_int_equal((int)(size_t)connect_to_product_database(), 0xDA7ABA53); }
void include(void) { #include "macro1.h" expect_string("macro1", MACRO_1); #define MACRO_2_FILE "macro2.h" #include MACRO_2_FILE expect_string("macro2", MACRO_2); #define STDBOOL_H_FILE <stdbool.h> #ifdef __STDBOOL_H # error test failed #endif #include STDBOOL_H_FILE #ifndef __STDBOOL_H # error test failed #endif }
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 ); }
void cmd_otr_log_shows_usage_when_invalid_subcommand(void **state) { gchar *args[] = { "log", "wrong", NULL }; expect_string(cons_bad_cmd_usage, cmd, CMD_OTR); gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); }
void cmd_otr_shows_usage_when_no_args(void **state) { gchar *args[] = { NULL }; expect_string(cons_bad_cmd_usage, cmd, CMD_OTR); gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); }
static void test_read_pid_fail_if_open_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, 0 ); // Test if correctly opened. expect_string( mock_open, pathname, path ); expect_value( mock_open, flags, O_RDONLY ); expect_value( mock_open, mode, 0 ); will_return( mock_open, -1 ); // Go pid_t pid = read_pid( "/home/yasuhito/trema/tmp", "chess" ); assert_true( pid == -1 ); }
void expect_and_return_bookmark_remove(char *expected_jid, gboolean expected_autojoin, gboolean removed) { expect_string(_mock_bookmark_remove, jid, expected_jid); expect_value(_mock_bookmark_remove, autojoin, expected_autojoin); will_return(_mock_bookmark_remove, removed); }
void test_temporal_creating_etherstub( void** state ) { char etherstub[] = "etherstub1"; boolean_t temporary = 1; //temporal dladm_status_t flags = DLADM_OPT_ANCHOR | DLADM_OPT_ACTIVE; expect_string( dladm_valid_linkname, link, etherstub ); will_return( dladm_valid_linkname, 1 ); expect_value( dladm_vnic_create, flags, flags); expect_string( dladm_vnic_create, vnic, etherstub ); will_return( dladm_vnic_create, DLADM_STATUS_OK ); assert_true( XBOW_STATUS_OK == create_etherstub( etherstub, temporary ) ); }
void test_getting_property_value_when_operation_fails( void** state ) { char etherstub[] = "etherstub"; char parameter[] = "fdsfdff"; datalink_id_t linkid; expect_string( dladm_name2info, link, etherstub ); will_return( dladm_name2info, &linkid ); will_return( dladm_name2info, DLADM_STATUS_OK ); expect_string( dladm_get_linkprop, parameter, parameter ); will_return( dladm_get_linkprop, "" ); will_return( dladm_get_linkprop, DLADM_STATUS_FAILED ); assert_string_equal(NULL, get_etherstub_property( etherstub, parameter )); }
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 ); }