Mercurial > pidgin
changeset 27451:962ce369fc35
Add tests for jabber_id_new(). Please add to this! JIDs with accented
characters and stuff would be great.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 10 Jul 2009 05:26:41 +0000 |
parents | 7bdad85c5fed |
children | 2131abd387f9 |
files | libpurple/tests/test_jabber_jutil.c |
diffstat | 1 files changed, 34 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/tests/test_jabber_jutil.c Fri Jul 10 05:05:51 2009 +0000 +++ b/libpurple/tests/test_jabber_jutil.c Fri Jul 10 05:26:41 2009 +0000 @@ -68,6 +68,38 @@ } END_TEST +#define assert_valid_jid(str) { \ + JabberID *jid = jabber_id_new(str); \ + fail_if(jid == NULL, "JID '%s' is valid but jabber_id_new() rejected it", str); \ + jabber_id_free(jid); \ +} + +#define assert_invalid_jid(str) { \ + JabberID *jid = jabber_id_new(str); \ + fail_if(jid != NULL, "JID '%s' is invalid but jabber_id_new() allowed it", str); \ + jabber_id_free(jid); \ +} + +START_TEST(test_jabber_id_new) +{ + assert_valid_jid("gmail.com"); + assert_valid_jid("gmail.com/Test"); + assert_valid_jid("gmail.com/Test@"); + assert_valid_jid("gmail.com/Test@alkjaweflkj"); + assert_valid_jid("mark.doliner@gmail.com"); + assert_valid_jid("mark.doliner@gmail.com/Test12345"); + assert_valid_jid("mark.doliner@gmail.com/Test@12345"); + assert_valid_jid("mark.doliner@gmail.com/Te/st@12@//345"); + + assert_invalid_jid("@@gmail.com"); + assert_invalid_jid("mark.doliner@@gmail.com/Test12345"); + assert_invalid_jid("mark@doliner@gmail.com/Test12345"); + assert_invalid_jid("@gmail.com/Test@12345"); + assert_invalid_jid("/Test@12345"); + assert_invalid_jid("mark.doliner@"); +} +END_TEST + Suite * jabber_jutil_suite(void) { @@ -82,10 +114,11 @@ tcase_add_test(tc, test_get_bare_jid); suite_add_tcase(s, tc); - tc = tcase_create("Nodeprep validate"); + tc = tcase_create("JID validate"); tcase_add_test(tc, test_nodeprep_validate); tcase_add_test(tc, test_nodeprep_validate_illegal_chars); tcase_add_test(tc, test_nodeprep_validate_too_long); + tcase_add_test(tc, test_jabber_id_new); suite_add_tcase(s, tc); return s;