diff options
author | James Booth <boothj5@gmail.com> | 2015-01-10 01:06:52 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-01-10 01:06:52 +0000 |
commit | ab7bd6fe5f9c0a0abdc82426ab2eaaeb9416da28 (patch) | |
tree | a9421e1a827822a574ebe0bf03eca3b916e86bc6 /tests | |
parent | 9bd2315d83d042156a5aa28227071756c46291b9 (diff) | |
download | profani-tty-ab7bd6fe5f9c0a0abdc82426ab2eaaeb9416da28.tar.gz |
Added test to ensure chat sessions cleared on cmd_disconnect
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd_disconnect.c | 34 | ||||
-rw-r--r-- | tests/test_cmd_disconnect.h | 1 | ||||
-rw-r--r-- | tests/testsuite.c | 3 | ||||
-rw-r--r-- | tests/ui/stub_ui.c | 6 | ||||
-rw-r--r-- | tests/ui/stub_ui.h | 1 | ||||
-rw-r--r-- | tests/xmpp/stub_xmpp.c | 2 |
6 files changed, 46 insertions, 1 deletions
diff --git a/tests/test_cmd_disconnect.c b/tests/test_cmd_disconnect.c new file mode 100644 index 00000000..43152872 --- /dev/null +++ b/tests/test_cmd_disconnect.c @@ -0,0 +1,34 @@ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> +#include <stdlib.h> +#include <string.h> + +#include "chat_session.h" +#include "command/commands.h" +#include "xmpp/xmpp.h" +#include "roster_list.h" + +#include "ui/stub_ui.h" + +void clears_chat_sessions(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + + chat_sessions_init(); + chat_session_on_recipient_activity("bob@server.org", "laptop"); + roster_init(); + + will_return(jabber_get_connection_status, JABBER_CONNECTED); + will_return(jabber_get_fulljid, "myjid@myserver.com"); + expect_any_cons_show(); + + gboolean result = cmd_disconnect(NULL, *help); + + assert_true(result); + + ChatSession *session = chat_session_get("bob@server.org"); + assert_null(session); + free(help); +} \ No newline at end of file diff --git a/tests/test_cmd_disconnect.h b/tests/test_cmd_disconnect.h new file mode 100644 index 00000000..856b501e --- /dev/null +++ b/tests/test_cmd_disconnect.h @@ -0,0 +1 @@ +void clears_chat_sessions(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index e333c93f..ebc4c7ac 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -33,6 +33,7 @@ #include "test_muc.h" #include "test_cmd_roster.h" #include "test_cmd_win.h" +#include "test_cmd_disconnect.h" #include "test_form.h" int main(int argc, char* argv[]) { @@ -609,6 +610,8 @@ int main(int argc, char* argv[]) { unit_test(remove_text_multi_value_does_nothing_when_doesnt_exist), unit_test(remove_text_multi_value_removes_when_one), unit_test(remove_text_multi_value_removes_when_many), + + unit_test(clears_chat_sessions), }; return run_tests(all_tests); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 5361c08d..f0dd1195 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -20,6 +20,12 @@ expect_cons_show(char *expected) } void +expect_any_cons_show(void) +{ + expect_any(cons_show, output); +} + +void expect_cons_show_error(char *expected) { expect_string(cons_show_error, output, expected); diff --git a/tests/ui/stub_ui.h b/tests/ui/stub_ui.h index f64eba02..3e6e435f 100644 --- a/tests/ui/stub_ui.h +++ b/tests/ui/stub_ui.h @@ -1,4 +1,5 @@ void expect_cons_show(char *expected); +void expect_any_cons_show(void); void expect_cons_show_error(char *expected); void expect_ui_current_print_line(char *message); void expect_ui_current_print_formatted_line(char show_char, int attrs, char *message); \ No newline at end of file diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index a6058058..cc5ad5fc 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -29,7 +29,7 @@ void jabber_shutdown(void) {} void jabber_process_events(void) {} const char * jabber_get_fulljid(void) { - return NULL; + return (char *)mock(); } const char * jabber_get_domain(void) |