1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added message stanza error tests

This commit is contained in:
James Booth 2014-01-28 23:56:45 +00:00
parent 96af960995
commit 571665eeac
6 changed files with 102 additions and 8 deletions

View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
./configure CFLAGS='-g -O0' CXXFLAGS='-g -O0' ./configure --enable-otr CFLAGS='-g -O0' CXXFLAGS='-g -O0'

View File

@ -8,6 +8,7 @@
#include "server_events.h" #include "server_events.h"
#include "roster_list.h" #include "roster_list.h"
#include "chat_session.h"
#include "config/preferences.h" #include "config/preferences.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "ui/mock_ui.h" #include "ui/mock_ui.h"
@ -108,8 +109,46 @@ void console_shows_dnd_presence_when_set_all(void **state)
void handle_message_stanza_error_when_no_from(void **state) void handle_message_stanza_error_when_no_from(void **state)
{ {
char *err_msg = "Some error."; char *err_msg = "Some error.";
mock_ui_handle_error();
expect_ui_handle_error(err_msg); expect_ui_handle_error(err_msg);
handle_message_error(NULL, "cancel", err_msg); handle_message_error(NULL, "cancel", err_msg);
} }
void handle_message_stanza_error_from_cancel(void **state)
{
char *err_msg = "Some error.";
char *from = "bob@server.com";
prefs_set_boolean(PREF_STATES, FALSE);
chat_sessions_init();
expect_ui_handle_recipient_not_found(from, err_msg);
handle_message_error(from, "cancel", err_msg);
}
void handle_message_stanza_error_from_cancel_disables_chat_session(void **state)
{
char *err_msg = "Some error.";
char *from = "bob@server.com";
stub_ui_handle_recipient_not_found();
prefs_set_boolean(PREF_STATES, TRUE);
chat_sessions_init();
chat_session_start(from, TRUE);
handle_message_error(from, "cancel", err_msg);
gboolean chat_session_supported = chat_session_get_recipient_supports(from);
assert_false(chat_session_supported);
chat_sessions_clear();
}
void handle_message_stanza_error_from_no_type(void **state)
{
char *err_msg = "Some error.";
char *from = "bob@server.com";
expect_ui_handle_recipient_error(from, err_msg);
handle_message_error(from, NULL, err_msg);
}

View File

@ -5,3 +5,6 @@ void console_doesnt_show_dnd_presence_when_set_none(void **state);
void console_doesnt_show_dnd_presence_when_set_online(void **state); void console_doesnt_show_dnd_presence_when_set_online(void **state);
void console_shows_dnd_presence_when_set_all(void **state); void console_shows_dnd_presence_when_set_all(void **state);
void handle_message_stanza_error_when_no_from(void **state); void handle_message_stanza_error_when_no_from(void **state);
void handle_message_stanza_error_from_cancel(void **stanza);
void handle_message_stanza_error_from_cancel_disables_chat_session(void **stanza);
void handle_message_stanza_error_from_no_type(void **state);

View File

