about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--tests/test_cmd_roster.c33
-rw-r--r--tests/test_cmd_roster.h2
-rw-r--r--tests/testsuite.c2
-rw-r--r--tests/xmpp/mock_xmpp.c20
-rw-r--r--tests/xmpp/mock_xmpp.h3
5 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_cmd_roster.c b/tests/test_cmd_roster.c
index 9cfb711c..b29019bb 100644
--- a/tests/test_cmd_roster.c
+++ b/tests/test_cmd_roster.c
@@ -68,3 +68,36 @@ void cmd_roster_shows_roster_when_no_args(void **state)
     free(help);
     roster_free();
 }
+
+void cmd_roster_add_shows_message_when_no_jid(void)
+{
+    mock_cons_show();
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    help->usage = "some usage";
+    gchar *args[] = { "add", NULL };
+
+    mock_connection_status(JABBER_CONNECTED);
+    expect_cons_show("Usage: some usage");
+
+    gboolean result = cmd_roster(args, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+void cmd_roster_add_sends_roster_add_request(void)
+{
+    char *jid = "bob@server.org";
+    char *nick = "bob";
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "add", jid, nick, NULL };
+
+    mock_roster_send_add_new();
+    mock_connection_status(JABBER_CONNECTED);
+    roster_send_add_new_expect(jid, nick);
+
+    gboolean result = cmd_roster(args, *help);
+    assert_true(result);
+
+    free(help);
+}
diff --git a/tests/test_cmd_roster.h b/tests/test_cmd_roster.h
index e3e687ef..cfed5875 100644
--- a/tests/test_cmd_roster.h
+++ b/tests/test_cmd_roster.h
@@ -3,3 +3,5 @@ void cmd_roster_shows_message_when_connecting(void **state);
 void cmd_roster_shows_message_when_disconnected(void **state);
 void cmd_roster_shows_message_when_undefined(void **state);
 void cmd_roster_shows_roster_when_no_args(void **state);
+void cmd_roster_add_shows_message_when_no_jid(void **state);
+void cmd_roster_add_sends_roster_add_request(void **state);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 4e20265d..937e4642 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -507,6 +507,8 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_roster_shows_message_when_disconnected),
         unit_test(cmd_roster_shows_message_when_undefined),
         unit_test(cmd_roster_shows_roster_when_no_args),
+        unit_test(cmd_roster_add_shows_message_when_no_jid),
+        unit_test(cmd_roster_add_sends_roster_add_request),
     };
 
     return run_tests(all_tests);
diff --git a/tests/xmpp/mock_xmpp.c b/tests/xmpp/mock_xmpp.c
index 3b824c19..c25156be 100644
--- a/tests/xmpp/mock_xmpp.c
+++ b/tests/xmpp/mock_xmpp.c
@@ -96,6 +96,13 @@ _mock_presence_join_room(char *room, char*nick, char *passwd)
     check_expected(passwd);
 }
 
+static void
+_mock_roster_send_add_new(const char *const barejid, const char * const name)
+{
+    check_expected(barejid);
+    check_expected(name);
+}
+
 void
 mock_jabber_connect_with_details(void)
 {
@@ -140,6 +147,12 @@ mock_presence_join_room(void)
 }
 
 void
+mock_roster_send_add_new(void)
+{
+    roster_send_add_new = _mock_roster_send_add_new;
+}
+
+void
 bookmark_get_list_returns(GList *bookmarks)
 {
     bookmark_get_list = _mock_bookmark_get_list;
@@ -260,3 +273,10 @@ presence_join_room_expect(char *room, char *nick, char *passwd)
         expect_string(_mock_presence_join_room, passwd, passwd);
     }
 }
+
+void
+roster_send_add_new_expect(char *jid, char *nick)
+{
+    expect_string(_mock_roster_send_add_new, barejid, jid);
+    expect_string(_mock_roster_send_add_new, name, nick);
+}
diff --git a/tests/xmpp/mock_xmpp.h b/tests/xmpp/mock_xmpp.h
index 2b535761..aafe1ba7 100644
--- a/tests/xmpp/mock_xmpp.h
+++ b/tests/xmpp/mock_xmpp.h
@@ -36,4 +36,7 @@ void message_send_expect(char *message, char *recipient);
 void mock_presence_join_room(void);
 void presence_join_room_expect(char *room, char *nick, char *passwd);
 
+void mock_roster_send_add_new(void);
+void roster_send_add_new_expect(char *jid, char *nick);
+
 #endif