mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Added test for /bookmark list
This commit is contained in:
parent
1654f13656
commit
3d7d070b13
@ -1726,7 +1726,8 @@ cmd_bookmark(gchar **args, struct cmd_help_t help)
|
||||
/* TODO: /bookmark list room@server */
|
||||
|
||||
if (cmd == NULL || strcmp(cmd, "list") == 0) {
|
||||
cons_show_bookmarks(bookmark_get_list());
|
||||
const GList *bookmarks = bookmark_get_list();
|
||||
cons_show_bookmarks(bookmarks);
|
||||
} else {
|
||||
gboolean autojoin = FALSE;
|
||||
gchar *jid = NULL;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "helpers.h"
|
||||
#include "config/preferences.h"
|
||||
|
||||
void init_preferences(void **state)
|
||||
@ -38,3 +39,47 @@ void close_preferences(void **state)
|
||||
rmdir("./tests/files/xdg_config_home");
|
||||
rmdir("./tests/files");
|
||||
}
|
||||
|
||||
static GCompareFunc cmp_func;
|
||||
|
||||
void
|
||||
glist_set_cmp(GCompareFunc func)
|
||||
{
|
||||
cmp_func = func;
|
||||
}
|
||||
|
||||
int
|
||||
glist_contents_equal(const void *actual, const void *expected)
|
||||
{
|
||||
GList *ac = (GList *)actual;
|
||||
GList *ex = (GList *)expected;
|
||||
|
||||
GList *p = ex;
|
||||
printf("\nExpected\n");
|
||||
while(ex) {
|
||||
printf("\n\n%s\n", (char*)p->data);
|
||||
ex = g_list_next(ex);
|
||||
}
|
||||
printf("\n\n");
|
||||
p = ac;
|
||||
printf("\nActual\n");
|
||||
while(ac) {
|
||||
printf("\n\n%s\n", (char *)p->data);
|
||||
ac = g_list_next(ac);
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
if (g_list_length(ex) != g_list_length(ac)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
GList *ex_curr = ex;
|
||||
while (ex_curr != NULL) {
|
||||
if (g_list_find_custom(ac, ex_curr->data, cmp_func) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ex_curr = g_list_next(ex_curr);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,2 +1,7 @@
|
||||
#include "glib.h"
|
||||
|
||||
void init_preferences(void **state);
|
||||
void close_preferences(void **state);
|
||||
|
||||
void glist_set_cmp(GCompareFunc func);
|
||||
int glist_contents_equal(const void *actual, const void *expected);
|
||||
|
@ -6,12 +6,13 @@
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ui/mock_ui.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/mock_xmpp.h"
|
||||
|
||||
#include "command/commands.h"
|
||||
|
||||
#include "ui/mock_ui.h"
|
||||
#include "xmpp/bookmark.h"
|
||||
|
||||
static void test_with_connection_status(jabber_conn_status_t status)
|
||||
{
|
||||
@ -67,3 +68,56 @@ void cmd_bookmark_shows_usage_when_no_args(void **state)
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
static void _free_bookmark(Bookmark *bookmark)
|
||||
{
|
||||
free(bookmark->jid);
|
||||
free(bookmark->nick);
|
||||
free(bookmark);
|
||||
}
|
||||
|
||||
void cmd_bookmark_list_shows_bookmarks(void **state)
|
||||
{
|
||||
mock_cons_show_bookmarks();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "list", NULL };
|
||||
GList *bookmarks = NULL;
|
||||
|
||||
Bookmark *bm1 = malloc(sizeof(Bookmark));
|
||||
bm1->jid = strdup("room1@conf.org");
|
||||
bm1->nick = strdup("bob");
|
||||
bm1->autojoin = FALSE;
|
||||
Bookmark *bm2 = malloc(sizeof(Bookmark));
|
||||
bm2->jid = strdup("room2@conf.org");
|
||||
bm2->nick = strdup("steve");
|
||||
bm2->autojoin = TRUE;
|
||||
Bookmark *bm3 = malloc(sizeof(Bookmark));
|
||||
bm3->jid = strdup("room3@conf.org");
|
||||
bm3->nick = strdup("dave");
|
||||
bm3->autojoin = TRUE;
|
||||
Bookmark *bm4 = malloc(sizeof(Bookmark));
|
||||
bm4->jid = strdup("room4@conf.org");
|
||||
bm4->nick = strdup("james");
|
||||
bm4->autojoin = FALSE;
|
||||
Bookmark *bm5 = malloc(sizeof(Bookmark));
|
||||
bm5->jid = strdup("room5@conf.org");
|
||||
bm5->nick = strdup("mike");
|
||||
bm5->autojoin = FALSE;
|
||||
|
||||
bookmarks = g_list_append(bookmarks, bm1);
|
||||
bookmarks = g_list_append(bookmarks, bm2);
|
||||
bookmarks = g_list_append(bookmarks, bm3);
|
||||
bookmarks = g_list_append(bookmarks, bm4);
|
||||
bookmarks = g_list_append(bookmarks, bm5);
|
||||
|
||||
mock_connection_status(JABBER_CONNECTED);
|
||||
|
||||
bookmark_get_list_returns(bookmarks);
|
||||
expect_cons_show_bookmarks(bookmarks);
|
||||
|
||||
gboolean result = cmd_bookmark(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
g_list_free_full(bookmarks, (GDestroyNotify)_free_bookmark);
|
||||
}
|
||||
|
@ -4,3 +4,4 @@ void cmd_bookmark_shows_message_when_connecting(void **state);
|
||||
void cmd_bookmark_shows_message_when_started(void **state);
|
||||
void cmd_bookmark_shows_message_when_undefined(void **state);
|
||||
void cmd_bookmark_shows_usage_when_no_args(void **state);
|
||||
void cmd_bookmark_list_shows_bookmarks(void **state);
|
||||
|
@ -445,6 +445,7 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(cmd_bookmark_shows_message_when_started),
|
||||
unit_test(cmd_bookmark_shows_message_when_undefined),
|
||||
unit_test(cmd_bookmark_shows_usage_when_no_args),
|
||||
unit_test(cmd_bookmark_list_shows_bookmarks),
|
||||
};
|
||||
|
||||
|
||||
|
@ -26,6 +26,9 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "ui/ui.h"
|
||||
#include "tests/helpers.h"
|
||||
|
||||
#include "xmpp/bookmark.h"
|
||||
|
||||
char output[256];
|
||||
|
||||
@ -70,6 +73,12 @@ void _mock_cons_show_account(ProfAccount *account)
|
||||
check_expected(account);
|
||||
}
|
||||
|
||||
static
|
||||
void _mock_cons_show_bookmarks(const GList *list)
|
||||
{
|
||||
check_expected(list);
|
||||
}
|
||||
|
||||
static
|
||||
void _mock_cons_show_aliases(GList *aliases)
|
||||
{
|
||||
@ -165,6 +174,12 @@ mock_cons_show_account(void)
|
||||
cons_show_account = _mock_cons_show_account;
|
||||
}
|
||||
|
||||
void
|
||||
mock_cons_show_bookmarks(void)
|
||||
{
|
||||
cons_show_bookmarks = _mock_cons_show_bookmarks;
|
||||
}
|
||||
|
||||
void
|
||||
mock_cons_show_aliases(void)
|
||||
{
|
||||
@ -233,6 +248,30 @@ expect_cons_show_account(ProfAccount *account)
|
||||
expect_memory(_mock_cons_show_account, account, account, sizeof(ProfAccount));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cmp_bookmark(Bookmark *bm1, Bookmark *bm2)
|
||||
{
|
||||
if (strcmp(bm1->jid, bm2->jid) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
if (strcmp(bm1->nick, bm2->nick) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
if (bm1->autojoin != bm2->autojoin) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
expect_cons_show_bookmarks(GList *bookmarks)
|
||||
{
|
||||
glist_set_cmp((GCompareFunc)_cmp_bookmark);
|
||||
expect_any(_mock_cons_show_bookmarks, list);
|
||||
// expect_check(_mock_cons_show_bookmarks, list, (CheckParameterValue)glist_contents_equal, bookmarks);
|
||||
}
|
||||
|
||||
void
|
||||
expect_cons_show_account_list(gchar **accounts)
|
||||
{
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include "config/account.h"
|
||||
#include "contact.h"
|
||||
|
||||
void stub_cons_show(void);
|
||||
|
||||
void mock_cons_show(void);
|
||||
@ -27,6 +30,9 @@ void expect_ui_handle_recipient_not_found(char *recipient, char *err_msg);
|
||||
void mock_cons_show_account(void);
|
||||
void expect_cons_show_account(ProfAccount *account);
|
||||
|
||||
void mock_cons_show_bookmarks(void);
|
||||
void expect_cons_show_bookmarks(GList *bookmarks);
|
||||
|
||||
void mock_cons_show_aliases(void);
|
||||
void expect_cons_show_aliases(void);
|
||||
|
||||
|
@ -58,6 +58,12 @@ _mock_presence_update(resource_presence_t status, const char * const msg, int id
|
||||
check_expected(idle);
|
||||
}
|
||||
|
||||
static const GList *
|
||||
_mock_bookmark_get_list(void)
|
||||
{
|
||||
return (GList *)mock();
|
||||
}
|
||||
|
||||
void
|
||||
mock_jabber_connect_with_details(void)
|
||||
{
|
||||
@ -83,6 +89,13 @@ mock_connection_status(jabber_conn_status_t status)
|
||||
will_return(_mock_jabber_get_connection_status, status);
|
||||
}
|
||||
|
||||
void
|
||||
bookmark_get_list_returns(GList *bookmarks)
|
||||
{
|
||||
bookmark_get_list = _mock_bookmark_get_list;
|
||||
will_return(_mock_bookmark_get_list, bookmarks);
|
||||
}
|
||||
|
||||
void
|
||||
mock_connection_account_name(char *name)
|
||||
{
|
||||
|
@ -21,4 +21,6 @@ void jabber_connect_with_account_return(jabber_conn_status_t result);
|
||||
void mock_presence_update(void);
|
||||
void presence_update_expect(resource_presence_t presence, char *msg, int idle);
|
||||
|
||||
void bookmark_get_list_returns(GList *bookmarks);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user