source: tests/check_jabber_util.c @ 3e6764a

Last change on this file since 3e6764a was 3e6764a, checked in by Wilmer van der Gaast <wilmer@…>, at 2008-06-21T23:34:11Z

Added jabber_util unittests (buddy_add/_by_jid only ATM).

  • Property mode set to 100644
File size: 3.0 KB
Line 
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{
13        struct jabber_buddy *budw1, *budw2, *budw3, *budw4, *budn;
14        int i;
15       
16        budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee" );
17        budw1->last_act = time( NULL ) - 100;
18        budw2 = jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" );
19        budw2->priority = 2;
20        budw2->last_act = time( NULL );
21        budw3 = jabber_buddy_add( ic, "wilmer@gaast.net/Druif" );
22        budw3->last_act = time( NULL ) - 200;
23        budw3->priority = 4;
24        /* TODO(wilmer): Shouldn't this just return budw3? */
25        fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/druif" ) != NULL );
26       
27        budn = jabber_buddy_add( ic, "nekkid@lamejab.net" );
28        /* Shouldn't be allowed if there's already a bare JID. */
29        fail_if( jabber_buddy_add( ic, "nekkid@lamejab.net/Illegal" ) );
30       
31        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == budw1 );
32        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", GET_BUDDY_EXACT ) == budw1 );
33        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", GET_BUDDY_CREAT ) == budw1 );
34
35        fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_EXACT ) );
36        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) == budw1 );
37        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw3 );
38       
39        set_setstr( &ic->acc->set, "resource_select", "activity" );
40        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw2 );
41       
42        fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", 0 ) );
43        fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", GET_BUDDY_CREAT ) );
44        fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) == budn );
45        fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", GET_BUDDY_EXACT ) == budn );
46        fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", GET_BUDDY_CREAT ) == budn );
47       
48        jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" );
49        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 );
50       
51        fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ) );
52        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 );
53       
54        fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) );
55        fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) );
56
57        fail_if( jabber_buddy_remove( ic, "nekkid@lamejab.net/Illegal" ) );
58        fail_unless( jabber_buddy_remove( ic, "nekkid@lamejab.net" ) );
59        fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) );
60}
61
62Suite *jabber_util_suite (void)
63{
64        Suite *s = suite_create("jabber/util");
65        TCase *tc_core = tcase_create("Buddy");
66        struct jabber_data *jd;
67       
68        ic = g_new0( struct im_connection, 1 );
69        ic->acc = g_new0( account_t, 1 );
70        ic->proto_data = jd = g_new0( struct jabber_data, 1 );
71        jd->buddies = g_hash_table_new( g_str_hash, g_str_equal );
72        set_add( &ic->acc->set, "resource_select", "priority", NULL, ic->acc );
73       
74        suite_add_tcase (s, tc_core);
75        tcase_add_test (tc_core, check_buddy_add);
76        return s;
77}
Note: See TracBrowser for help on using the repository browser.