1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <glib.h>
#include <wocky/wocky-resource-contact.h>
#include <wocky/wocky-utils.h>
#include "wocky-test-helper.h"
static void
test_instantiation (void)
{
WockyBareContact *bare_contact;
WockyResourceContact *resource_contact;
bare_contact = g_object_new (WOCKY_TYPE_BARE_CONTACT,
"jid", "juliet@example.net",
NULL);
resource_contact = g_object_new (WOCKY_TYPE_RESOURCE_CONTACT,
"resource", "Balcony",
"bare-contact", bare_contact,
NULL);
g_assert (WOCKY_IS_RESOURCE_CONTACT (resource_contact));
/* WockyResourceContact is a sub-class of WockyContact */
g_assert (WOCKY_IS_CONTACT (resource_contact));
g_object_unref (resource_contact);
resource_contact = wocky_resource_contact_new (bare_contact, "Balcony");
g_assert (WOCKY_IS_RESOURCE_CONTACT (resource_contact));
g_assert (WOCKY_IS_CONTACT (resource_contact));
g_object_unref (resource_contact);
g_object_unref (bare_contact);
}
static void
test_get_resource (void)
{
WockyBareContact *bare_contact;
WockyResourceContact *resource_contact;
bare_contact = g_object_new (WOCKY_TYPE_BARE_CONTACT,
"jid", "juliet@example.net",
NULL);
resource_contact = wocky_resource_contact_new (bare_contact, "Balcony");
g_assert (!wocky_strdiff (
wocky_resource_contact_get_resource (resource_contact), "Balcony"));
g_object_unref (bare_contact);
g_object_unref (resource_contact);
}
static void
test_get_bare_contact (void)
{
WockyBareContact *bare_contact;
WockyResourceContact *resource_contact;
bare_contact = g_object_new (WOCKY_TYPE_BARE_CONTACT,
"jid", "juliet@example.net",
NULL);
resource_contact = wocky_resource_contact_new (bare_contact, "Balcony");
g_assert (wocky_resource_contact_get_bare_contact (resource_contact) ==
bare_contact);
g_object_unref (bare_contact);
g_object_unref (resource_contact);
}
static void
test_equal (void)
{
WockyBareContact *a, *b;
WockyResourceContact *a_1, *a_2, *b_1;
a = wocky_bare_contact_new ("a@example.net");
a_1 = wocky_resource_contact_new (a, "Resource1");
g_assert (wocky_resource_contact_equal (a_1, a_1));
g_assert (!wocky_resource_contact_equal (a_1, NULL));
g_assert (!wocky_resource_contact_equal (NULL, a_1));
a_2 = wocky_resource_contact_new (a, "Resource2");
g_assert (!wocky_resource_contact_equal (a_1, a_2));
b = wocky_bare_contact_new ("b@example.net");
b_1 = wocky_resource_contact_new (b, "Resource1");
g_assert (!wocky_resource_contact_equal (b_1, a_1));
g_assert (!wocky_resource_contact_equal (b_1, a_2));
g_object_unref (a);
g_object_unref (b);
g_object_unref (a_1);
g_object_unref (a_2);
g_object_unref (b_1);
}
int
main (int argc, char **argv)
{
int result;
test_init (argc, argv);
g_test_add_func ("/resource-contact/instantiation", test_instantiation);
g_test_add_func ("/resource-contact/get-resource", test_get_resource);
g_test_add_func ("/resource-contact/get-bare-contact", test_get_bare_contact);
g_test_add_func ("/resource-contact/equal", test_equal);
result = g_test_run ();
test_deinit ();
return result;
}
|