@ -389,7 +389,14 @@ int main(int argc, char* argv[]) {
unit_test_setup_teardown(console_shows_dnd_presence_when_set_all, unit_test_setup_teardown(console_shows_dnd_presence_when_set_all,
init_preferences, init_preferences,
close_preferences), close_preferences),
unit_test(handle_message_stanza_error_when_no_from) unit_test(handle_message_stanza_error_when_no_from),
unit_test_setup_teardown(handle_message_stanza_error_from_cancel,
init_preferences,
close_preferences),
unit_test_setup_teardown(handle_message_stanza_error_from_cancel_disables_chat_session,
init_preferences,
close_preferences),
unit_test(handle_message_stanza_error_from_no_type),
}; };
const UnitTest cmd_alias_tests[] = { const UnitTest cmd_alias_tests[] = {
@ -436,8 +443,8 @@ int main(int argc, char* argv[]) {
PROF_RUN_TESTS(contact_tests); PROF_RUN_TESTS(contact_tests);
PROF_RUN_TESTS(cmd_statuses_tests); PROF_RUN_TESTS(cmd_statuses_tests);
PROF_RUN_TESTS(preferences_tests); PROF_RUN_TESTS(preferences_tests);
PROF_RUN_TESTS(server_events_tests);
PROF_RUN_TESTS(cmd_alias_tests); PROF_RUN_TESTS(cmd_alias_tests);
PROF_RUN_TESTS(server_events_tests);
fflush(stdout); fflush(stdout);
dup2(bak, 1); dup2(bak, 1);

View File

@ -29,6 +29,8 @@
char output[256]; char output[256];
// Mocks and stubs
static static
void _mock_cons_show(const char * const msg, ...) void _mock_cons_show(const char * const msg, ...)
{ {
@ -98,11 +100,34 @@ void _mock_ui_handle_error(const char * const err_msg)
check_expected(err_msg); check_expected(err_msg);
} }
static
void _mock_ui_handle_recipient_error(const char * const recipient,
const char * const err_msg)
{
check_expected(recipient);
check_expected(err_msg);
}
static
void _mock_ui_handle_recipient_not_found(const char * const recipient,
const char * const err_msg)
{
check_expected(recipient);
check_expected(err_msg);
}
static static
void _stub_ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) void _stub_ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)
{ {
} }
static
void _stub_ui_handle_recipient_not_found(const char * const recipient, const char * const err_msg)
{
}
// bind mocks and stubs
void void
mock_cons_show(void) mock_cons_show(void)
{ {
@ -146,7 +171,6 @@ mock_cons_show_account_list(void)
cons_show_account_list = _mock_cons_show_account_list; cons_show_account_list = _mock_cons_show_account_list;
} }
void void
mock_ui_ask_password(void) mock_ui_ask_password(void)
{ {
@ -166,11 +190,13 @@ stub_cons_show(void)
} }
void void
mock_ui_handle_error(void) stub_ui_handle_recipient_not_found(void)
{ {
ui_handle_error = _mock_ui_handle_error; ui_handle_recipient_not_found = _stub_ui_handle_recipient_not_found;
} }
// expectations
void void
expect_cons_show(char *output) expect_cons_show(char *output)
{ {
@ -229,5 +255,22 @@ mock_ui_ask_password_returns(char *password)
void void
expect_ui_handle_error(char *err_msg) expect_ui_handle_error(char *err_msg)
{ {
ui_handle_error = _mock_ui_handle_error;
expect_string(_mock_ui_handle_error, err_msg, err_msg); expect_string(_mock_ui_handle_error, err_msg, err_msg);
} }
void
expect_ui_handle_recipient_error(char *recipient, char *err_msg)
{
ui_handle_recipient_error = _mock_ui_handle_recipient_error;
expect_string(_mock_ui_handle_recipient_error, recipient, recipient);
expect_string(_mock_ui_handle_recipient_error, err_msg, err_msg);
}
void
expect_ui_handle_recipient_not_found(char *recipient, char *err_msg)
{
ui_handle_recipient_not_found = _mock_ui_handle_recipient_not_found;
expect_string(_mock_ui_handle_recipient_not_found, recipient, recipient);
expect_string(_mock_ui_handle_recipient_not_found, err_msg, err_msg);
}

View File

@ -18,8 +18,10 @@ void stub_ui_chat_win_contact_online(void);
void mock_cons_show_error(void); void mock_cons_show_error(void);
void expect_cons_show_error(char *output); void expect_cons_show_error(char *output);
void mock_ui_handle_error(void); void stub_ui_handle_recipient_not_found(void);
void expect_ui_handle_error(char *err_msg); void expect_ui_handle_error(char *err_msg);
void expect_ui_handle_recipient_error(char *recipient, char *err_msg);
void expect_ui_handle_recipient_not_found(char *recipient, char *err_msg);
void mock_cons_show_account(void); void mock_cons_show_account(void);
void expect_cons_show_account(ProfAccount *account); void expect_cons_show_account(ProfAccount *account);