mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-29 12:16:21 +00:00
revert: restore pre-upstream-merge baseline (tree of 3b673150b)
Roll the tree back to the pre-merge tip3b673150b, undoing the upstream sync merge72f4f186d(303 files) and the 13 post-merge commits layered on top of it. Purpose: restore the last pre-sync baseline so the reported OMEMO/OTR encryption regressions can be reproduced against a known-good state and the upstream sync ruled in or out as the cause. Nothing is dropped from history; the merge and every post-merge commit remain reachable and can be cherry-picked back selectively. Baseline:3b673150bchore(chatlog): disable background message file logging (stage 1) Undoes merge:72f4f186dmerge: sync upstream profanity-im/profanity
This commit is contained in:
@@ -1,11 +1,3 @@
|
||||
/*
|
||||
* stub_xmpp.c
|
||||
*
|
||||
* Copyright (C) 2015 - 2018 James Booth <boothj5@gmail.com>
|
||||
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
#include "prof_cmocka.h"
|
||||
|
||||
#include "xmpp/xmpp.h"
|
||||
@@ -170,6 +162,11 @@ connection_get_profanity_identifier(void)
|
||||
return "profident";
|
||||
}
|
||||
|
||||
void
|
||||
connection_debug_print_features()
|
||||
{
|
||||
}
|
||||
|
||||
jabber_conn_status_t
|
||||
connection_register(const char* const altdomain, int port, const char* const tls_policy,
|
||||
const char* const username, const char* const password)
|
||||
@@ -616,9 +613,3 @@ void
|
||||
blocked_ac_reset(void)
|
||||
{
|
||||
}
|
||||
|
||||
GList*
|
||||
connection_get_available_resources(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/chat_session.h"
|
||||
|
||||
void
|
||||
chat_session_get__returns__null_when_no_session(void** state)
|
||||
{
|
||||
ChatSession* session = chat_session_get("somejid@server.org");
|
||||
assert_null(session);
|
||||
}
|
||||
|
||||
void
|
||||
chat_session_recipient_active__updates__new_session(void** state)
|
||||
{
|
||||
char* barejid = "myjid@server.org";
|
||||
char* resource = "tablet";
|
||||
|
||||
chat_session_recipient_active(barejid, resource, FALSE);
|
||||
ChatSession* session = chat_session_get(barejid);
|
||||
|
||||
assert_non_null(session);
|
||||
assert_string_equal(session->resource, resource);
|
||||
}
|
||||
|
||||
void
|
||||
chat_session_recipient_active__updates__replace_resource(void** state)
|
||||
{
|
||||
char* barejid = "myjid@server.org";
|
||||
char* resource1 = "tablet";
|
||||
char* resource2 = "mobile";
|
||||
|
||||
chat_session_recipient_active(barejid, resource1, FALSE);
|
||||
chat_session_recipient_active(barejid, resource2, FALSE);
|
||||
ChatSession* session = chat_session_get(barejid);
|
||||
|
||||
assert_string_equal(session->resource, resource2);
|
||||
}
|
||||
|
||||
void
|
||||
chat_session_remove__updates__session_removed(void** state)
|
||||
{
|
||||
char* barejid = "myjid@server.org";
|
||||
char* resource1 = "laptop";
|
||||
|
||||
chat_session_recipient_active(barejid, resource1, FALSE);
|
||||
chat_session_remove(barejid);
|
||||
ChatSession* session = chat_session_get(barejid);
|
||||
|
||||
assert_null(session);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef TESTS_TEST_CHAT_SESSION_H
|
||||
#define TESTS_TEST_CHAT_SESSION_H
|
||||
|
||||
void chat_session_get__returns__null_when_no_session(void** state);
|
||||
void chat_session_recipient_active__updates__new_session(void** state);
|
||||
void chat_session_recipient_active__updates__replace_resource(void** state);
|
||||
void chat_session_remove__updates__session_removed(void** state);
|
||||
|
||||
#endif
|
||||
@@ -1,428 +0,0 @@
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/contact.h"
|
||||
|
||||
void
|
||||
p_contact_in_group__is__true_when_in_group(void** state)
|
||||
{
|
||||
GSList* groups = NULL;
|
||||
groups = g_slist_append(groups, g_strdup("somegroup"));
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", groups, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
gboolean result = p_contact_in_group(contact, "somegroup");
|
||||
|
||||
assert_true(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
// g_slist_free(groups);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_in_group__is__false_when_not_in_group(void** state)
|
||||
{
|
||||
GSList* groups = NULL;
|
||||
groups = g_slist_append(groups, g_strdup("somegroup"));
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", groups, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
gboolean result = p_contact_in_group(contact, "othergroup");
|
||||
|
||||
assert_false(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
// g_slist_free(groups);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_name_or_jid__returns__name_when_exists(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
const char* name = p_contact_name_or_jid(contact);
|
||||
|
||||
assert_string_equal("bob", name);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_name_or_jid__returns__jid_when_name_not_exists(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", NULL, NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
const char* jid = p_contact_name_or_jid(contact);
|
||||
|
||||
assert_string_equal("bob@server.com", jid);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_create_display_string__returns__name_and_resource_when_name_exists(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
char* str = p_contact_create_display_string(contact, "laptop");
|
||||
|
||||
assert_string_equal("bob (laptop)", str);
|
||||
|
||||
p_contact_free(contact);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_create_display_string__returns__jid_and_resource_when_name_not_exists(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", NULL, NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
char* str = p_contact_create_display_string(contact, "laptop");
|
||||
|
||||
assert_string_equal("bob@server.com (laptop)", str);
|
||||
|
||||
p_contact_free(contact);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_create_display_string__returns__name_when_default_resource(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
char* str = p_contact_create_display_string(contact, "__prof_default");
|
||||
|
||||
assert_string_equal("bob", str);
|
||||
|
||||
p_contact_free(contact);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_presence__returns__offline_when_no_resources(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
const char* presence = p_contact_presence(contact);
|
||||
|
||||
assert_string_equal("offline", presence);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_presence__returns__highest_priority_presence(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource10 = resource_new("resource10", RESOURCE_ONLINE, NULL, 10);
|
||||
Resource* resource20 = resource_new("resource20", RESOURCE_CHAT, NULL, 20);
|
||||
Resource* resource30 = resource_new("resource30", RESOURCE_AWAY, NULL, 30);
|
||||
Resource* resource1 = resource_new("resource1", RESOURCE_XA, NULL, 1);
|
||||
Resource* resource2 = resource_new("resource2", RESOURCE_DND, NULL, 2);
|
||||
p_contact_set_presence(contact, resource10);
|
||||
p_contact_set_presence(contact, resource20);
|
||||
p_contact_set_presence(contact, resource30);
|
||||
p_contact_set_presence(contact, resource1);
|
||||
p_contact_set_presence(contact, resource2);
|
||||
|
||||
const char* presence = p_contact_presence(contact);
|
||||
|
||||
assert_string_equal("away", presence);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_presence__returns__chat_when_same_priority(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 10);
|
||||
Resource* resource_chat = resource_new("resource_chat", RESOURCE_CHAT, NULL, 10);
|
||||
Resource* resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10);
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_online);
|
||||
p_contact_set_presence(contact, resource_chat);
|
||||
p_contact_set_presence(contact, resource_away);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
const char* presence = p_contact_presence(contact);
|
||||
|
||||
assert_string_equal("chat", presence);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_presence__returns__online_when_same_priority(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 10);
|
||||
Resource* resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10);
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_online);
|
||||
p_contact_set_presence(contact, resource_away);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
const char* presence = p_contact_presence(contact);
|
||||
|
||||
assert_string_equal("online", presence);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_presence__returns__away_when_same_priority(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10);
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_away);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
const char* presence = p_contact_presence(contact);
|
||||
|
||||
assert_string_equal("away", presence);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_presence__returns__xa_when_same_priority(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
const char* presence = p_contact_presence(contact);
|
||||
|
||||
assert_string_equal("xa", presence);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_presence__returns__dnd(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
const char* presence = p_contact_presence(contact);
|
||||
|
||||
assert_string_equal("dnd", presence);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_subscribed__is__true_when_to(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "to",
|
||||
"is offline", FALSE);
|
||||
|
||||
gboolean result = p_contact_subscribed(contact);
|
||||
|
||||
assert_true(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_subscribed__is__true_when_both(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "both",
|
||||
"is offline", FALSE);
|
||||
|
||||
gboolean result = p_contact_subscribed(contact);
|
||||
|
||||
assert_true(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_subscribed__is__false_when_from(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, "from",
|
||||
"is offline", FALSE);
|
||||
|
||||
gboolean result = p_contact_subscribed(contact);
|
||||
|
||||
assert_false(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_subscribed__is__false_when_no_subscription_value(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
|
||||
"is offline", FALSE);
|
||||
|
||||
gboolean result = p_contact_subscribed(contact);
|
||||
|
||||
assert_false(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_is_available__is__false_when_offline(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
|
||||
"is offline", FALSE);
|
||||
|
||||
gboolean result = p_contact_is_available(contact);
|
||||
|
||||
assert_false(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_is_available__is__false_when_highest_priority_away(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 10);
|
||||
Resource* resource_chat = resource_new("resource_chat", RESOURCE_CHAT, NULL, 10);
|
||||
Resource* resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 20);
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_online);
|
||||
p_contact_set_presence(contact, resource_chat);
|
||||
p_contact_set_presence(contact, resource_away);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
gboolean result = p_contact_is_available(contact);
|
||||
|
||||
assert_false(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_is_available__is__false_when_highest_priority_xa(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 10);
|
||||
Resource* resource_chat = resource_new("resource_chat", RESOURCE_CHAT, NULL, 10);
|
||||
Resource* resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10);
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 20);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_online);
|
||||
p_contact_set_presence(contact, resource_chat);
|
||||
p_contact_set_presence(contact, resource_away);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
gboolean result = p_contact_is_available(contact);
|
||||
|
||||
assert_false(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_is_available__is__false_when_highest_priority_dnd(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 10);
|
||||
Resource* resource_chat = resource_new("resource_chat", RESOURCE_CHAT, NULL, 10);
|
||||
Resource* resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10);
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 20);
|
||||
p_contact_set_presence(contact, resource_online);
|
||||
p_contact_set_presence(contact, resource_chat);
|
||||
p_contact_set_presence(contact, resource_away);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
gboolean result = p_contact_is_available(contact);
|
||||
|
||||
assert_false(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_is_available__is__true_when_highest_priority_online(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 20);
|
||||
Resource* resource_chat = resource_new("resource_chat", RESOURCE_CHAT, NULL, 10);
|
||||
Resource* resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10);
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_online);
|
||||
p_contact_set_presence(contact, resource_chat);
|
||||
p_contact_set_presence(contact, resource_away);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
gboolean result = p_contact_is_available(contact);
|
||||
|
||||
assert_true(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_is_available__is__true_when_highest_priority_chat(void** state)
|
||||
{
|
||||
PContact contact = p_contact_new("bob@server.com", "bob", NULL, NULL,
|
||||
"is offline", FALSE);
|
||||
|
||||
Resource* resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 10);
|
||||
Resource* resource_chat = resource_new("resource_chat", RESOURCE_CHAT, NULL, 20);
|
||||
Resource* resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10);
|
||||
Resource* resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10);
|
||||
Resource* resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10);
|
||||
p_contact_set_presence(contact, resource_online);
|
||||
p_contact_set_presence(contact, resource_chat);
|
||||
p_contact_set_presence(contact, resource_away);
|
||||
p_contact_set_presence(contact, resource_xa);
|
||||
p_contact_set_presence(contact, resource_dnd);
|
||||
|
||||
gboolean result = p_contact_is_available(contact);
|
||||
|
||||
assert_true(result);
|
||||
|
||||
p_contact_free(contact);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef TESTS_TEST_CONTACT_H
|
||||
#define TESTS_TEST_CONTACT_H
|
||||
|
||||
void p_contact_in_group__is__true_when_in_group(void** state);
|
||||
void p_contact_in_group__is__false_when_not_in_group(void** state);
|
||||
void p_contact_name_or_jid__returns__name_when_exists(void** state);
|
||||
void p_contact_name_or_jid__returns__jid_when_name_not_exists(void** state);
|
||||
void p_contact_create_display_string__returns__name_and_resource_when_name_exists(void** state);
|
||||
void p_contact_create_display_string__returns__jid_and_resource_when_name_not_exists(void** state);
|
||||
void p_contact_create_display_string__returns__name_when_default_resource(void** state);
|
||||
void p_contact_presence__returns__offline_when_no_resources(void** state);
|
||||
void p_contact_presence__returns__highest_priority_presence(void** state);
|
||||
void p_contact_presence__returns__chat_when_same_priority(void** state);
|
||||
void p_contact_presence__returns__online_when_same_priority(void** state);
|
||||
void p_contact_presence__returns__away_when_same_priority(void** state);
|
||||
void p_contact_presence__returns__xa_when_same_priority(void** state);
|
||||
void p_contact_presence__returns__dnd(void** state);
|
||||
void p_contact_subscribed__is__true_when_to(void** state);
|
||||
void p_contact_subscribed__is__true_when_both(void** state);
|
||||
void p_contact_subscribed__is__false_when_from(void** state);
|
||||
void p_contact_subscribed__is__false_when_no_subscription_value(void** state);
|
||||
void p_contact_is_available__is__false_when_offline(void** state);
|
||||
void p_contact_is_available__is__false_when_highest_priority_away(void** state);
|
||||
void p_contact_is_available__is__false_when_highest_priority_xa(void** state);
|
||||
void p_contact_is_available__is__false_when_highest_priority_dnd(void** state);
|
||||
void p_contact_is_available__is__true_when_highest_priority_online(void** state);
|
||||
void p_contact_is_available__is__true_when_highest_priority_chat(void** state);
|
||||
|
||||
#endif
|
||||
@@ -1,744 +0,0 @@
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/form.h"
|
||||
|
||||
xmpp_ctx_t*
|
||||
connection_get_ctx(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static DataForm*
|
||||
_new_form(void)
|
||||
{
|
||||
DataForm* form = g_new0(DataForm, 1);
|
||||
form->type = NULL;
|
||||
form->title = NULL;
|
||||
form->instructions = NULL;
|
||||
form->fields = NULL;
|
||||
form->var_to_tag = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
form->tag_to_var = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
form->tag_ac = NULL;
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
static FormField*
|
||||
_new_field(void)
|
||||
{
|
||||
FormField* field = g_new0(FormField, 1);
|
||||
field->label = NULL;
|
||||
field->type = NULL;
|
||||
field->description = NULL;
|
||||
field->required = FALSE;
|
||||
field->options = NULL;
|
||||
field->var = NULL;
|
||||
field->values = NULL;
|
||||
field->value_ac = NULL;
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
void
|
||||
form_get_form_type_field__returns__null_no_fields(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
|
||||
char* result = form_get_form_type_field(form);
|
||||
|
||||
assert_null(result);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_get_form_type_field__returns__null_when_not_present(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
FormField* field = _new_field();
|
||||
field->var = g_strdup("var1");
|
||||
field->values = g_slist_append(field->values, g_strdup("value1"));
|
||||
form->fields = g_slist_append(form->fields, field);
|
||||
|
||||
char* result = form_get_form_type_field(form);
|
||||
|
||||
assert_null(result);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_get_form_type_field__returns__value_when_present(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value1"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
FormField* field2 = _new_field();
|
||||
field2->var = g_strdup("FORM_TYPE");
|
||||
field2->values = g_slist_append(field2->values, g_strdup("value2"));
|
||||
form->fields = g_slist_append(form->fields, field2);
|
||||
|
||||
FormField* field3 = _new_field();
|
||||
field3->var = g_strdup("var3");
|
||||
field3->values = g_slist_append(field3->values, g_strdup("value3"));
|
||||
form->fields = g_slist_append(form->fields, field3);
|
||||
|
||||
char* result = form_get_form_type_field(form);
|
||||
|
||||
assert_string_equal(result, "value2");
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_get_field_type__returns__unknown_when_no_fields(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
|
||||
form_field_type_t result = form_get_field_type(form, "tag");
|
||||
|
||||
assert_int_equal(result, FIELD_UNKNOWN);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_get_field_type__returns__correct_type(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_TEXT_SINGLE;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value1"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
FormField* field2 = _new_field();
|
||||
field2->var = g_strdup("var2");
|
||||
field2->type_t = FIELD_TEXT_MULTI;
|
||||
field2->values = g_slist_append(field2->values, g_strdup("value2"));
|
||||
form->fields = g_slist_append(form->fields, field2);
|
||||
|
||||
form_field_type_t result = form_get_field_type(form, "tag2");
|
||||
|
||||
assert_int_equal(result, FIELD_TEXT_MULTI);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_set_value__updates__adds_when_none(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_TEXT_SINGLE;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value1"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
FormField* field2 = _new_field();
|
||||
field2->var = g_strdup("var2");
|
||||
field2->type_t = FIELD_LIST_SINGLE;
|
||||
form->fields = g_slist_append(form->fields, field2);
|
||||
|
||||
form_set_value(form, "tag2", "a new value");
|
||||
|
||||
int length = 0;
|
||||
char* value = NULL;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var2") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
value = field->values->data;
|
||||
break;
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_int_equal(length, 1);
|
||||
assert_string_equal(value, "a new value");
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_set_value__updates__updates_when_one(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_TEXT_SINGLE;
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
FormField* field2 = _new_field();
|
||||
field2->var = g_strdup("var2");
|
||||
field2->type_t = FIELD_LIST_SINGLE;
|
||||
field2->values = g_slist_append(field2->values, g_strdup("value2"));
|
||||
form->fields = g_slist_append(form->fields, field2);
|
||||
|
||||
form_set_value(form, "tag2", "a new value");
|
||||
|
||||
int length = 0;
|
||||
char* value = NULL;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var2") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
value = field->values->data;
|
||||
break;
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_int_equal(length, 1);
|
||||
assert_string_equal(value, "a new value");
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_add_unique_value__updates__adds_when_none(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_JID_MULTI;
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
FormField* field2 = _new_field();
|
||||
field2->var = g_strdup("var2");
|
||||
field2->type_t = FIELD_LIST_SINGLE;
|
||||
field2->values = g_slist_append(field2->values, g_strdup("value2"));
|
||||
form->fields = g_slist_append(form->fields, field2);
|
||||
|
||||
gboolean ret = form_add_unique_value(form, "tag1", "me@server.com");
|
||||
|
||||
int length = 0;
|
||||
char* value = NULL;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
value = field->values->data;
|
||||
break;
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_true(ret);
|
||||
assert_int_equal(length, 1);
|
||||
assert_string_equal(value, "me@server.com");
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_add_unique_value__updates__does_nothing_when_exists(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_JID_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("me@server.com"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
FormField* field2 = _new_field();
|
||||
field2->var = g_strdup("var2");
|
||||
field2->type_t = FIELD_LIST_SINGLE;
|
||||
field2->values = g_slist_append(field2->values, g_strdup("value2"));
|
||||
form->fields = g_slist_append(form->fields, field2);
|
||||
|
||||
gboolean ret = form_add_unique_value(form, "tag1", "me@server.com");
|
||||
|
||||
int length = 0;
|
||||
char* value = NULL;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
value = field->values->data;
|
||||
break;
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_false(ret);
|
||||
assert_int_equal(length, 1);
|
||||
assert_string_equal(value, "me@server.com");
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_add_unique_value__updates__adds_when_doesnt_exist(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag2"), g_strdup("var2"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_JID_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("dolan@server.com"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("kieran@server.com"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("chi@server.com"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
FormField* field2 = _new_field();
|
||||
field2->var = g_strdup("var2");
|
||||
field2->type_t = FIELD_LIST_SINGLE;
|
||||
field2->values = g_slist_append(field2->values, g_strdup("value2"));
|
||||
form->fields = g_slist_append(form->fields, field2);
|
||||
|
||||
gboolean ret = form_add_unique_value(form, "tag1", "me@server.com");
|
||||
|
||||
int length = 0;
|
||||
int count = 0;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
GSList* curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
if (g_strcmp0(curr_value->data, "me@server.com") == 0) {
|
||||
count++;
|
||||
}
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_true(ret);
|
||||
assert_int_equal(length, 4);
|
||||
assert_int_equal(count, 1);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_add_value__updates__adds_when_none(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
form_add_value(form, "tag1", "somevalue");
|
||||
|
||||
int length = 0;
|
||||
char* value = NULL;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
value = field->values->data;
|
||||
break;
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_int_equal(length, 1);
|
||||
assert_string_equal(value, "somevalue");
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_add_value__updates__adds_when_some(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("some text"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("some more text"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("yet some more text"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
form_add_value(form, "tag1", "new value");
|
||||
|
||||
int num_values = 0;
|
||||
int new_value_count = 0;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
GSList* curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
num_values++;
|
||||
if (g_strcmp0(curr_value->data, "new value") == 0) {
|
||||
new_value_count++;
|
||||
}
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_int_equal(num_values, 4);
|
||||
assert_int_equal(new_value_count, 1);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_add_value__updates__adds_when_exists(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("some text"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("some more text"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("yet some more text"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("new value"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
form_add_value(form, "tag1", "new value");
|
||||
|
||||
int num_values = 0;
|
||||
int new_value_count = 0;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
GSList* curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
num_values++;
|
||||
if (g_strcmp0(curr_value->data, "new value") == 0) {
|
||||
new_value_count++;
|
||||
}
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_int_equal(num_values, 5);
|
||||
assert_int_equal(new_value_count, 2);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_remove_value__updates__does_nothing_when_none(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
gboolean res = form_remove_value(form, "tag1", "some value");
|
||||
|
||||
int length = -1;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_false(res);
|
||||
assert_int_equal(length, 0);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_remove_value__updates__does_nothing_when_doesnt_exist(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value1"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value2"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value3"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value4"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
gboolean res = form_remove_value(form, "tag1", "value5");
|
||||
|
||||
int length = -1;
|
||||
int value_count = 0;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
GSList* curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
if (g_strcmp0(curr_value->data, "value5") == 0) {
|
||||
value_count++;
|
||||
}
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_false(res);
|
||||
assert_int_equal(length, 4);
|
||||
assert_int_equal(value_count, 0);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_remove_value__updates__removes_when_one(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value4"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
gboolean res = form_remove_value(form, "tag1", "value4");
|
||||
|
||||
int length = -1;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_true(res);
|
||||
assert_int_equal(length, 0);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_remove_value__updates__removes_when_many(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value1"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value2"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value3"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value4"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
gboolean res = form_remove_value(form, "tag1", "value2");
|
||||
|
||||
int length = -1;
|
||||
int value_count = 0;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
GSList* curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
if (g_strcmp0(curr_value->data, "value2") == 0) {
|
||||
value_count++;
|
||||
}
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_true(res);
|
||||
assert_int_equal(length, 3);
|
||||
assert_int_equal(value_count, 0);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_remove_text_multi_value__updates__does_nothing_when_none(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
gboolean res = form_remove_text_multi_value(form, "tag1", 3);
|
||||
|
||||
int length = -1;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_false(res);
|
||||
assert_int_equal(length, 0);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_remove_text_multi_value__updates__does_nothing_when_doesnt_exist(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value1"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value2"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value3"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value4"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
gboolean res = form_remove_text_multi_value(form, "tag1", 5);
|
||||
|
||||
int length = -1;
|
||||
int value_count = 0;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
GSList* curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
if (g_strcmp0(curr_value->data, "value5") == 0) {
|
||||
value_count++;
|
||||
}
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_false(res);
|
||||
assert_int_equal(length, 4);
|
||||
assert_int_equal(value_count, 0);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_remove_text_multi_value__updates__removes_when_one(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value4"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
gboolean res = form_remove_text_multi_value(form, "tag1", 1);
|
||||
|
||||
int length = -1;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_true(res);
|
||||
assert_int_equal(length, 0);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
|
||||
void
|
||||
form_remove_text_multi_value__updates__removes_when_many(void** state)
|
||||
{
|
||||
DataForm* form = _new_form();
|
||||
g_hash_table_insert(form->tag_to_var, g_strdup("tag1"), g_strdup("var1"));
|
||||
|
||||
FormField* field1 = _new_field();
|
||||
field1->var = g_strdup("var1");
|
||||
field1->type_t = FIELD_LIST_MULTI;
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value1"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value2"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value3"));
|
||||
field1->values = g_slist_append(field1->values, g_strdup("value4"));
|
||||
form->fields = g_slist_append(form->fields, field1);
|
||||
|
||||
gboolean res = form_remove_text_multi_value(form, "tag1", 2);
|
||||
|
||||
int length = -1;
|
||||
int value_count = 0;
|
||||
GSList* curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField* field = curr_field->data;
|
||||
if (g_strcmp0(field->var, "var1") == 0) {
|
||||
length = g_slist_length(field->values);
|
||||
GSList* curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
if (g_strcmp0(curr_value->data, "value2") == 0) {
|
||||
value_count++;
|
||||
}
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
}
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
assert_true(res);
|
||||
assert_int_equal(length, 3);
|
||||
assert_int_equal(value_count, 0);
|
||||
|
||||
form_destroy(form);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef TESTS_TEST_FORM_H
|
||||
#define TESTS_TEST_FORM_H
|
||||
|
||||
void form_get_form_type_field__returns__null_no_fields(void** state);
|
||||
void form_get_form_type_field__returns__null_when_not_present(void** state);
|
||||
void form_get_form_type_field__returns__value_when_present(void** state);
|
||||
void form_get_field_type__returns__unknown_when_no_fields(void** state);
|
||||
void form_get_field_type__returns__correct_type(void** state);
|
||||
void form_set_value__updates__adds_when_none(void** state);
|
||||
void form_set_value__updates__updates_when_one(void** state);
|
||||
void form_add_unique_value__updates__adds_when_none(void** state);
|
||||
void form_add_unique_value__updates__does_nothing_when_exists(void** state);
|
||||
void form_add_unique_value__updates__adds_when_doesnt_exist(void** state);
|
||||
void form_add_value__updates__adds_when_none(void** state);
|
||||
void form_add_value__updates__adds_when_some(void** state);
|
||||
void form_add_value__updates__adds_when_exists(void** state);
|
||||
void form_remove_value__updates__does_nothing_when_none(void** state);
|
||||
void form_remove_value__updates__does_nothing_when_doesnt_exist(void** state);
|
||||
void form_remove_value__updates__removes_when_one(void** state);
|
||||
void form_remove_value__updates__removes_when_many(void** state);
|
||||
void form_remove_text_multi_value__updates__does_nothing_when_none(void** state);
|
||||
void form_remove_text_multi_value__updates__does_nothing_when_doesnt_exist(void** state);
|
||||
void form_remove_text_multi_value__updates__removes_when_one(void** state);
|
||||
void form_remove_text_multi_value__updates__removes_when_many(void** state);
|
||||
|
||||
#endif
|
||||
@@ -1,372 +0,0 @@
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/jid.h"
|
||||
|
||||
void
|
||||
jid_create__returns__null_from_null(void** state)
|
||||
{
|
||||
Jid* result = jid_create(NULL);
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__null_from_empty_string(void** state)
|
||||
{
|
||||
Jid* result = jid_create("");
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__full_from_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser@mydomain/laptop", result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__bare_from_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser@mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__resourcepart_from_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("laptop", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__localpart_from_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser", result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__domainpart_from_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__full_from_full_nolocal(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain/laptop", result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__bare_from_full_nolocal(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__resourcepart_from_full_nolocal(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("laptop", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__domainpart_from_full_nolocal(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__null_localpart_from_full_nolocal(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_null(result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__null_full_from_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_null(result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__null_resource_from_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_null(result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__bare_from_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("myuser@mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__localpart_from_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("myuser", result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__domainpart_from_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create_from_bare_and_resource__returns__room(void** state)
|
||||
{
|
||||
Jid* result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
|
||||
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create_from_bare_and_resource__returns__nick(void** state)
|
||||
{
|
||||
Jid* result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
|
||||
|
||||
assert_string_equal("myname", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__correct_parts_with_slash_in_resource(void** state)
|
||||
{
|
||||
Jid* result = jid_create("room@conference.domain.org/my/nick");
|
||||
|
||||
assert_string_equal("room", result->localpart);
|
||||
assert_string_equal("conference.domain.org", result->domainpart);
|
||||
assert_string_equal("my/nick", result->resourcepart);
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
assert_string_equal("room@conference.domain.org/my/nick", result->fulljid);
|
||||
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__correct_parts_with_at_in_resource(void** state)
|
||||
{
|
||||
Jid* result = jid_create("room@conference.domain.org/my@nick");
|
||||
|
||||
assert_string_equal("room", result->localpart);
|
||||
assert_string_equal("conference.domain.org", result->domainpart);
|
||||
assert_string_equal("my@nick", result->resourcepart);
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
assert_string_equal("room@conference.domain.org/my@nick", result->fulljid);
|
||||
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__correct_parts_with_at_and_slash_in_resource(void** state)
|
||||
{
|
||||
Jid* result = jid_create("room@conference.domain.org/my@nick/something");
|
||||
|
||||
assert_string_equal("room", result->localpart);
|
||||
assert_string_equal("conference.domain.org", result->domainpart);
|
||||
assert_string_equal("my@nick/something", result->resourcepart);
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
assert_string_equal("room@conference.domain.org/my@nick/something", result->fulljid);
|
||||
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__correct_parts_with_trailing_slash(void** state)
|
||||
{
|
||||
Jid* result = jid_create("room@conference.domain.org/nick/");
|
||||
|
||||
assert_string_equal("room", result->localpart);
|
||||
assert_string_equal("conference.domain.org", result->domainpart);
|
||||
assert_string_equal("nick/", result->resourcepart);
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
assert_string_equal("room@conference.domain.org/nick/", result->fulljid);
|
||||
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_fulljid_or_barejid__returns__fulljid_when_exists(void** state)
|
||||
{
|
||||
Jid* jid = jid_create("localpart@domainpart/resourcepart");
|
||||
|
||||
const gchar* result = jid_fulljid_or_barejid(jid);
|
||||
|
||||
assert_string_equal("localpart@domainpart/resourcepart", result);
|
||||
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
void
|
||||
jid_fulljid_or_barejid__returns__barejid_when_fulljid_not_exists(void** state)
|
||||
{
|
||||
Jid* jid = jid_create("localpart@domainpart");
|
||||
|
||||
const gchar* result = jid_fulljid_or_barejid(jid);
|
||||
|
||||
assert_string_equal("localpart@domainpart", result);
|
||||
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__bare_from_trailing_slash(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/");
|
||||
assert_non_null(result);
|
||||
assert_string_equal("myuser@mydomain", result->barejid);
|
||||
assert_null(result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__null_from_invalid_localpart_chars(void** state)
|
||||
{
|
||||
// Space
|
||||
Jid* result = jid_create("user name@domain.com");
|
||||
assert_null(result);
|
||||
|
||||
// Double quote
|
||||
result = jid_create("user\"name@domain.com");
|
||||
assert_null(result);
|
||||
|
||||
// Ampersand
|
||||
result = jid_create("user&name@domain.com");
|
||||
assert_null(result);
|
||||
|
||||
// Single quote
|
||||
result = jid_create("user'name@domain.com");
|
||||
assert_null(result);
|
||||
|
||||
// Colon
|
||||
result = jid_create("user:name@domain.com");
|
||||
assert_null(result);
|
||||
|
||||
// Less than
|
||||
result = jid_create("user<name@domain.com");
|
||||
assert_null(result);
|
||||
|
||||
// Greater than
|
||||
result = jid_create("user>name@domain.com");
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__null_from_empty_parts(void** state)
|
||||
{
|
||||
// Empty local
|
||||
Jid* result = jid_create("@domain.com");
|
||||
assert_null(result);
|
||||
|
||||
// Empty domain (trailing @)
|
||||
result = jid_create("user@");
|
||||
assert_null(result);
|
||||
|
||||
// Empty domain in full jid
|
||||
result = jid_create("user@/resource");
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__null_from_multiple_at_in_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("user@domain@other.com");
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_create__returns__correct_parts_with_at_in_resource_only(void** state)
|
||||
{
|
||||
// domain.com/user@host (no localpart)
|
||||
Jid* result = jid_create("domain.com/user@host");
|
||||
assert_non_null(result);
|
||||
assert_null(result->localpart);
|
||||
assert_string_equal("domain.com", result->domainpart);
|
||||
assert_string_equal("user@host", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
jid_is_valid_user_jid__is__true_for_valid_user_jid(void** state)
|
||||
{
|
||||
assert_true(jid_is_valid_user_jid("myuser@mydomain/laptop"));
|
||||
assert_true(jid_is_valid_user_jid("myuser@mydomain"));
|
||||
}
|
||||
|
||||
void
|
||||
jid_is_valid_user_jid__is__true_for_at_in_resource(void** state)
|
||||
{
|
||||
// RFC 6122 section 2.4: '@' is allowed in the resourcepart.
|
||||
assert_true(jid_is_valid_user_jid("myuser@mydomain/user@laptop"));
|
||||
assert_true(jid_is_valid_user_jid("room@conference.example.org/user@host.example.org"));
|
||||
}
|
||||
|
||||
void
|
||||
jid_is_valid_user_jid__is__false_for_domain_jid(void** state)
|
||||
{
|
||||
assert_false(jid_is_valid_user_jid("mydomain/laptop"));
|
||||
assert_false(jid_is_valid_user_jid("mydomain"));
|
||||
}
|
||||
|
||||
void
|
||||
jid_is_valid_user_jid__is__false_for_invalid_jid(void** state)
|
||||
{
|
||||
assert_false(jid_is_valid_user_jid("@mydomain"));
|
||||
assert_false(jid_is_valid_user_jid("/laptop"));
|
||||
assert_false(jid_is_valid_user_jid(NULL));
|
||||
assert_false(jid_is_valid_user_jid(""));
|
||||
}
|
||||
|
||||
void
|
||||
jid_is_valid__is__true_for_valid_jid(void** state)
|
||||
{
|
||||
assert_true(jid_is_valid("myuser@mydomain/laptop"));
|
||||
assert_true(jid_is_valid("myuser@mydomain"));
|
||||
assert_true(jid_is_valid("mydomain/laptop"));
|
||||
assert_true(jid_is_valid("mydomain"));
|
||||
}
|
||||
|
||||
void
|
||||
jid_is_valid__is__false_for_invalid_jid(void** state)
|
||||
{
|
||||
assert_false(jid_is_valid("@mydomain"));
|
||||
assert_false(jid_is_valid("/laptop"));
|
||||
}
|
||||
|
||||
void
|
||||
jid_is_valid__is__false_for_null(void** state)
|
||||
{
|
||||
assert_false(jid_is_valid(NULL));
|
||||
}
|
||||
|
||||
void
|
||||
jid_is_valid__is__false_for_empty_string(void** state)
|
||||
{
|
||||
assert_false(jid_is_valid(""));
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef TESTS_TEST_JID_H
|
||||
#define TESTS_TEST_JID_H
|
||||
|
||||
void jid_create__returns__null_from_null(void** state);
|
||||
void jid_create__returns__null_from_empty_string(void** state);
|
||||
void jid_create__returns__full_from_full(void** state);
|
||||
void jid_create__returns__bare_from_full(void** state);
|
||||
void jid_create__returns__resourcepart_from_full(void** state);
|
||||
void jid_create__returns__localpart_from_full(void** state);
|
||||
void jid_create__returns__domainpart_from_full(void** state);
|
||||
void jid_create__returns__full_from_full_nolocal(void** state);
|
||||
void jid_create__returns__bare_from_full_nolocal(void** state);
|
||||
void jid_create__returns__resourcepart_from_full_nolocal(void** state);
|
||||
void jid_create__returns__domainpart_from_full_nolocal(void** state);
|
||||
void jid_create__returns__null_localpart_from_full_nolocal(void** state);
|
||||
void jid_create__returns__null_full_from_bare(void** state);
|
||||
void jid_create__returns__null_resource_from_bare(void** state);
|
||||
void jid_create__returns__bare_from_bare(void** state);
|
||||
void jid_create__returns__localpart_from_bare(void** state);
|
||||
void jid_create__returns__domainpart_from_bare(void** state);
|
||||
void jid_create_from_bare_and_resource__returns__room(void** state);
|
||||
void jid_create_from_bare_and_resource__returns__nick(void** state);
|
||||
void jid_create__returns__correct_parts_with_slash_in_resource(void** state);
|
||||
void jid_create__returns__correct_parts_with_at_in_resource(void** state);
|
||||
void jid_create__returns__correct_parts_with_at_and_slash_in_resource(void** state);
|
||||
void jid_create__returns__correct_parts_with_trailing_slash(void** state);
|
||||
void jid_fulljid_or_barejid__returns__fulljid_when_exists(void** state);
|
||||
void jid_fulljid_or_barejid__returns__barejid_when_fulljid_not_exists(void** state);
|
||||
void jid_create__returns__bare_from_trailing_slash(void** state);
|
||||
void jid_create__returns__null_from_invalid_localpart_chars(void** state);
|
||||
void jid_create__returns__null_from_empty_parts(void** state);
|
||||
void jid_create__returns__null_from_multiple_at_in_bare(void** state);
|
||||
void jid_create__returns__correct_parts_with_at_in_resource_only(void** state);
|
||||
void jid_is_valid_user_jid__is__true_for_valid_user_jid(void** state);
|
||||
void jid_is_valid_user_jid__is__true_for_at_in_resource(void** state);
|
||||
void jid_is_valid_user_jid__is__false_for_domain_jid(void** state);
|
||||
void jid_is_valid_user_jid__is__false_for_invalid_jid(void** state);
|
||||
void jid_is_valid__is__true_for_valid_jid(void** state);
|
||||
void jid_is_valid__is__false_for_invalid_jid(void** state);
|
||||
void jid_is_valid__is__false_for_null(void** state);
|
||||
void jid_is_valid__is__false_for_empty_string(void** state);
|
||||
|
||||
#endif
|
||||
@@ -1,87 +0,0 @@
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/muc.h"
|
||||
|
||||
void prof_shutdown(void);
|
||||
|
||||
int
|
||||
muc_before_test(void** state)
|
||||
{
|
||||
muc_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
muc_after_test(void** state)
|
||||
{
|
||||
prof_shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
muc_invites_add__updates__invites_list(void** state)
|
||||
{
|
||||
char* room = "room@conf.server";
|
||||
muc_invites_add(room, NULL);
|
||||
|
||||
gboolean invite_exists = muc_invites_contain(room);
|
||||
|
||||
assert_true(invite_exists);
|
||||
}
|
||||
|
||||
void
|
||||
muc_invites_remove__updates__invites_list(void** state)
|
||||
{
|
||||
char* room = "room@conf.server";
|
||||
muc_invites_add(room, NULL);
|
||||
muc_invites_remove(room);
|
||||
|
||||
gboolean invite_exists = muc_invites_contain(room);
|
||||
|
||||
assert_false(invite_exists);
|
||||
}
|
||||
|
||||
void
|
||||
muc_invites_count__returns__0_when_no_invites(void** state)
|
||||
{
|
||||
int invite_count = muc_invites_count();
|
||||
|
||||
assert_true(invite_count == 0);
|
||||
}
|
||||
|
||||
void
|
||||
muc_invites_count__returns__5_when_five_invites_added(void** state)
|
||||
{
|
||||
muc_invites_add("room1@conf.server", NULL);
|
||||
muc_invites_add("room2@conf.server", NULL);
|
||||
muc_invites_add("room3@conf.server", NULL);
|
||||
muc_invites_add("room4@conf.server", NULL);
|
||||
muc_invites_add("room5@conf.server", NULL);
|
||||
|
||||
int invite_count = muc_invites_count();
|
||||
|
||||
assert_true(invite_count == 5);
|
||||
}
|
||||
|
||||
void
|
||||
muc_active__is__false_when_not_joined(void** state)
|
||||
{
|
||||
char* room = "room@server.org";
|
||||
|
||||
gboolean room_is_active = muc_active(room);
|
||||
|
||||
assert_false(room_is_active);
|
||||
}
|
||||
|
||||
void
|
||||
muc_active__is__true_when_joined(void** state)
|
||||
{
|
||||
char* room = "room@server.org";
|
||||
char* nick = "bob";
|
||||
muc_join(room, nick, NULL, FALSE);
|
||||
|
||||
gboolean room_is_active = muc_active(room);
|
||||
|
||||
assert_true(room_is_active);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef TESTS_TEST_MUC_H
|
||||
#define TESTS_TEST_MUC_H
|
||||
|
||||
int muc_before_test(void** state);
|
||||
int muc_after_test(void** state);
|
||||
|
||||
void muc_invites_add__updates__invites_list(void** state);
|
||||
void muc_invites_remove__updates__invites_list(void** state);
|
||||
void muc_invites_count__returns__0_when_no_invites(void** state);
|
||||
void muc_invites_count__returns__5_when_five_invites_added(void** state);
|
||||
void muc_active__is__false_when_not_joined(void** state);
|
||||
void muc_active__is__true_when_joined(void** state);
|
||||
|
||||
#endif
|
||||
@@ -1,742 +0,0 @@
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/contact.h"
|
||||
#include "xmpp/roster_list.h"
|
||||
|
||||
void
|
||||
roster_get_contacts__returns__empty_list_when_none_added(void** state)
|
||||
{
|
||||
roster_create();
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
assert_null(list);
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_contacts__returns__one_element(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
assert_int_equal(1, g_slist_length(list));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_contacts__returns__correct_first_element(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
PContact james = list->data;
|
||||
|
||||
assert_string_equal("James", p_contact_barejid(james));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_contacts__returns__two_elements(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
|
||||
assert_int_equal(2, g_slist_length(list));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_contacts__returns__correct_first_and_second_elements(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
|
||||
PContact first = list->data;
|
||||
PContact second = (g_slist_next(list))->data;
|
||||
|
||||
assert_string_equal("Dave", p_contact_barejid(first));
|
||||
assert_string_equal("James", p_contact_barejid(second));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_contacts__returns__three_elements(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
|
||||
assert_int_equal(3, g_slist_length(list));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_contacts__returns__correct_first_three_elements(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
PContact bob = list->data;
|
||||
PContact dave = (g_slist_next(list))->data;
|
||||
PContact james = (g_slist_next(g_slist_next(list)))->data;
|
||||
|
||||
assert_string_equal("James", p_contact_barejid(james));
|
||||
assert_string_equal("Dave", p_contact_barejid(dave));
|
||||
assert_string_equal("Bob", p_contact_barejid(bob));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_add__updates__adds_once_when_called_twice_at_beginning(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
PContact first = list->data;
|
||||
PContact second = (g_slist_next(list))->data;
|
||||
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
||||
|
||||
assert_int_equal(3, g_slist_length(list));
|
||||
assert_string_equal("Bob", p_contact_barejid(first));
|
||||
assert_string_equal("Dave", p_contact_barejid(second));
|
||||
assert_string_equal("James", p_contact_barejid(third));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_add__updates__adds_once_when_called_twice_in_middle(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
PContact first = list->data;
|
||||
PContact second = (g_slist_next(list))->data;
|
||||
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
||||
|
||||
assert_int_equal(3, g_slist_length(list));
|
||||
assert_string_equal("Bob", p_contact_barejid(first));
|
||||
assert_string_equal("Dave", p_contact_barejid(second));
|
||||
assert_string_equal("James", p_contact_barejid(third));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_add__updates__adds_once_when_called_twice_at_end(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
GSList* list = roster_get_contacts(ROSTER_ORD_NAME);
|
||||
PContact first = list->data;
|
||||
PContact second = (g_slist_next(list))->data;
|
||||
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
||||
|
||||
assert_int_equal(3, g_slist_length(list));
|
||||
assert_string_equal("Bob", p_contact_barejid(first));
|
||||
assert_string_equal("Dave", p_contact_barejid(second));
|
||||
assert_string_equal("James", p_contact_barejid(third));
|
||||
|
||||
g_slist_free(list);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__first_exists(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
|
||||
char* search = g_strdup("B");
|
||||
|
||||
char* result = roster_contact_autocomplete(search, FALSE, NULL);
|
||||
assert_string_equal("Bob", result);
|
||||
g_free(result);
|
||||
g_free(search);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__second_exists(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
|
||||
char* result = roster_contact_autocomplete("Dav", FALSE, NULL);
|
||||
assert_string_equal("Dave", result);
|
||||
g_free(result);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__third_exists(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
|
||||
char* result = roster_contact_autocomplete("Ja", FALSE, NULL);
|
||||
assert_string_equal("James", result);
|
||||
g_free(result);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__null_when_no_match(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
|
||||
char* result = roster_contact_autocomplete("Mike", FALSE, NULL);
|
||||
assert_null(result);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__null_on_empty_roster(void** state)
|
||||
{
|
||||
roster_create();
|
||||
char* result = roster_contact_autocomplete("James", FALSE, NULL);
|
||||
assert_null(result);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__second_when_two_match(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Jamie", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
|
||||
char* result1 = roster_contact_autocomplete("Jam", FALSE, NULL);
|
||||
char* result2 = roster_contact_autocomplete(result1, FALSE, NULL);
|
||||
assert_string_equal("Jamie", result2);
|
||||
g_free(result1);
|
||||
g_free(result2);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__fifth_when_multiple_match(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("Jama", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Jamb", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Mike", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Jamm", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Jamn", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Matt", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Jamo", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Jamy", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Jamz", NULL, NULL, NULL, FALSE);
|
||||
|
||||
char* result1 = roster_contact_autocomplete("Jam", FALSE, NULL);
|
||||
char* result2 = roster_contact_autocomplete(result1, FALSE, NULL);
|
||||
char* result3 = roster_contact_autocomplete(result2, FALSE, NULL);
|
||||
char* result4 = roster_contact_autocomplete(result3, FALSE, NULL);
|
||||
char* result5 = roster_contact_autocomplete(result4, FALSE, NULL);
|
||||
assert_string_equal("Jamo", result5);
|
||||
g_free(result1);
|
||||
g_free(result2);
|
||||
g_free(result3);
|
||||
g_free(result4);
|
||||
g_free(result5);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__first_when_two_match_and_reset(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Jamie", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||
|
||||
char* result1 = roster_contact_autocomplete("Jam", FALSE, NULL);
|
||||
roster_reset_search_attempts();
|
||||
char* result2 = roster_contact_autocomplete(result1, FALSE, NULL);
|
||||
assert_string_equal("James", result2);
|
||||
g_free(result1);
|
||||
g_free(result2);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__utf8(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("Σωκράτης", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Πλάτων", NULL, NULL, NULL, FALSE);
|
||||
|
||||
// Byte-wise (strcmp): Πλάτων (CE A0...) < Σωκράτης (CE A3...)
|
||||
char* result = roster_contact_autocomplete("Π", FALSE, NULL);
|
||||
assert_string_equal("Πλάτων", result);
|
||||
g_free(result);
|
||||
|
||||
roster_reset_search_attempts();
|
||||
|
||||
result = roster_contact_autocomplete("σω", FALSE, NULL);
|
||||
assert_string_equal("Σωκράτης", result);
|
||||
g_free(result);
|
||||
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_groups__returns__empty_for_no_group(void** state)
|
||||
|
||||
{
|
||||
roster_create();
|
||||
roster_add("person@server.org", NULL, NULL, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 0);
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_groups__returns__one_group(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups = NULL;
|
||||
groups = g_slist_append(groups, g_strdup("friends"));
|
||||
roster_add("person@server.org", NULL, groups, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 1);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "friends");
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_groups__returns__two_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups = NULL;
|
||||
groups = g_slist_append(groups, g_strdup("friends"));
|
||||
groups = g_slist_append(groups, g_strdup("work"));
|
||||
roster_add("person@server.org", NULL, groups, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 2);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "friends");
|
||||
found = g_list_find_custom(groups_res, "work", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "work");
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_groups__returns__three_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups = NULL;
|
||||
groups = g_slist_append(groups, g_strdup("friends"));
|
||||
groups = g_slist_append(groups, g_strdup("work"));
|
||||
groups = g_slist_append(groups, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 3);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "friends");
|
||||
found = g_list_find_custom(groups_res, "work", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "work");
|
||||
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "stuff");
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_update__updates__adding_two_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
GSList* groups2 = NULL;
|
||||
groups2 = g_slist_append(groups2, g_strdup("friends"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("work"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("stuff"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("things"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("people"));
|
||||
roster_update("person@server.org", NULL, groups2, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 5);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "friends");
|
||||
found = g_list_find_custom(groups_res, "work", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "work");
|
||||
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "stuff");
|
||||
found = g_list_find_custom(groups_res, "things", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "things");
|
||||
found = g_list_find_custom(groups_res, "people", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "people");
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_update__updates__removing_one_group(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
GSList* groups2 = NULL;
|
||||
groups2 = g_slist_append(groups2, g_strdup("friends"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("stuff"));
|
||||
roster_update("person@server.org", NULL, groups2, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 2);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "friends");
|
||||
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "stuff");
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_update__updates__removing_two_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
GSList* groups2 = NULL;
|
||||
groups2 = g_slist_append(groups2, g_strdup("stuff"));
|
||||
roster_update("person@server.org", NULL, groups2, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 1);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
assert_string_equal(found->data, "stuff");
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_update__updates__removing_three_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
roster_update("person@server.org", NULL, NULL, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 0);
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_update__updates__two_new_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
GSList* groups2 = NULL;
|
||||
groups2 = g_slist_append(groups2, g_strdup("newfriends"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("somepeople"));
|
||||
roster_update("person@server.org", NULL, groups2, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 2);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "newfriends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "somepeople", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_remove__updates__contact_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
roster_remove("person@server.org", "person@server.org");
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 0);
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_add__updates__different_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
GSList* groups2 = NULL;
|
||||
groups2 = g_slist_append(groups2, g_strdup("newfriends"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("somepeople"));
|
||||
roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 5);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "work", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "newfriends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "somepeople", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_add__updates__same_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
GSList* groups2 = NULL;
|
||||
groups2 = g_slist_append(groups2, g_strdup("friends"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("work"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("stuff"));
|
||||
roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 3);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "work", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_add__updates__overlapping_groups(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
GSList* groups2 = NULL;
|
||||
groups2 = g_slist_append(groups2, g_strdup("friends"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("work"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("different"));
|
||||
roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 4);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "work", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "different", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_remove__updates__remaining_in_group(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
GSList* groups1 = NULL;
|
||||
groups1 = g_slist_append(groups1, g_strdup("friends"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("work"));
|
||||
groups1 = g_slist_append(groups1, g_strdup("stuff"));
|
||||
roster_add("person@server.org", NULL, groups1, NULL, FALSE);
|
||||
|
||||
GSList* groups2 = NULL;
|
||||
groups2 = g_slist_append(groups2, g_strdup("friends"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("work"));
|
||||
groups2 = g_slist_append(groups2, g_strdup("different"));
|
||||
roster_add("bob@server.org", NULL, groups2, NULL, FALSE);
|
||||
|
||||
roster_remove("bob@server.org", "bob@server.org");
|
||||
|
||||
GList* groups_res = roster_get_groups();
|
||||
assert_int_equal(g_list_length(groups_res), 3);
|
||||
|
||||
GList* found = g_list_find_custom(groups_res, "friends", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "work", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
found = g_list_find_custom(groups_res, "stuff", (GCompareFunc)g_strcmp0);
|
||||
assert_true(found != NULL);
|
||||
|
||||
g_list_free_full(groups_res, g_free);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_display_name__returns__nickname_when_exists(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("person@server.org", "nickname", NULL, NULL, FALSE);
|
||||
|
||||
assert_string_equal("nickname", roster_get_display_name("person@server.org"));
|
||||
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_display_name__returns__barejid_when_nickname_empty(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("person@server.org", NULL, NULL, NULL, FALSE);
|
||||
|
||||
assert_string_equal("person@server.org", roster_get_display_name("person@server.org"));
|
||||
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_display_name__returns__barejid_when_not_exists(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
assert_string_equal("person@server.org", roster_get_display_name("person@server.org"));
|
||||
|
||||
roster_destroy();
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
#ifndef TESTS_TEST_ROSTER_LIST_H
|
||||
#define TESTS_TEST_ROSTER_LIST_H
|
||||
|
||||
void roster_get_contacts__returns__empty_list_when_none_added(void** state);
|
||||
void roster_get_contacts__returns__one_element(void** state);
|
||||
void roster_get_contacts__returns__correct_first_element(void** state);
|
||||
void roster_get_contacts__returns__two_elements(void** state);
|
||||
void roster_get_contacts__returns__correct_first_and_second_elements(void** state);
|
||||
void roster_get_contacts__returns__three_elements(void** state);
|
||||
void roster_get_contacts__returns__correct_first_three_elements(void** state);
|
||||
void roster_add__updates__adds_once_when_called_twice_at_beginning(void** state);
|
||||
void roster_add__updates__adds_once_when_called_twice_in_middle(void** state);
|
||||
void roster_add__updates__adds_once_when_called_twice_at_end(void** state);
|
||||
void roster_contact_autocomplete__returns__first_exists(void** state);
|
||||
void roster_contact_autocomplete__returns__second_exists(void** state);
|
||||
void roster_contact_autocomplete__returns__third_exists(void** state);
|
||||
void roster_contact_autocomplete__returns__null_when_no_match(void** state);
|
||||
void roster_contact_autocomplete__returns__null_on_empty_roster(void** state);
|
||||
void roster_contact_autocomplete__returns__second_when_two_match(void** state);
|
||||
void roster_contact_autocomplete__returns__fifth_when_multiple_match(void** state);
|
||||
void roster_contact_autocomplete__returns__first_when_two_match_and_reset(void** state);
|
||||
void roster_contact_autocomplete__returns__utf8(void** state);
|
||||
void roster_get_groups__returns__empty_for_no_group(void** state);
|
||||
void roster_get_groups__returns__one_group(void** state);
|
||||
void roster_get_groups__returns__two_groups(void** state);
|
||||
void roster_get_groups__returns__three_groups(void** state);
|
||||
void roster_update__updates__adding_two_groups(void** state);
|
||||
void roster_update__updates__removing_one_group(void** state);
|
||||
void roster_update__updates__removing_two_groups(void** state);
|
||||
void roster_update__updates__removing_three_groups(void** state);
|
||||
void roster_update__updates__two_new_groups(void** state);
|
||||
void roster_remove__updates__contact_groups(void** state);
|
||||
void roster_add__updates__different_groups(void** state);
|
||||
void roster_add__updates__same_groups(void** state);
|
||||
void roster_add__updates__overlapping_groups(void** state);
|
||||
void roster_remove__updates__remaining_in_group(void** state);
|
||||
void roster_get_display_name__returns__nickname_when_exists(void** state);
|
||||
void roster_get_display_name__returns__barejid_when_nickname_empty(void** state);
|
||||
void roster_get_display_name__returns__barejid_when_not_exists(void** state);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user