[3e6764a] | 1 | #include <stdlib.h> |
---|
| 2 | #include <glib.h> |
---|
| 3 | #include <gmodule.h> |
---|
| 4 | #include <check.h> |
---|
| 5 | #include <string.h> |
---|
| 6 | #include <stdio.h> |
---|
| 7 | #include "jabber/jabber.h" |
---|
| 8 | |
---|
| 9 | static struct im_connection *ic; |
---|
| 10 | |
---|
| 11 | static void check_buddy_add(int l) |
---|
| 12 | { |
---|
[98de2cc] | 13 | struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud; |
---|
[5ebff60] | 14 | |
---|
| 15 | budw1 = jabber_buddy_add(ic, "wilmer@gaast.net/BitlBee"); |
---|
| 16 | budw1->last_msg = time(NULL) - 100; |
---|
| 17 | budw2 = jabber_buddy_add(ic, "WILMER@gaast.net/Telepathy"); |
---|
[3e6764a] | 18 | budw2->priority = 2; |
---|
[5ebff60] | 19 | budw2->last_msg = time(NULL); |
---|
| 20 | budw3 = jabber_buddy_add(ic, "wilmer@GAAST.NET/bitlbee"); |
---|
| 21 | budw3->last_msg = time(NULL) - 200; |
---|
[3e6764a] | 22 | budw3->priority = 4; |
---|
| 23 | /* TODO(wilmer): Shouldn't this just return budw3? */ |
---|
[5ebff60] | 24 | fail_if(jabber_buddy_add(ic, "wilmer@gaast.net/Telepathy") != NULL); |
---|
| 25 | |
---|
| 26 | budn = jabber_buddy_add(ic, "nekkid@lamejab.net"); |
---|
[3e6764a] | 27 | /* Shouldn't be allowed if there's already a bare JID. */ |
---|
[5ebff60] | 28 | fail_if(jabber_buddy_add(ic, "nekkid@lamejab.net/Illegal")); |
---|
| 29 | |
---|
[98de2cc] | 30 | /* Case sensitivity: Case only matters after the / */ |
---|
[5ebff60] | 31 | fail_if(jabber_buddy_by_jid(ic, "wilmer@gaast.net/BitlBee", 0) == |
---|
| 32 | jabber_buddy_by_jid(ic, "wilmer@gaast.net/bitlbee", 0)); |
---|
| 33 | fail_if(jabber_buddy_by_jid(ic, "wilmer@gaast.net/telepathy", 0)); |
---|
| 34 | |
---|
| 35 | fail_unless(jabber_buddy_by_jid(ic, "wilmer@gaast.net/BitlBee", 0) == budw1); |
---|
| 36 | fail_unless(jabber_buddy_by_jid(ic, "WILMER@GAAST.NET/BitlBee", GET_BUDDY_EXACT) == budw1); |
---|
| 37 | fail_unless(jabber_buddy_by_jid(ic, "wilmer@GAAST.NET/BitlBee", GET_BUDDY_CREAT) == budw1); |
---|
[3e6764a] | 38 | |
---|
[671b1ef] | 39 | fail_unless(jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_EXACT) != NULL); |
---|
[5ebff60] | 40 | fail_unless(jabber_buddy_by_jid(ic, "WILMER@gaast.net", 0) == budw3); |
---|
[98de2cc] | 41 | |
---|
| 42 | /* Check O_FIRST and see if it's indeed the first item from the list. */ |
---|
[5ebff60] | 43 | fail_unless((bud = jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_FIRST)) == budw1); |
---|
| 44 | fail_unless(bud->next == budw2 && bud->next->next == budw3 && bud->next->next->next == NULL); |
---|
| 45 | |
---|
[98de2cc] | 46 | /* Change the resource_select setting, now we should get a different resource. */ |
---|
[5ebff60] | 47 | set_setstr(&ic->acc->set, "resource_select", "activity"); |
---|
| 48 | fail_unless(jabber_buddy_by_jid(ic, "wilmer@GAAST.NET", 0) == budw2); |
---|
| 49 | |
---|
[98de2cc] | 50 | /* Some testing of bare JID handling (which is horrible). */ |
---|
[5ebff60] | 51 | fail_if(jabber_buddy_by_jid(ic, "nekkid@lamejab.net/Illegal", 0)); |
---|
| 52 | fail_if(jabber_buddy_by_jid(ic, "NEKKID@LAMEJAB.NET/Illegal", GET_BUDDY_CREAT)); |
---|
| 53 | fail_unless(jabber_buddy_by_jid(ic, "nekkid@lamejab.net", 0) == budn); |
---|
| 54 | fail_unless(jabber_buddy_by_jid(ic, "NEKKID@lamejab.net", GET_BUDDY_EXACT) == budn); |
---|
| 55 | fail_unless(jabber_buddy_by_jid(ic, "nekkid@LAMEJAB.NET", GET_BUDDY_CREAT) == budn); |
---|
| 56 | |
---|
[98de2cc] | 57 | /* More case sensitivity testing, and see if remove works properly. */ |
---|
[5ebff60] | 58 | fail_if(jabber_buddy_remove(ic, "wilmer@gaast.net/telepathy")); |
---|
| 59 | fail_if(jabber_buddy_by_jid(ic, "wilmer@GAAST.NET/telepathy", GET_BUDDY_CREAT) == budw2); |
---|
| 60 | fail_unless(jabber_buddy_remove(ic, "wilmer@gaast.net/Telepathy")); |
---|
| 61 | fail_unless(jabber_buddy_remove(ic, "wilmer@gaast.net/telepathy")); |
---|
| 62 | |
---|
[00a0bc5] | 63 | /* Test activity_timeout and GET_BUDDY_BARE_OK. */ |
---|
[5ebff60] | 64 | fail_unless(jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK) == budw1); |
---|
[00a0bc5] | 65 | budw1->last_msg -= 50; |
---|
[5ebff60] | 66 | fail_unless((bud = jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK)) != NULL); |
---|
| 67 | fail_unless(strcmp(bud->full_jid, "wilmer@gaast.net") == 0); |
---|
| 68 | |
---|
| 69 | fail_if(jabber_buddy_remove(ic, "wilmer@gaast.net")); |
---|
| 70 | fail_unless(jabber_buddy_by_jid(ic, "wilmer@gaast.net", 0) == budw1); |
---|
| 71 | |
---|
| 72 | fail_if(jabber_buddy_remove(ic, "wilmer@gaast.net")); |
---|
| 73 | fail_unless(jabber_buddy_remove(ic, "wilmer@gaast.net/bitlbee")); |
---|
| 74 | fail_unless(jabber_buddy_remove(ic, "wilmer@gaast.net/BitlBee")); |
---|
| 75 | fail_if(jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK)); |
---|
| 76 | |
---|
[98de2cc] | 77 | /* Check if remove_bare() indeed gets rid of all. */ |
---|
[00a0bc5] | 78 | /* disable this one for now. |
---|
[3e6764a] | 79 | fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) ); |
---|
| 80 | fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) ); |
---|
[00a0bc5] | 81 | */ |
---|
[3e6764a] | 82 | |
---|
[5ebff60] | 83 | fail_if(jabber_buddy_remove(ic, "nekkid@lamejab.net/Illegal")); |
---|
| 84 | fail_unless(jabber_buddy_remove(ic, "nekkid@lamejab.net")); |
---|
[671b1ef] | 85 | fail_if(jabber_buddy_by_jid(ic, "nekkid@lamejab.net", 0) != NULL); |
---|
[5ebff60] | 86 | |
---|
[842cd8d] | 87 | /* Fixing a bug in this branch that caused information to get lost when |
---|
| 88 | removing the first full JID from a list. */ |
---|
[5ebff60] | 89 | jabber_buddy_add(ic, "bugtest@google.com/A"); |
---|
| 90 | jabber_buddy_add(ic, "bugtest@google.com/B"); |
---|
| 91 | jabber_buddy_add(ic, "bugtest@google.com/C"); |
---|
| 92 | fail_unless(jabber_buddy_remove(ic, "bugtest@google.com/A")); |
---|
| 93 | fail_unless(jabber_buddy_remove(ic, "bugtest@google.com/B")); |
---|
| 94 | fail_unless(jabber_buddy_remove(ic, "bugtest@google.com/C")); |
---|
[3e6764a] | 95 | } |
---|
| 96 | |
---|
[757515a] | 97 | static void check_compareJID(int l) |
---|
| 98 | { |
---|
[5ebff60] | 99 | fail_unless(jabber_compare_jid("bugtest@google.com/B", "bugtest@google.com/A")); |
---|
| 100 | fail_if(jabber_compare_jid("bugtest1@google.com/B", "bugtest@google.com/A")); |
---|
| 101 | fail_if(jabber_compare_jid("bugtest@google.com/B", "bugtest1@google.com/A")); |
---|
| 102 | fail_if(jabber_compare_jid("bugtest1@google.com/B", "bugtest2@google.com/A")); |
---|
| 103 | fail_unless(jabber_compare_jid("bugtest@google.com/A", "bugtest@google.com/A")); |
---|
| 104 | fail_if(jabber_compare_jid("", "bugtest@google.com/A")); |
---|
[2dc394c] | 105 | fail_if(jabber_compare_jid(NULL, "")); |
---|
| 106 | fail_if(jabber_compare_jid("", NULL)); |
---|
[757515a] | 107 | } |
---|
| 108 | |
---|
[9c8dbc7] | 109 | static void check_hipchat_slug(int l) |
---|
| 110 | { |
---|
| 111 | int i; |
---|
| 112 | |
---|
| 113 | const char *tests[] = { |
---|
| 114 | "test !\"#$%&\'()*+,-./0123456789:;<=>?@ABC", "test_!#$%\()*+,-.0123456789;=?abc", |
---|
| 115 | "test XYZ[\\]^_`abc", "test_xyz[\\]^_`abc", |
---|
| 116 | "test {|}~¡¢£¤¥¦§¨©ª«¬\xad®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ", "test_{|}~¡¢£¤¥¦§¨©ª«¬\xad®¯°±²³´µ¶·¸¹º»¼½¾¿àáâãäåæ", |
---|
| 117 | "test IJ ij I ı I ı", "test_ij_ij_i_ı_i_ı", |
---|
| 118 | NULL, |
---|
| 119 | }; |
---|
| 120 | |
---|
| 121 | for (i = 0; tests[i]; i += 2) { |
---|
| 122 | char *new = hipchat_make_channel_slug(tests[i]); |
---|
| 123 | fail_unless(!strcmp(tests[i + 1], new)); |
---|
| 124 | g_free(new); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
[5ebff60] | 128 | Suite *jabber_util_suite(void) |
---|
[3e6764a] | 129 | { |
---|
| 130 | Suite *s = suite_create("jabber/util"); |
---|
| 131 | TCase *tc_core = tcase_create("Buddy"); |
---|
| 132 | struct jabber_data *jd; |
---|
[5ebff60] | 133 | |
---|
| 134 | ic = g_new0(struct im_connection, 1); |
---|
| 135 | ic->acc = g_new0(account_t, 1); |
---|
| 136 | ic->proto_data = jd = g_new0(struct jabber_data, 1); |
---|
| 137 | jd->buddies = g_hash_table_new(g_str_hash, g_str_equal); |
---|
| 138 | set_add(&ic->acc->set, "resource_select", "priority", NULL, ic->acc); |
---|
| 139 | set_add(&ic->acc->set, "activity_timeout", "120", NULL, ic->acc); |
---|
| 140 | |
---|
| 141 | suite_add_tcase(s, tc_core); |
---|
| 142 | tcase_add_test(tc_core, check_buddy_add); |
---|
| 143 | tcase_add_test(tc_core, check_compareJID); |
---|
[9c8dbc7] | 144 | tcase_add_test(tc_core, check_hipchat_slug); |
---|
[3e6764a] | 145 | return s; |
---|
| 146 | } |
---|