Fri, 10 Jul 2009 22:42:18 +0000
Whoops, some of these were asserting valid but should have been
asserting invalid
|
15950
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
1 | #include <string.h> |
|
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
2 | |
| 15155 | 3 | #include "tests.h" |
|
15953
dfb69139ddf9
Update #includes to match changes in jabber
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15950
diff
changeset
|
4 | #include "../account.h" |
|
dfb69139ddf9
Update #includes to match changes in jabber
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15950
diff
changeset
|
5 | #include "../conversation.h" |
|
dfb69139ddf9
Update #includes to match changes in jabber
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15950
diff
changeset
|
6 | #include "../xmlnode.h" |
| 15155 | 7 | #include "../protocols/jabber/jutil.h" |
| 8 | ||
| 9 | START_TEST(test_get_resource) | |
| 10 | { | |
| 11 | assert_string_equal_free("baz", jabber_get_resource("foo@bar/baz")); | |
| 12 | assert_string_equal_free("baz", jabber_get_resource("bar/baz")); | |
| 13 | assert_string_equal_free("baz/bat", jabber_get_resource("foo@bar/baz/bat")); | |
| 14 | assert_string_equal_free("baz/bat", jabber_get_resource("bar/baz/bat")); | |
| 15 | } | |
| 16 | END_TEST | |
| 17 | ||
| 18 | START_TEST(test_get_resource_no_resource) | |
| 19 | { | |
| 20 | ||
| 21 | fail_unless(NULL == jabber_get_resource("foo@bar")); | |
| 22 | fail_unless(NULL == jabber_get_resource("bar")); | |
| 23 | } | |
| 24 | END_TEST | |
| 25 | ||
| 26 | START_TEST(test_get_bare_jid) | |
| 27 | { | |
| 28 | assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar")); | |
| 29 | assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar/baz")); | |
| 30 | assert_string_equal_free("bar", jabber_get_bare_jid("bar")); | |
| 31 | assert_string_equal_free("bar", jabber_get_bare_jid("bar/baz")); | |
| 32 | } | |
| 33 | END_TEST | |
| 34 | ||
| 35 | START_TEST(test_nodeprep_validate) | |
| 36 | { | |
|
15950
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
37 | char *longnode; |
|
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
38 | |
| 15155 | 39 | fail_unless(jabber_nodeprep_validate(NULL)); |
| 40 | fail_unless(jabber_nodeprep_validate("foo")); | |
| 41 | fail_unless(jabber_nodeprep_validate("%d")); | |
| 42 | fail_unless(jabber_nodeprep_validate("y\\z")); | |
| 43 | ||
|
15950
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15435
diff
changeset
|
44 | longnode = g_strnfill(1023, 'a'); |
| 15155 | 45 | fail_unless(jabber_nodeprep_validate(longnode)); |
| 46 | g_free(longnode); | |
| 47 | } | |
| 48 | END_TEST | |
| 49 | ||
| 50 | START_TEST(test_nodeprep_validate_illegal_chars) | |
| 51 | { | |
| 52 | fail_if(jabber_nodeprep_validate("don't")); | |
| 53 | fail_if(jabber_nodeprep_validate("m@ke")); | |
| 54 | fail_if(jabber_nodeprep_validate("\"me\"")); | |
| 55 | fail_if(jabber_nodeprep_validate("&ngry")); | |
| 56 | fail_if(jabber_nodeprep_validate("c:")); | |
| 57 | fail_if(jabber_nodeprep_validate("a/b")); | |
| 58 | fail_if(jabber_nodeprep_validate("4>2")); | |
| 59 | fail_if(jabber_nodeprep_validate("4<7")); | |
| 60 | } | |
| 61 | END_TEST | |
| 62 | ||
| 63 | START_TEST(test_nodeprep_validate_too_long) | |
| 64 | { | |
| 65 | char *longnode = g_strnfill(1024, 'a'); | |
| 66 | fail_if(jabber_nodeprep_validate(longnode)); | |
| 67 | g_free(longnode); | |
| 68 | } | |
| 69 | END_TEST | |
| 70 | ||
|
27710
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
71 | #define assert_valid_jid(str) { \ |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
72 | JabberID *jid = jabber_id_new(str); \ |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
73 | fail_if(jid == NULL, "JID '%s' is valid but jabber_id_new() rejected it", str); \ |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
74 | jabber_id_free(jid); \ |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
75 | } |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
76 | |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
77 | #define assert_invalid_jid(str) { \ |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
78 | JabberID *jid = jabber_id_new(str); \ |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
79 | fail_if(jid != NULL, "JID '%s' is invalid but jabber_id_new() allowed it", str); \ |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
80 | jabber_id_free(jid); \ |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
81 | } |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
82 | |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
83 | START_TEST(test_jabber_id_new) |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
84 | { |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
85 | assert_valid_jid("gmail.com"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
86 | assert_valid_jid("gmail.com/Test"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
87 | assert_valid_jid("gmail.com/Test@"); |
| 27712 | 88 | assert_valid_jid("gmail.com/@"); |
|
27710
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
89 | assert_valid_jid("gmail.com/Test@alkjaweflkj"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
90 | assert_valid_jid("mark.doliner@gmail.com"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
91 | assert_valid_jid("mark.doliner@gmail.com/Test12345"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
92 | assert_valid_jid("mark.doliner@gmail.com/Test@12345"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
93 | assert_valid_jid("mark.doliner@gmail.com/Te/st@12@//345"); |
|
27715
6b61fbf40032
More tests, some with an international flavor. I have no idea what that
Mark Doliner <markdoliner@pidgin.im>
parents:
27712
diff
changeset
|
94 | assert_valid_jid("わいど@conference.jabber.org"); |
|
6b61fbf40032
More tests, some with an international flavor. I have no idea what that
Mark Doliner <markdoliner@pidgin.im>
parents:
27712
diff
changeset
|
95 | assert_valid_jid("まりるーむ@conference.jabber.org"); |
|
6b61fbf40032
More tests, some with an international flavor. I have no idea what that
Mark Doliner <markdoliner@pidgin.im>
parents:
27712
diff
changeset
|
96 | assert_valid_jid("mark.doliner@gmail.com/まりるーむ"); |
|
27718
ae2f4ae35df9
Whoops, some of these were asserting valid but should have been
Mark Doliner <markdoliner@pidgin.im>
parents:
27715
diff
changeset
|
97 | assert_valid_jid("mark.doliner@gmail/stuff.org"); |
|
27710
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
98 | |
| 27712 | 99 | assert_invalid_jid("@gmail.com"); |
|
27710
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
100 | assert_invalid_jid("@@gmail.com"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
101 | assert_invalid_jid("mark.doliner@@gmail.com/Test12345"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
102 | assert_invalid_jid("mark@doliner@gmail.com/Test12345"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
103 | assert_invalid_jid("@gmail.com/Test@12345"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
104 | assert_invalid_jid("/Test@12345"); |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
105 | assert_invalid_jid("mark.doliner@"); |
|
27711
a259a8dd64cf
I thought of another invalid JID. I'm changing jabber_id_new() so that all
Mark Doliner <markdoliner@pidgin.im>
parents:
27710
diff
changeset
|
106 | assert_invalid_jid("mark.doliner/"); |
|
27718
ae2f4ae35df9
Whoops, some of these were asserting valid but should have been
Mark Doliner <markdoliner@pidgin.im>
parents:
27715
diff
changeset
|
107 | assert_invalid_jid("mark.doliner@gmail_stuff.org"); |
|
ae2f4ae35df9
Whoops, some of these were asserting valid but should have been
Mark Doliner <markdoliner@pidgin.im>
parents:
27715
diff
changeset
|
108 | assert_invalid_jid("mark.doliner@gmail[stuff.org"); |
|
ae2f4ae35df9
Whoops, some of these were asserting valid but should have been
Mark Doliner <markdoliner@pidgin.im>
parents:
27715
diff
changeset
|
109 | assert_invalid_jid("mark.doliner@gmail\\stuff.org"); |
|
ae2f4ae35df9
Whoops, some of these were asserting valid but should have been
Mark Doliner <markdoliner@pidgin.im>
parents:
27715
diff
changeset
|
110 | assert_invalid_jid("mark.doliner@わいど.org"); |
|
27710
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
111 | } |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
112 | END_TEST |
|
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
113 | |
| 15155 | 114 | Suite * |
| 115 | jabber_jutil_suite(void) | |
| 116 | { | |
| 117 | Suite *s = suite_create("Jabber Utility Functions"); | |
| 118 | ||
| 119 | TCase *tc = tcase_create("Get Resource"); | |
| 120 | tcase_add_test(tc, test_get_resource); | |
| 121 | tcase_add_test(tc, test_get_resource_no_resource); | |
| 122 | suite_add_tcase(s, tc); | |
| 123 | ||
| 124 | tc = tcase_create("Get Bare JID"); | |
| 125 | tcase_add_test(tc, test_get_bare_jid); | |
| 126 | suite_add_tcase(s, tc); | |
| 127 | ||
|
27710
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
128 | tc = tcase_create("JID validate"); |
| 15155 | 129 | tcase_add_test(tc, test_nodeprep_validate); |
| 130 | tcase_add_test(tc, test_nodeprep_validate_illegal_chars); | |
| 131 | tcase_add_test(tc, test_nodeprep_validate_too_long); | |
|
27710
e4b25e3c28a2
Add tests for jabber_id_new(). Please add to this! JIDs with accented
Mark Doliner <markdoliner@pidgin.im>
parents:
15953
diff
changeset
|
132 | tcase_add_test(tc, test_jabber_id_new); |
| 15155 | 133 | suite_add_tcase(s, tc); |
| 134 | ||
| 135 | return s; | |
| 136 | } |