diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd_sub.c | 48 | ||||
-rw-r--r-- | tests/test_cmd_sub.h | 2 | ||||
-rw-r--r-- | tests/testsuite.c | 5 |
3 files changed, 55 insertions, 0 deletions
diff --git a/tests/test_cmd_sub.c b/tests/test_cmd_sub.c new file mode 100644 index 00000000..d2447a91 --- /dev/null +++ b/tests/test_cmd_sub.c @@ -0,0 +1,48 @@ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#include "xmpp/xmpp.h" +#include "xmpp/mock_xmpp.h" + +#include "ui/ui.h" +#include "ui/mock_ui.h" + +#include "command/commands.h" + +void cmd_sub_shows_message_when_not_connected(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { NULL }; + + mock_connection_status(JABBER_DISCONNECTED); + + expect_cons_show("You are currently not connected."); + + gboolean result = cmd_sub(args, *help); + assert_true(result); + + free(help); +} + +void cmd_sub_shows_usage_when_no_arg(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "Some usage"; + gchar *args[] = { NULL }; + + mock_connection_status(JABBER_CONNECTED); + + expect_cons_show("Usage: Some usage"); + + gboolean result = cmd_sub(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_sub.h b/tests/test_cmd_sub.h new file mode 100644 index 00000000..6e8addd3 --- /dev/null +++ b/tests/test_cmd_sub.h @@ -0,0 +1,2 @@ +void cmd_sub_shows_message_when_not_connected(void **state); +void cmd_sub_shows_usage_when_no_arg(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index e906c358..c0e98b23 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -8,6 +8,7 @@ #include "test_cmd_connect.h" #include "test_cmd_account.h" #include "test_cmd_rooms.h" +#include "test_cmd_sub.h" #include "test_history.h" #include "test_jid.h" #include "test_parser.h" @@ -252,6 +253,10 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_clear_checks_account_exists), unit_test(cmd_account_clear_shows_message_when_account_doesnt_exist), unit_test(cmd_account_clear_shows_message_when_invalid_property), + + unit_test(cmd_sub_shows_message_when_not_connected), + unit_test(cmd_sub_shows_usage_when_no_arg), + }; return run_tests(tests); } |