source: tests/check_jabber_util.c @ 673a54c

Last change on this file since 673a54c was 98de2cc, checked in by Wilmer van der Gaast <wilmer@…>, at 2008-06-21T23:51:18Z

Now preserving case in JID resources, and handling them with case sensitivity
since apparently that's how the RFC wants it. (While the rest of the JID
should be case IN-sensitive. Consistency is hard to find these days...) Also
extended the unittests a little bit. Closes #422.

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[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
9static struct im_connection *ic;
10
11static void check_buddy_add(int l)
12{
[98de2cc]13        struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud;
[3e6764a]14       
15        budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee" );
16        budw1->last_act = time( NULL ) - 100;
[98de2cc]17        budw2 = jabber_buddy_add( ic, "WILMER@gaast.net/Telepathy" );
[3e6764a]18        budw2->priority = 2;
19        budw2->last_act = time( NULL );
[98de2cc]20        budw3 = jabber_buddy_add( ic, "wilmer@GAAST.NET/bitlbee" );
[3e6764a]21        budw3->last_act = time( NULL ) - 200;
22        budw3->priority = 4;
23        /* TODO(wilmer): Shouldn't this just return budw3? */
[98de2cc]24        fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" ) != NULL );
[3e6764a]25       
26        budn = jabber_buddy_add( ic, "nekkid@lamejab.net" );
27        /* Shouldn't be allowed if there's already a bare JID. */
28        fail_if( jabber_buddy_add( ic, "nekkid@lamejab.net/Illegal" ) );
29       
[98de2cc]30        /* Case sensitivity: Case only matters after the / */
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       
[3e6764a]35        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == budw1 );
[98de2cc]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
39        fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_EXACT ) );
[98de2cc]40        fail_unless( jabber_buddy_by_jid( ic, "WILMER@gaast.net", 0 ) == budw3 );
41
42        /* Check O_FIRST and see if it's indeed the first item from the list. */
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 );
[3e6764a]45       
[98de2cc]46        /* Change the resource_select setting, now we should get a different resource. */
[3e6764a]47        set_setstr( &ic->acc->set, "resource_select", "activity" );
[98de2cc]48        fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET", 0 ) == budw2 );
[3e6764a]49       
[98de2cc]50        /* Some testing of bare JID handling (which is horrible). */
[3e6764a]51        fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", 0 ) );
[98de2cc]52        fail_if( jabber_buddy_by_jid( ic, "NEKKID@LAMEJAB.NET/Illegal", GET_BUDDY_CREAT ) );
[3e6764a]53        fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) == budn );
[98de2cc]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 );
[3e6764a]56       
[98de2cc]57        /* More case sensitivity testing, and see if remove works properly. */
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" ) );
[3e6764a]62        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 );
63       
64        fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ) );
65        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 );
66       
[98de2cc]67        /* Check if remove_bare() indeed gets rid of all. */
[3e6764a]68        fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) );
69        fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) );
70
71        fail_if( jabber_buddy_remove( ic, "nekkid@lamejab.net/Illegal" ) );
72        fail_unless( jabber_buddy_remove( ic, "nekkid@lamejab.net" ) );
73        fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) );
74}
75
76Suite *jabber_util_suite (void)
77{
78        Suite *s = suite_create("jabber/util");
79        TCase *tc_core = tcase_create("Buddy");
80        struct jabber_data *jd;
81       
82        ic = g_new0( struct im_connection, 1 );
83        ic->acc = g_new0( account_t, 1 );
84        ic->proto_data = jd = g_new0( struct jabber_data, 1 );
85        jd->buddies = g_hash_table_new( g_str_hash, g_str_equal );
86        set_add( &ic->acc->set, "resource_select", "priority", NULL, ic->acc );
87       
88        suite_add_tcase (s, tc_core);
89        tcase_add_test (tc_core, check_buddy_add);
90        return s;
91}
Note: See TracBrowser for help on using the repository browser.