mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-27 06:46:21 +00:00
cleanup: Map test files according to structure in src
For example cmd_account() is located in src/command/cmd_funcs.c. The unit test was located in tests/unittests/test_cmd_account.c. Let's move it to a subdirectory like tests/unittests/command/test_cmd_account.c to correpsond to the same structure.
This commit is contained in:
52
tests/unittests/xmpp/test_chat_session.c
Normal file
52
tests/unittests/xmpp/test_chat_session.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/chat_session.h"
|
||||
|
||||
void
|
||||
returns_false_when_chat_session_does_not_exist(void** state)
|
||||
{
|
||||
ChatSession* session = chat_session_get("somejid@server.org");
|
||||
assert_null(session);
|
||||
}
|
||||
|
||||
void
|
||||
creates_chat_session_on_recipient_activity(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
|
||||
replaces_chat_session_on_recipient_activity_with_different_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
|
||||
removes_chat_session(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);
|
||||
}
|
||||
4
tests/unittests/xmpp/test_chat_session.h
Normal file
4
tests/unittests/xmpp/test_chat_session.h
Normal file
@@ -0,0 +1,4 @@
|
||||
void returns_false_when_chat_session_does_not_exist(void** state);
|
||||
void creates_chat_session_on_recipient_activity(void** state);
|
||||
void replaces_chat_session_on_recipient_activity_with_different_resource(void** state);
|
||||
void removes_chat_session(void** state);
|
||||
428
tests/unittests/xmpp/test_contact.c
Normal file
428
tests/unittests/xmpp/test_contact.c
Normal file
@@ -0,0 +1,428 @@
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/contact.h"
|
||||
|
||||
void
|
||||
contact_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
|
||||
contact_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
|
||||
contact_name_when_name_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
|
||||
contact_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
|
||||
contact_string_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
|
||||
contact_string_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
|
||||
contact_string_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
|
||||
contact_presence_offline(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
|
||||
contact_presence_uses_highest_priority(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
|
||||
contact_presence_chat_when_same_prioroty(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
|
||||
contact_presence_online_when_same_prioroty(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
|
||||
contact_presence_away_when_same_prioroty(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
|
||||
contact_presence_xa_when_same_prioroty(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
|
||||
contact_presence_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
|
||||
contact_subscribed_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
|
||||
contact_subscribed_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
|
||||
contact_not_subscribed_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
|
||||
contact_not_subscribed_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
|
||||
contact_not_available(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
|
||||
contact_not_available_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
|
||||
contact_not_available_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
|
||||
contact_not_available_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
|
||||
contact_available_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
|
||||
contact_available_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);
|
||||
}
|
||||
24
tests/unittests/xmpp/test_contact.h
Normal file
24
tests/unittests/xmpp/test_contact.h
Normal file
@@ -0,0 +1,24 @@
|
||||
void contact_in_group(void** state);
|
||||
void contact_not_in_group(void** state);
|
||||
void contact_name_when_name_exists(void** state);
|
||||
void contact_jid_when_name_not_exists(void** state);
|
||||
void contact_string_when_name_exists(void** state);
|
||||
void contact_string_when_name_not_exists(void** state);
|
||||
void contact_string_when_default_resource(void** state);
|
||||
void contact_presence_offline(void** state);
|
||||
void contact_presence_uses_highest_priority(void** state);
|
||||
void contact_presence_chat_when_same_prioroty(void** state);
|
||||
void contact_presence_online_when_same_prioroty(void** state);
|
||||
void contact_presence_away_when_same_prioroty(void** state);
|
||||
void contact_presence_xa_when_same_prioroty(void** state);
|
||||
void contact_presence_dnd(void** state);
|
||||
void contact_subscribed_when_to(void** state);
|
||||
void contact_subscribed_when_both(void** state);
|
||||
void contact_not_subscribed_when_from(void** state);
|
||||
void contact_not_subscribed_when_no_subscription_value(void** state);
|
||||
void contact_not_available(void** state);
|
||||
void contact_not_available_when_highest_priority_away(void** state);
|
||||
void contact_not_available_when_highest_priority_xa(void** state);
|
||||
void contact_not_available_when_highest_priority_dnd(void** state);
|
||||
void contact_available_when_highest_priority_online(void** state);
|
||||
void contact_available_when_highest_priority_chat(void** state);
|
||||
744
tests/unittests/xmpp/test_form.c
Normal file
744
tests/unittests/xmpp/test_form.c
Normal file
@@ -0,0 +1,744 @@
|
||||
#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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
set_value_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
|
||||
set_value_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
|
||||
add_unique_value_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
|
||||
add_unique_value_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
|
||||
add_unique_value_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
|
||||
add_value_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
|
||||
add_value_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
|
||||
add_value_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
|
||||
remove_value_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
|
||||
remove_value_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
|
||||
remove_value_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
|
||||
remove_value_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
|
||||
remove_text_multi_value_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
|
||||
remove_text_multi_value_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
|
||||
remove_text_multi_value_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
|
||||
remove_text_multi_value_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);
|
||||
}
|
||||
21
tests/unittests/xmpp/test_form.h
Normal file
21
tests/unittests/xmpp/test_form.h
Normal file
@@ -0,0 +1,21 @@
|
||||
void get_form_type_field_returns_null_no_fields(void** state);
|
||||
void get_form_type_field_returns_null_when_not_present(void** state);
|
||||
void get_form_type_field_returns_value_when_present(void** state);
|
||||
void get_field_type_returns_unknown_when_no_fields(void** state);
|
||||
void get_field_type_returns_correct_type(void** state);
|
||||
void set_value_adds_when_none(void** state);
|
||||
void set_value_updates_when_one(void** state);
|
||||
void add_unique_value_adds_when_none(void** state);
|
||||
void add_unique_value_does_nothing_when_exists(void** state);
|
||||
void add_unique_value_adds_when_doesnt_exist(void** state);
|
||||
void add_value_adds_when_none(void** state);
|
||||
void add_value_adds_when_some(void** state);
|
||||
void add_value_adds_when_exists(void** state);
|
||||
void remove_value_does_nothing_when_none(void** state);
|
||||
void remove_value_does_nothing_when_doesnt_exist(void** state);
|
||||
void remove_value_removes_when_one(void** state);
|
||||
void remove_value_removes_when_many(void** state);
|
||||
void remove_text_multi_value_does_nothing_when_none(void** state);
|
||||
void remove_text_multi_value_does_nothing_when_doesnt_exist(void** state);
|
||||
void remove_text_multi_value_removes_when_one(void** state);
|
||||
void remove_text_multi_value_removes_when_many(void** state);
|
||||
236
tests/unittests/xmpp/test_jid.c
Normal file
236
tests/unittests/xmpp/test_jid.c
Normal file
@@ -0,0 +1,236 @@
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/jid.h"
|
||||
|
||||
void
|
||||
create_jid_from_null_returns_null(void** state)
|
||||
{
|
||||
Jid* result = jid_create(NULL);
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_empty_string_returns_null(void** state)
|
||||
{
|
||||
Jid* result = jid_create("");
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser@mydomain/laptop", result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser@mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_resourcepart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("laptop", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_localpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser", result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_domainpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain/laptop", result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_resourcepart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("laptop", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_domainpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_null_localpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_null(result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_null_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_null(result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_null_resource(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_null(result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("myuser@mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_localpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("myuser", result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_domainpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_room_jid_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
|
||||
create_room_jid_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
|
||||
create_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
|
||||
create_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
|
||||
create_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
|
||||
create_full_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
|
||||
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
|
||||
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);
|
||||
}
|
||||
25
tests/unittests/xmpp/test_jid.h
Normal file
25
tests/unittests/xmpp/test_jid.h
Normal file
@@ -0,0 +1,25 @@
|
||||
void create_jid_from_null_returns_null(void** state);
|
||||
void create_jid_from_empty_string_returns_null(void** state);
|
||||
void create_jid_from_full_returns_full(void** state);
|
||||
void create_jid_from_full_returns_bare(void** state);
|
||||
void create_jid_from_full_returns_resourcepart(void** state);
|
||||
void create_jid_from_full_returns_localpart(void** state);
|
||||
void create_jid_from_full_returns_domainpart(void** state);
|
||||
void create_jid_from_full_nolocal_returns_full(void** state);
|
||||
void create_jid_from_full_nolocal_returns_bare(void** state);
|
||||
void create_jid_from_full_nolocal_returns_resourcepart(void** state);
|
||||
void create_jid_from_full_nolocal_returns_domainpart(void** state);
|
||||
void create_jid_from_full_nolocal_returns_null_localpart(void** state);
|
||||
void create_jid_from_bare_returns_null_full(void** state);
|
||||
void create_jid_from_bare_returns_null_resource(void** state);
|
||||
void create_jid_from_bare_returns_bare(void** state);
|
||||
void create_jid_from_bare_returns_localpart(void** state);
|
||||
void create_jid_from_bare_returns_domainpart(void** state);
|
||||
void create_room_jid_returns_room(void** state);
|
||||
void create_room_jid_returns_nick(void** state);
|
||||
void create_with_slash_in_resource(void** state);
|
||||
void create_with_at_in_resource(void** state);
|
||||
void create_with_at_and_slash_in_resource(void** state);
|
||||
void create_full_with_trailing_slash(void** state);
|
||||
void returns_fulljid_when_exists(void** state);
|
||||
void returns_barejid_when_fulljid_not_exists(void** state);
|
||||
87
tests/unittests/xmpp/test_muc.c
Normal file
87
tests/unittests/xmpp/test_muc.c
Normal file
@@ -0,0 +1,87 @@
|
||||
#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
|
||||
test_muc_invites_add(void** state)
|
||||
{
|
||||
char* room = "room@conf.server";
|
||||
muc_invites_add(room, NULL);
|
||||
|
||||
gboolean invite_exists = muc_invites_contain(room);
|
||||
|
||||
assert_true(invite_exists);
|
||||
}
|
||||
|
||||
void
|
||||
test_muc_remove_invite(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
|
||||
test_muc_invites_count_0(void** state)
|
||||
{
|
||||
int invite_count = muc_invites_count();
|
||||
|
||||
assert_true(invite_count == 0);
|
||||
}
|
||||
|
||||
void
|
||||
test_muc_invites_count_5(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
|
||||
test_muc_room_is_not_active(void** state)
|
||||
{
|
||||
char* room = "room@server.org";
|
||||
|
||||
gboolean room_is_active = muc_active(room);
|
||||
|
||||
assert_false(room_is_active);
|
||||
}
|
||||
|
||||
void
|
||||
test_muc_active(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);
|
||||
}
|
||||
9
tests/unittests/xmpp/test_muc.h
Normal file
9
tests/unittests/xmpp/test_muc.h
Normal file
@@ -0,0 +1,9 @@
|
||||
int muc_before_test(void** state);
|
||||
int muc_after_test(void** state);
|
||||
|
||||
void test_muc_invites_add(void** state);
|
||||
void test_muc_remove_invite(void** state);
|
||||
void test_muc_invites_count_0(void** state);
|
||||
void test_muc_invites_count_5(void** state);
|
||||
void test_muc_room_is_not_active(void** state);
|
||||
void test_muc_active(void** state);
|
||||
720
tests/unittests/xmpp/test_roster_list.c
Normal file
720
tests/unittests/xmpp/test_roster_list.c
Normal file
@@ -0,0 +1,720 @@
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/contact.h"
|
||||
#include "xmpp/roster_list.h"
|
||||
|
||||
void
|
||||
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
|
||||
contains_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
|
||||
first_element_correct(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
|
||||
contains_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
|
||||
first_and_second_elements_correct(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
|
||||
contains_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
|
||||
first_three_elements_correct(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
|
||||
add_twice_at_beginning_adds_once(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
|
||||
add_twice_in_middle_adds_once(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
|
||||
add_twice_at_end_adds_once(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
|
||||
find_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
|
||||
find_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
|
||||
find_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
|
||||
find_returns_null(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
|
||||
find_on_empty_returns_null(void** state)
|
||||
{
|
||||
roster_create();
|
||||
char* result = roster_contact_autocomplete("James", FALSE, NULL);
|
||||
assert_null(result);
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
find_twice_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
|
||||
find_five_times_finds_fifth(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
|
||||
find_twice_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
|
||||
add_contact_with_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
|
||||
add_contact_with_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
|
||||
add_contact_with_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
|
||||
add_contact_with_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
|
||||
add_contact_with_three_groups_update_adding_two(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
|
||||
add_contact_with_three_groups_update_removing_one(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
|
||||
add_contact_with_three_groups_update_removing_two(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
|
||||
add_contact_with_three_groups_update_removing_three(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
|
||||
add_contact_with_three_groups_update_two_new(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
|
||||
add_remove_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
|
||||
add_contacts_with_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
|
||||
add_contacts_with_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
|
||||
add_contacts_with_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
|
||||
remove_contact_with_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
|
||||
get_contact_display_name(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
|
||||
get_contact_display_name_is_barejid_if_name_is_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
|
||||
get_contact_display_name_is_passed_barejid_if_contact_does_not_exist(void** state)
|
||||
{
|
||||
roster_create();
|
||||
|
||||
assert_string_equal("person@server.org", roster_get_display_name("person@server.org"));
|
||||
|
||||
roster_destroy();
|
||||
}
|
||||
35
tests/unittests/xmpp/test_roster_list.h
Normal file
35
tests/unittests/xmpp/test_roster_list.h
Normal file
@@ -0,0 +1,35 @@
|
||||
void empty_list_when_none_added(void** state);
|
||||
void contains_one_element(void** state);
|
||||
void first_element_correct(void** state);
|
||||
void contains_two_elements(void** state);
|
||||
void first_and_second_elements_correct(void** state);
|
||||
void contains_three_elements(void** state);
|
||||
void first_three_elements_correct(void** state);
|
||||
void add_twice_at_beginning_adds_once(void** state);
|
||||
void add_twice_in_middle_adds_once(void** state);
|
||||
void add_twice_at_end_adds_once(void** state);
|
||||
void find_first_exists(void** state);
|
||||
void find_second_exists(void** state);
|
||||
void find_third_exists(void** state);
|
||||
void find_returns_null(void** state);
|
||||
void find_on_empty_returns_null(void** state);
|
||||
void find_twice_returns_second_when_two_match(void** state);
|
||||
void find_five_times_finds_fifth(void** state);
|
||||
void find_twice_returns_first_when_two_match_and_reset(void** state);
|
||||
void add_contact_with_no_group(void** state);
|
||||
void add_contact_with_group(void** state);
|
||||
void add_contact_with_two_groups(void** state);
|
||||
void add_contact_with_three_groups(void** state);
|
||||
void add_contact_with_three_groups_update_adding_two(void** state);
|
||||
void add_contact_with_three_groups_update_removing_one(void** state);
|
||||
void add_contact_with_three_groups_update_removing_two(void** state);
|
||||
void add_contact_with_three_groups_update_removing_three(void** state);
|
||||
void add_contact_with_three_groups_update_two_new(void** state);
|
||||
void add_remove_contact_groups(void** state);
|
||||
void add_contacts_with_different_groups(void** state);
|
||||
void add_contacts_with_same_groups(void** state);
|
||||
void add_contacts_with_overlapping_groups(void** state);
|
||||
void remove_contact_with_remaining_in_group(void** state);
|
||||
void get_contact_display_name(void** state);
|
||||
void get_contact_display_name_is_barejid_if_name_is_empty(void** state);
|
||||
void get_contact_display_name_is_passed_barejid_if_contact_does_not_exist(void** state);
|
||||
Reference in New Issue
Block a user