about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--tests/test_cmd_roster.c36
-rw-r--r--tests/test_cmd_roster.h2
-rw-r--r--tests/testsuite.c2
-rw-r--r--tests/xmpp/mock_xmpp.c18
-rw-r--r--tests/xmpp/mock_xmpp.h3
5 files changed, 59 insertions, 2 deletions
diff --git a/tests/test_cmd_roster.c b/tests/test_cmd_roster.c
index b29019bb..e59f5e5e 100644
--- a/tests/test_cmd_roster.c
+++ b/tests/test_cmd_roster.c
@@ -69,7 +69,7 @@ void cmd_roster_shows_roster_when_no_args(void **state)
     roster_free();
 }
 
-void cmd_roster_add_shows_message_when_no_jid(void)
+void cmd_roster_add_shows_message_when_no_jid(void **state)
 {
     mock_cons_show();
     CommandHelp *help = malloc(sizeof(CommandHelp));
@@ -85,7 +85,7 @@ void cmd_roster_add_shows_message_when_no_jid(void)
     free(help);
 }
 
-void cmd_roster_add_sends_roster_add_request(void)
+void cmd_roster_add_sends_roster_add_request(void **state)
 {
     char *jid = "bob@server.org";
     char *nick = "bob";
@@ -101,3 +101,35 @@ void cmd_roster_add_sends_roster_add_request(void)
 
     free(help);
 }
+
+void cmd_roster_remove_shows_message_when_no_jid(void **state)
+{
+    mock_cons_show();
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    help->usage = "some usage";
+    gchar *args[] = { "remove", 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_remove_sends_roster_remove_request(void)
+{
+    char *jid = "bob@server.org";
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "remove", jid, NULL };
+
+    mock_roster_send_remove();
+    mock_connection_status(JABBER_CONNECTED);
+    roster_send_remove_expect(jid);
+
+    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 cfed5875..418b3bc5 100644
--- a/tests/test_cmd_roster.h
+++ b/tests/test_cmd_roster.h
@@ -5,3 +5,5 @@ 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);
+void cmd_roster_remove_shows_message_when_no_jid(void **state);
+void cmd_roster_remove_sends_roster_remove_request(void **state);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 937e4642..bc669735 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -509,6 +509,8 @@ int main(int argc, char* argv[]) {
         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),
+        unit_test(cmd_roster_remove_shows_message_when_no_jid),
+        unit_test(cmd_roster_remove_sends_roster_remove_request),
     };
 
     return run_tests(all_tests);
diff --git a/tests/xmpp/mock_xmpp.c b/tests/xmpp/mock_xmpp.c
index c25156be..43f31e6c 100644
--- a/tests/xmpp/mock_xmpp.c
+++ b/tests/xmpp/mock_xmpp.c
@@ -103,6 +103,12 @@ _mock_roster_send_add_new(const char *const barejid, const char * const name)
     check_expected(name);
 }
 
+static void
+_mock_roster_send_remove(const char * const barejid)
+{
+    check_expected(barejid);
+}
+
 void
 mock_jabber_connect_with_details(void)
 {
@@ -153,6 +159,12 @@ mock_roster_send_add_new(void)
 }
 
 void
+mock_roster_send_remove(void)
+{
+    roster_send_remove = _mock_roster_send_remove;
+}
+
+void
 bookmark_get_list_returns(GList *bookmarks)
 {
     bookmark_get_list = _mock_bookmark_get_list;
@@ -280,3 +292,9 @@ 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);
 }
+
+void
+roster_send_remove_expect(char *jid)
+{
+    expect_string(_mock_roster_send_remove, barejid, jid);
+}
diff --git a/tests/xmpp/mock_xmpp.h b/tests/xmpp/mock_xmpp.h
index aafe1ba7..a917f9b8 100644
--- a/tests/xmpp/mock_xmpp.h
+++ b/tests/xmpp/mock_xmpp.h
@@ -39,4 +39,7 @@ 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);
 
+void mock_roster_send_remove(void);
+void roster_send_remove_expect(char *jid);
+
 #endif