about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-12-15 18:08:26 +0000
committerJames Booth <boothj5@gmail.com>2013-12-15 18:08:26 +0000
commitbf347ab9e05b4b5bcd0dfa354f139aca85744440 (patch)
tree394af38841ba81be42324147a28a66291b52d1d3 /tests
parent2490f5b417a13639771211a7862bab88a6a5195e (diff)
downloadprofani-tty-bf347ab9e05b4b5bcd0dfa354f139aca85744440.tar.gz
Added cmd_connect tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd_connect.c79
-rw-r--r--tests/test_cmd_connect.h4
-rw-r--r--tests/test_cmd_rooms.c (renamed from tests/test_command.c)2
-rw-r--r--tests/test_cmd_rooms.h (renamed from tests/test_command.h)2
-rw-r--r--tests/testsuite.c10
5 files changed, 93 insertions, 4 deletions
diff --git a/tests/test_cmd_connect.c b/tests/test_cmd_connect.c
new file mode 100644
index 00000000..2acc2c48
--- /dev/null
+++ b/tests/test_cmd_connect.c
@@ -0,0 +1,79 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include "xmpp/xmpp.h"
+#include "ui/ui.h"
+#include "command/commands.h"
+
+static void test_with_connection_status(jabber_conn_status_t status)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    
+    will_return(jabber_get_connection_status, status);
+    expect_string(cons_show, msg, "You are either connected already, or a login is in process.");
+    
+    gboolean result = cmd_connect(NULL, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+void cmd_connect_shows_message_when_disconnecting(void **state)
+{
+    test_with_connection_status(JABBER_DISCONNECTING);
+}
+
+void cmd_connect_shows_message_when_connecting(void **state)
+{
+    test_with_connection_status(JABBER_CONNECTING);
+}
+
+void cmd_connect_shows_message_when_connected(void **state)
+{
+    test_with_connection_status(JABBER_CONNECTED);
+}
+
+void cmd_connect_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_rooms_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);
+}
+*/
diff --git a/tests/test_cmd_connect.h b/tests/test_cmd_connect.h
new file mode 100644
index 00000000..af187d68
--- /dev/null
+++ b/tests/test_cmd_connect.h
@@ -0,0 +1,4 @@
+void cmd_connect_shows_message_when_disconnecting(void **state);
+void cmd_connect_shows_message_when_connecting(void **state);
+void cmd_connect_shows_message_when_connected(void **state);
+void cmd_connect_shows_message_when_undefined(void **state);
diff --git a/tests/test_command.c b/tests/test_cmd_rooms.c
index 6dc51ecb..e58e178d 100644
--- a/tests/test_command.c
+++ b/tests/test_cmd_rooms.c
@@ -67,7 +67,7 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
     free(account);
 }
 
-void cmd_arg_used_when_passed(void **state)
+void cmd_rooms_arg_used_when_passed(void **state)
 {
     CommandHelp *help = malloc(sizeof(CommandHelp));
     gchar *args[] = { "conf_server_arg" }; 
diff --git a/tests/test_command.h b/tests/test_cmd_rooms.h
index 0f47be84..a9a7af83 100644
--- a/tests/test_command.h
+++ b/tests/test_cmd_rooms.h
@@ -4,4 +4,4 @@ void cmd_rooms_shows_message_when_connecting(void **state);
 void cmd_rooms_shows_message_when_started(void **state);
 void cmd_rooms_shows_message_when_undefined(void **state);
 void cmd_rooms_uses_account_default_when_no_arg(void **state);
-void cmd_arg_used_when_passed(void **state);
+void cmd_rooms_arg_used_when_passed(void **state);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index ee18fe6a..d13a3d46 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -5,7 +5,8 @@
 
 #include "test_autocomplete.h"
 #include "test_common.h"
-#include "test_command.h"
+#include "test_cmd_connect.h"
+#include "test_cmd_rooms.h"
 #include "test_history.h"
 #include "test_jid.h"
 #include "test_parser.h"
@@ -13,13 +14,18 @@
 
 int main(int argc, char* argv[]) {
     const UnitTest tests[] = {
+        unit_test(cmd_connect_shows_message_when_disconnecting),
+        unit_test(cmd_connect_shows_message_when_connecting),
+        unit_test(cmd_connect_shows_message_when_connected),
+        unit_test(cmd_connect_shows_message_when_undefined),
+
         unit_test(cmd_rooms_shows_message_when_disconnected),
         unit_test(cmd_rooms_shows_message_when_disconnecting),
         unit_test(cmd_rooms_shows_message_when_connecting),
         unit_test(cmd_rooms_shows_message_when_started),
         unit_test(cmd_rooms_shows_message_when_undefined),
         unit_test(cmd_rooms_uses_account_default_when_no_arg),
-        unit_test(cmd_arg_used_when_passed),
+        unit_test(cmd_rooms_arg_used_when_passed),
  
         unit_test(replace_one_substr),
         unit_test(replace_one_substr_beginning),