about summary refs log tree commit diff stats
path: root/tests/test_command.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-12-14 18:43:19 +0000
committerJames Booth <boothj5@gmail.com>2013-12-14 18:43:19 +0000
commit447d235868e9e1554e432aad1e6a3b3db10e7b1d (patch)
tree9ebb385c02a86b78c66ac4ce677aa3ef9a02a6a7 /tests/test_command.c
parent7955bc52ab003b26d3ea439c34e7006e6e1f1593 (diff)
downloadprofani-tty-447d235868e9e1554e432aad1e6a3b3db10e7b1d.tar.gz
Mocked account preferences and tested cmd_rooms
Diffstat (limited to 'tests/test_command.c')
-rw-r--r--tests/test_command.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/tests/test_command.c b/tests/test_command.c
index d553f7e5..5469cd44 100644
--- a/tests/test_command.c
+++ b/tests/test_command.c
@@ -9,16 +9,75 @@
 #include "ui/ui.h"
 #include "command/command.h"
 
-void cmd_rooms_shows_message_when_not_connected(void **state)
+static void test_with_connection_status(jabber_conn_status_t status)
 {
     CommandHelp *help = malloc(sizeof(CommandHelp));
-    will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
+    
+    will_return(jabber_get_connection_status, status);
     expect_string(cons_show, msg, "You are not currently connected.");
     
     gboolean result = _cmd_rooms(NULL, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+void cmd_rooms_shows_message_when_disconnected(void **state)
+{
+    test_with_connection_status(JABBER_DISCONNECTED);
+}
+
+void cmd_rooms_shows_message_when_disconnecting(void **state)
+{
+    test_with_connection_status(JABBER_DISCONNECTING);
+}
+
+void cmd_rooms_shows_message_when_connecting(void **state)
+{
+    test_with_connection_status(JABBER_CONNECTING);
+}
+
+void cmd_rooms_shows_message_when_started(void **state)
+{
+    test_with_connection_status(JABBER_STARTED);
+}
+
+void cmd_rooms_shows_message_when_undefined(void **state)
+{
+    test_with_connection_status(JABBER_UNDEFINED);
+}
+
+void cmd_rooms_uses_account_default_when_no_arg(void **state)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    ProfAccount *account = malloc(sizeof(ProfAccount));
+    account->muc_service = "default_conf_server";
+    gchar *args[] = { NULL }; 
+
+    will_return(jabber_get_connection_status, JABBER_CONNECTED);
+    will_return(jabber_get_account_name, "account_name");
+    will_return(accounts_get_account, account);
+    expect_string(iq_room_list_request, conferencejid, "default_conf_server");
+    
+    gboolean result = _cmd_rooms(args, *help);
 
     assert_true(result);
 
     free(help);
+    free(account);
 }
 
+void cmd_arg_used_when_passed(void **state)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "conf_server_arg" }; 
+
+    will_return(jabber_get_connection_status, JABBER_CONNECTED);
+    expect_string(iq_room_list_request, conferencejid, "conf_server_arg");
+    
+    gboolean result = _cmd_rooms(args, *help);
+
+    assert_true(result);
+
+    free(help);
+}