diff options
author | James Booth <boothj5@gmail.com> | 2014-01-05 00:35:48 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-01-05 00:35:48 +0000 |
commit | d15751649c5bc18f61d13b9db35a385cf7077538 (patch) | |
tree | d2af83b6bcb55612d3475f9e93471bb2203312fc /tests | |
parent | c7cc27351fc1345c535c4f77ab0e724ec8db142d (diff) | |
download | profani-tty-d15751649c5bc18f61d13b9db35a385cf7077538.tar.gz |
Added tests for contact type
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_contact.c | 102 | ||||
-rw-r--r-- | tests/test_contact.h | 7 | ||||
-rw-r--r-- | tests/testsuite.c | 8 |
3 files changed, 117 insertions, 0 deletions
diff --git a/tests/test_contact.c b/tests/test_contact.c new file mode 100644 index 00000000..332d6fd2 --- /dev/null +++ b/tests/test_contact.c @@ -0,0 +1,102 @@ +#include <glib.h> +#include <stdarg.h> +#include <string.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> +#include <stdlib.h> + +#include "contact.h" + +void contact_in_group(void **state) +{ + GSList *groups = NULL; + groups = g_slist_append(groups, 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, 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); + 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); + 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); + free(str); +} diff --git a/tests/test_contact.h b/tests/test_contact.h new file mode 100644 index 00000000..f0ba043f --- /dev/null +++ b/tests/test_contact.h @@ -0,0 +1,7 @@ +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); diff --git a/tests/testsuite.c b/tests/testsuite.c index c0e98b23..71f2fdf9 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -5,6 +5,7 @@ #include "test_autocomplete.h" #include "test_common.h" +#include "test_contact.h" #include "test_cmd_connect.h" #include "test_cmd_account.h" #include "test_cmd_rooms.h" @@ -257,6 +258,13 @@ int main(int argc, char* argv[]) { unit_test(cmd_sub_shows_message_when_not_connected), unit_test(cmd_sub_shows_usage_when_no_arg), + unit_test(contact_in_group), + unit_test(contact_not_in_group), + unit_test(contact_name_when_name_exists), + unit_test(contact_jid_when_name_not_exists), + unit_test(contact_string_when_name_exists), + unit_test(contact_string_when_name_not_exists), + unit_test(contact_string_when_default_resource), }; return run_tests(tests); } |