mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added cmd_roster test
This commit is contained in:
parent
05952e8337
commit
93397e4581
@ -76,6 +76,7 @@ tests_sources = \
|
||||
tests/test_preferences.c \
|
||||
tests/test_server_events.c \
|
||||
tests/test_muc.c \
|
||||
tests/test_cmd_roster.c \
|
||||
tests/testsuite.c
|
||||
|
||||
main_source = src/main.c
|
||||
|
70
tests/test_cmd_roster.c
Normal file
70
tests/test_cmd_roster.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ui/ui.h"
|
||||
#include "ui/mock_ui.h"
|
||||
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/mock_xmpp.h"
|
||||
|
||||
#include "roster_list.h"
|
||||
#include "command/commands.h"
|
||||
|
||||
static void test_with_connection_status(jabber_conn_status_t status)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
|
||||
mock_connection_status(status);
|
||||
|
||||
expect_cons_show("You are not currently connected.");
|
||||
|
||||
gboolean result = cmd_roster(NULL, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_roster_shows_message_when_disconnecting(void **state)
|
||||
{
|
||||
test_with_connection_status(JABBER_DISCONNECTING);
|
||||
}
|
||||
|
||||
void cmd_roster_shows_message_when_connecting(void **state)
|
||||
{
|
||||
test_with_connection_status(JABBER_CONNECTING);
|
||||
}
|
||||
|
||||
void cmd_roster_shows_message_when_disconnected(void **state)
|
||||
{
|
||||
test_with_connection_status(JABBER_DISCONNECTED);
|
||||
}
|
||||
|
||||
void cmd_roster_shows_message_when_undefined(void **state)
|
||||
{
|
||||
test_with_connection_status(JABBER_UNDEFINED);
|
||||
}
|
||||
|
||||
void cmd_roster_shows_roster_when_no_args(void **state)
|
||||
{
|
||||
mock_cons_show_roster();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { NULL };
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
roster_init();
|
||||
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
|
||||
GSList *roster = roster_get_contacts();
|
||||
cons_show_roster_expect(roster);
|
||||
|
||||
gboolean result = cmd_roster(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
roster_free();
|
||||
}
|
5
tests/test_cmd_roster.h
Normal file
5
tests/test_cmd_roster.h
Normal file
@ -0,0 +1,5 @@
|
||||
void cmd_roster_shows_message_when_disconnecting(void **state);
|
||||
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);
|
@ -29,6 +29,7 @@
|
||||
#include "test_cmd_bookmark.h"
|
||||
#include "test_cmd_join.h"
|
||||
#include "test_muc.h"
|
||||
#include "test_cmd_roster.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
const UnitTest all_tests[] = {
|
||||
@ -500,6 +501,12 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_join_uses_supplied_nick),
|
||||
unit_test(cmd_join_uses_account_nick_when_not_supplied),
|
||||
unit_test(cmd_join_uses_password_when_supplied),
|
||||
|
||||
unit_test(cmd_roster_shows_message_when_disconnecting),
|
||||
unit_test(cmd_roster_shows_message_when_connecting),
|
||||
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),
|
||||
};
|
||||
|
||||
return run_tests(all_tests);
|
||||
|
@ -171,6 +171,12 @@ void _mock_ui_room_join(char *room)
|
||||
check_expected(room);
|
||||
}
|
||||
|
||||
static
|
||||
void _mock_cons_show_roster(GSList *list)
|
||||
{
|
||||
check_expected(list);
|
||||
}
|
||||
|
||||
// bind mocks and stubs
|
||||
|
||||
void
|
||||
@ -276,6 +282,12 @@ mock_ui_current_print_line(void)
|
||||
ui_current_print_line = _mock_ui_current_print_line;
|
||||
}
|
||||
|
||||
void
|
||||
mock_cons_show_roster(void)
|
||||
{
|
||||
cons_show_roster = _mock_cons_show_roster;
|
||||
}
|
||||
|
||||
// expectations
|
||||
|
||||
void
|
||||
@ -420,3 +432,9 @@ ui_room_join_expect(char *room)
|
||||
ui_room_join = _mock_ui_room_join;
|
||||
expect_string(_mock_ui_room_join, room, room);
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_roster_expect(GSList *list)
|
||||
{
|
||||
expect_any(_mock_cons_show_roster, list);
|
||||
}
|
||||
|
@ -61,4 +61,7 @@ void ui_current_win_is_otr_returns(gboolean result);
|
||||
|
||||
void ui_room_join_expect(char *room);
|
||||
|
||||
void mock_cons_show_roster(void);
|
||||
void cons_show_roster_expect(GSList *list);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user