belle_sip_headers_tester.c 35.1 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2010  Belledonne Communications SARL

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "belle-sip/belle-sip.h"
jehan's avatar
jehan committed
21
#include "belle_sip_internal.h"
Ghislain MARY's avatar
Ghislain MARY committed
22
#include "belle_sip_tester.h"
jehan's avatar
jehan committed
23 24 25 26
#include <stdio.h>
#include "CUnit/Basic.h"


Ghislain MARY's avatar
Ghislain MARY committed
27
static void test_simple_contact_header(void) {
28
	belle_sip_header_contact_t* L_tmp;
29
	belle_sip_uri_t* L_uri;
jehan's avatar
jehan committed
30
	belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("Contact:sip:titi.com");
jehan's avatar
jehan committed
31 32
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_contact));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
33 34 35
	L_tmp = belle_sip_header_contact_parse(l_raw_header);
	L_contact = BELLE_SIP_HEADER_CONTACT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
36 37
	belle_sip_free(l_raw_header);

38
	L_uri = belle_sip_header_address_get_uri((belle_sip_header_address_t*)L_contact);
jehan's avatar
jehan committed
39 40 41 42

	CU_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
	CU_ASSERT_PTR_NULL(belle_sip_uri_get_transport_param(L_uri));
jehan's avatar
jehan committed
43
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
jehan's avatar
jehan committed
44 45
}

Ghislain MARY's avatar
Ghislain MARY committed
46
static void test_complex_contact_header(void) {
47
	belle_sip_header_contact_t* L_contact;
48
	belle_sip_uri_t* L_uri;
49
	belle_sip_header_contact_t* L_tmp = belle_sip_header_contact_parse("Contact: \"jremis\" <sip:sip.linphone.org>;expires=3600;q=0.7, sip:titi.com");
50 51 52 53
	belle_sip_header_t* l_next;
	belle_sip_header_contact_t* L_next_contact;
	char* l_raw_header;
	float l_qvalue;
jehan's avatar
jehan committed
54

55 56
	L_contact = BELLE_SIP_HEADER_CONTACT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
57

58
	L_uri = belle_sip_header_address_get_uri((belle_sip_header_address_t*)L_contact);
jehan's avatar
jehan committed
59 60

	CU_ASSERT_PTR_NOT_NULL(L_uri);
jehan's avatar
jehan committed
61
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.linphone.org");
jehan's avatar
jehan committed
62 63 64 65

	CU_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname((belle_sip_header_address_t*)L_contact), "jremis");

	CU_ASSERT_EQUAL(belle_sip_header_contact_get_expires(L_contact),3600);
66
	l_qvalue = belle_sip_header_contact_get_qvalue(L_contact);
67
	CU_ASSERT_EQUAL(l_qvalue,0.7f);
jehan's avatar
jehan committed
68

69 70
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_contact));
	L_next_contact = BELLE_SIP_HEADER_CONTACT(l_next);
jehan's avatar
jehan committed
71 72 73
	CU_ASSERT_PTR_NOT_NULL(L_next_contact);
	CU_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_contact)));

jehan's avatar
jehan committed
74
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
jehan's avatar
jehan committed
75 76

	L_contact = belle_sip_header_contact_parse("Contact: toto <sip:titi.com>;expires=3600; q=0.7");
77
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_contact));
jehan's avatar
jehan committed
78 79 80
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
	L_contact = belle_sip_header_contact_parse(l_raw_header);
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
81 82

	CU_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname((belle_sip_header_address_t*)L_contact), "toto");
jehan's avatar
jehan committed
83
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
jehan's avatar
jehan committed
84

jehan's avatar
jehan committed
85 86
}

Ghislain MARY's avatar
Ghislain MARY committed
87
static void test_from_header(void) {
88
	belle_sip_header_from_t* L_tmp;
89
	belle_sip_uri_t* L_uri;
jehan's avatar
jehan committed
90
	belle_sip_header_from_t* L_from = belle_sip_header_from_parse("From:<sip:titi.com;transport=tcp>;tag=dlfjklcn6545614XX");
jehan's avatar
jehan committed
91 92
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_from));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
93 94 95
	L_tmp = belle_sip_header_from_parse(l_raw_header);
	L_from = BELLE_SIP_HEADER_FROM(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
96 97
	belle_sip_free(l_raw_header);

98
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
jehan's avatar
jehan committed
99 100 101 102 103

	CU_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
jehan's avatar
jehan committed
104 105

	/*test factory*/
jehan's avatar
jehan committed
106
	L_from = belle_sip_header_from_create2("super <sip:titi.com>","12345-abc");
jehan's avatar
jehan committed
107 108 109 110 111 112
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_from);
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_uri);
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"12345-abc");
	belle_sip_object_unref(L_from);
jehan's avatar
jehan committed
113 114
}

Ghislain MARY's avatar
Ghislain MARY committed
115
static void test_from_header_with_paramless_address_spec(void) {
jehan's avatar
jehan committed
116 117 118 119 120
	belle_sip_header_from_t* L_from = belle_sip_header_from_parse("From: sip:bob@titi.com;tag=dlfjklcn6545614XX");
	CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_from_get_tag(L_from));
	CU_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
	belle_sip_object_unref(L_from);
}
Ghislain MARY's avatar
Ghislain MARY committed
121 122

static void test_to_header_with_paramless_address_spec(void) {
jehan's avatar
jehan committed
123 124 125 126 127
	belle_sip_header_to_t* L_to = belle_sip_header_to_parse("To: sip:bob@titi.com;tag=dlfjklcn6545614XX");
	CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_to_get_tag(L_to));
	CU_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
	belle_sip_object_unref(L_to);
}
Ghislain MARY's avatar
Ghislain MARY committed
128 129

static void test_contact_header_with_paramless_address_spec(void) {
jehan's avatar
jehan committed
130 131 132 133 134
	belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("Contact: sip:bob@titi.com;expires=60");
	CU_ASSERT_EQUAL(belle_sip_header_contact_get_expires(L_contact),60);
	belle_sip_object_unref(L_contact);
}

Ghislain MARY's avatar
Ghislain MARY committed
135
static void test_to_header(void) {
136
	belle_sip_uri_t* L_uri;
jehan's avatar
jehan committed
137
	belle_sip_header_to_t* L_to = belle_sip_header_to_parse("To : < sip:titi.com;transport=tcp> ; tag = dlfjklcn6545614XX");
jehan's avatar
jehan committed
138 139 140 141 142
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_to));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));
	L_to = belle_sip_header_to_parse(l_raw_header);
	belle_sip_free(l_raw_header);

143
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
jehan's avatar
jehan committed
144 145 146 147 148

	CU_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));
jehan's avatar
jehan committed
149
	/*test factory*/
jehan's avatar
jehan committed
150
	L_to = belle_sip_header_to_create2("\"super man\" <sip:titi.com>","12345-abc");
jehan's avatar
jehan committed
151 152 153 154 155 156 157
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_to);
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_uri);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(L_to)), "super man");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"12345-abc");
	belle_sip_object_unref(L_to);

jehan's avatar
jehan committed
158
}
Ghislain MARY's avatar
Ghislain MARY committed
159 160

static void test_via_header(void) {
161
	belle_sip_header_via_t* L_tmp;
162 163
	belle_sip_header_t* l_next;
	belle_sip_header_via_t* L_next_via;
jehan's avatar
jehan committed
164
	belle_sip_header_via_t* L_via = belle_sip_header_via_parse("Via: SIP/2.0/UDP [::1]:5062;rport;received=192.169.0.4;branch=z9hG4bK368560724");
jehan's avatar
jehan committed
165 166
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_via));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
167 168 169
	L_tmp = belle_sip_header_via_parse(l_raw_header);
	L_via = BELLE_SIP_HEADER_VIA(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
170 171
	belle_sip_free(l_raw_header);

172 173
	CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_protocol(L_via), "SIP/2.0");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_transport(L_via), "UDP");
jehan's avatar
jehan committed
174
	CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_host(L_via), "::1");
175 176
	CU_ASSERT_EQUAL(belle_sip_header_via_get_port(L_via),5062);

177
	CU_ASSERT_TRUE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_via),"rport"));
178 179 180
	CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_received(L_via),"192.169.0.4");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_branch(L_via),"z9hG4bK368560724");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
jehan's avatar
jehan committed
181 182 183

	L_via = belle_sip_header_via_parse("Via: SIP/2.0/UDP 192.168.0.19:5062;rport;received=192.169.0.4;branch=z9hG4bK368560724, SIP/2.0/UDP 192.168.0.19:5062");

184 185
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_via));
	L_next_via = BELLE_SIP_HEADER_VIA(l_next);
jehan's avatar
jehan committed
186 187 188 189
	CU_ASSERT_PTR_NOT_NULL(L_next_via);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_host(L_next_via),"192.168.0.19");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));

190
}
Ghislain MARY's avatar
Ghislain MARY committed
191 192

static void test_call_id_header(void) {
193
	belle_sip_header_call_id_t* L_tmp;
jehan's avatar
jehan committed
194
	belle_sip_header_call_id_t* L_call_id = belle_sip_header_call_id_parse("Call-ID: 1665237789@titi.com");
jehan's avatar
jehan committed
195 196
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_call_id));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_call_id));
197 198 199
	L_tmp= belle_sip_header_call_id_parse(l_raw_header);
	L_call_id = BELLE_SIP_HEADER_CALL_ID(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
200 201
	belle_sip_free(l_raw_header);

jehan's avatar
jehan committed
202 203
	CU_ASSERT_STRING_EQUAL(belle_sip_header_call_id_get_call_id(L_call_id), "1665237789@titi.com");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_call_id));
204
}
Ghislain MARY's avatar
Ghislain MARY committed
205 206

static void test_cseq_header(void) {
207
	belle_sip_header_cseq_t* L_tmp;
208
	belle_sip_header_cseq_t* L_cseq = belle_sip_header_cseq_parse("CSeq: 21 INVITE");
jehan's avatar
jehan committed
209 210
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_cseq));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_cseq));
211 212 213
	L_tmp = belle_sip_header_cseq_parse(l_raw_header);
	L_cseq = BELLE_SIP_HEADER_CSEQ(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
214 215
	belle_sip_free(l_raw_header);

216 217 218
	CU_ASSERT_EQUAL(belle_sip_header_cseq_get_seq_number(L_cseq),21);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_cseq_get_method(L_cseq),"INVITE");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_cseq));
jehan's avatar
jehan committed
219 220 221 222 223 224

	/*test factory*/
	L_cseq = belle_sip_header_cseq_create(1,"INFO");
	CU_ASSERT_EQUAL(belle_sip_header_cseq_get_seq_number(L_cseq),1);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_cseq_get_method(L_cseq),"INFO");
	belle_sip_object_unref(L_cseq);
225
}
Ghislain MARY's avatar
Ghislain MARY committed
226 227

static void test_content_type_header(void) {
228
	belle_sip_header_content_type_t* L_tmp;
229
	belle_sip_header_content_type_t* L_content_type = belle_sip_header_content_type_parse("Content-Type: text/html; charset=ISO-8859-4");
jehan's avatar
jehan committed
230 231
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_type));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
232 233 234
	L_tmp = belle_sip_header_content_type_parse(l_raw_header);
	L_content_type = BELLE_SIP_HEADER_CONTENT_TYPE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
235 236
	belle_sip_free(l_raw_header);

237 238 239 240
	CU_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_type(L_content_type),"text");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_subtype(L_content_type),"html");
	CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_content_type),"charset"),"ISO-8859-4");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
jehan's avatar
jehan committed
241 242

	L_content_type = belle_sip_header_content_type_parse("Content-Type: application/sdp");
jehan's avatar
jehan committed
243 244 245 246
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_type));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
	L_content_type = belle_sip_header_content_type_parse(l_raw_header);
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
247 248 249 250 251
	CU_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_type(L_content_type),"application");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_subtype(L_content_type),"sdp");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));

	L_content_type = belle_sip_header_content_type_parse("Content-Type: application/pkcs7-mime; smime-type=enveloped-data; \r\n name=smime.p7m");
jehan's avatar
jehan committed
252 253 254 255
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_type));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
	L_content_type = belle_sip_header_content_type_parse(l_raw_header);
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
256 257
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));

258
}
Ghislain MARY's avatar
Ghislain MARY committed
259 260

static void test_record_route_header(void) {
261 262 263
	belle_sip_uri_t* L_uri;
	belle_sip_header_t* l_next;
	belle_sip_header_record_route_t* L_next_route;
jehan's avatar
jehan committed
264
	belle_sip_header_record_route_t* L_record_route = belle_sip_header_record_route_parse("Record-Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4");
jehan's avatar
jehan committed
265 266 267 268
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_record_route));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
	L_record_route = belle_sip_header_record_route_parse(l_raw_header);
	belle_sip_free(l_raw_header);
269
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_record_route));
jehan's avatar
jehan committed
270 271 272 273
	CU_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "212.27.52.5");
	CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_record_route),"charset"),"ISO-8859-4");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
jehan's avatar
jehan committed
274 275

	L_record_route = belle_sip_header_record_route_parse("Record-Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:212.27.52.5:5060;transport=udp;lr>");
276 277
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_record_route));
	L_next_route = BELLE_SIP_HEADER_RECORD_ROUTE(l_next);
jehan's avatar
jehan committed
278 279 280
	CU_ASSERT_PTR_NOT_NULL(L_next_route);
	CU_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_route)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
jehan's avatar
jehan committed
281
}
Ghislain MARY's avatar
Ghislain MARY committed
282 283

static void test_route_header(void) {
284 285 286 287
	belle_sip_header_route_t* L_route;
	belle_sip_uri_t* L_uri;
	belle_sip_header_t* l_next;
	belle_sip_header_route_t* L_next_route;
jehan's avatar
jehan committed
288
	belle_sip_header_address_t* address = belle_sip_header_address_parse("<sip:212.27.52.5:5060;transport=udp;lr>");
289
	char* l_raw_header;
jehan's avatar
jehan committed
290
	CU_ASSERT_PTR_NOT_NULL_FATAL(address);
291
	L_route = belle_sip_header_route_create(address);
jehan's avatar
jehan committed
292
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_route);
293
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
294 295 296
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
	L_route = belle_sip_header_route_parse(l_raw_header);
	belle_sip_free(l_raw_header);
297
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_route));
jehan's avatar
jehan committed
298 299
	CU_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060);
jehan's avatar
jehan committed
300

jehan's avatar
jehan committed
301
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
302 303

	L_route = belle_sip_header_route_parse("Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:titi.com>");
304 305
	l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_route));
	L_next_route = BELLE_SIP_HEADER_ROUTE(l_next);
jehan's avatar
jehan committed
306 307 308
	CU_ASSERT_PTR_NOT_NULL(L_next_route);
	CU_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_route)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
309
}
Ghislain MARY's avatar
Ghislain MARY committed
310 311

static void test_service_route_header(void) {
jehan's avatar
jehan committed
312
	belle_sip_header_service_route_t* L_service_route = belle_sip_header_service_route_parse("Service-Route: <sip:orig@scscf.ims.linphone.com:6060;lr>");
313 314
	belle_sip_uri_t* L_uri;
	char* l_raw_header;
jehan's avatar
jehan committed
315
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_service_route);
316
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_service_route));
jehan's avatar
jehan committed
317 318 319
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_service_route));
	L_service_route = belle_sip_header_service_route_parse(l_raw_header);
	belle_sip_free(l_raw_header);
320
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_service_route));
jehan's avatar
jehan committed
321 322 323 324
	CU_ASSERT_PTR_NOT_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 6060);
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_service_route));
}
Ghislain MARY's avatar
Ghislain MARY committed
325 326

static void test_content_length_header(void) {
327
	belle_sip_header_content_length_t* L_tmp;
jehan's avatar
jehan committed
328
	belle_sip_header_content_length_t* L_content_length = belle_sip_header_content_length_parse("Content-Length: 3495");
jehan's avatar
jehan committed
329 330
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_length));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_length));
331 332 333
	L_tmp = belle_sip_header_content_length_parse(l_raw_header);
	L_content_length = BELLE_SIP_HEADER_CONTENT_LENGTH(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
334
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
335 336 337
	CU_ASSERT_EQUAL(belle_sip_header_content_length_get_content_length(L_content_length), 3495);
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_length));
}
Ghislain MARY's avatar
Ghislain MARY committed
338 339

static void test_header_extension(void) {
340
	belle_sip_header_extension_t* L_tmp;
341
	belle_sip_header_extension_t* L_extension = belle_sip_header_extension_parse("toto: titi");
jehan's avatar
jehan committed
342 343
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_extension));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_extension));
344 345 346
	L_tmp = belle_sip_header_extension_parse(l_raw_header);
	L_extension = BELLE_SIP_HEADER_EXTENSION(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
347 348
	belle_sip_free(l_raw_header);

349 350 351
	CU_ASSERT_STRING_EQUAL(belle_sip_header_extension_get_value(L_extension), "titi");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_extension));
}
Ghislain MARY's avatar
Ghislain MARY committed
352 353

static void test_authorization_header(void) {
jehan's avatar
jehan committed
354
	const char* l_header = "Authorization: Digest username=\"0033482532176\", "\
355
			"realm=\"sip.ovh.net\", nonce=\"1bcdcb194b30df5f43973d4c69bdf54f\", uri=\"sip:sip.ovh.net\", response=\"eb36c8d5c8642c1c5f44ec3404613c81\","\
356 357
			"algorithm=MD5, opaque=\"1bc7f9097684320\","
			"\r\n qop=auth, nc=00000001,cnonce=\"0a4f113b\", blabla=\"toto\"";
358
	belle_sip_header_authorization_t* L_tmp;
jehan's avatar
jehan committed
359 360 361
	belle_sip_header_authorization_t* L_authorization = belle_sip_header_authorization_parse(l_header);
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_authorization));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
362 363 364
	L_tmp = belle_sip_header_authorization_parse(l_raw_header);
	L_authorization = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
365 366
	belle_sip_free(l_raw_header);

jehan's avatar
jehan committed
367
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_authorization);
jehan's avatar
jehan committed
368
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_scheme(L_authorization), "Digest");
369
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_username(L_authorization), "0033482532176");
jehan's avatar
jehan committed
370 371 372 373
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_realm(L_authorization), "sip.ovh.net");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_nonce(L_authorization), "1bcdcb194b30df5f43973d4c69bdf54f");
	CU_ASSERT_PTR_NOT_NULL(belle_sip_header_authorization_get_uri(L_authorization));
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(L_authorization), "eb36c8d5c8642c1c5f44ec3404613c81");
374 375 376
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_algorithm(L_authorization), "MD5");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_opaque(L_authorization), "1bc7f9097684320");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_qop(L_authorization), "auth");
jehan's avatar
jehan committed
377

378 379 380
	CU_ASSERT_EQUAL(belle_sip_header_authorization_get_nonce_count(L_authorization), 1);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_cnonce(L_authorization), "0a4f113b");
	CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_authorization), "blabla"),"\"toto\"");
381 382
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
}
Ghislain MARY's avatar
Ghislain MARY committed
383 384

static void test_proxy_authorization_header(void) {
jehan's avatar
jehan committed
385
	const char* l_header = "Proxy-Authorization: Digest username=\"Alice\""
386 387
			", realm=\"atlanta.com\", nonce=\"c60f3082ee1212b402a21831ae\""
			", response=\"245f23415f11432b3434341c022\"";
jehan's avatar
jehan committed
388 389 390 391 392
	belle_sip_header_proxy_authorization_t* L_authorization = belle_sip_header_proxy_authorization_parse(l_header);
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_authorization));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
	L_authorization = belle_sip_header_proxy_authorization_parse(l_raw_header);
	belle_sip_free(l_raw_header);
393 394 395 396
	CU_ASSERT_PTR_NOT_NULL(L_authorization);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_username(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "Alice");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_realm(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "atlanta.com");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_nonce(BELLE_SIP_HEADER_AUTHORIZATION(L_authorization)), "c60f3082ee1212b402a21831ae");
jehan's avatar
jehan committed
397 398 399
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));

}
Ghislain MARY's avatar
Ghislain MARY committed
400

jehan's avatar
jehan committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
static void check_header_authenticate(belle_sip_header_www_authenticate_t* authenticate) {
	belle_sip_list_t* qop;
	CU_ASSERT_PTR_NOT_NULL(authenticate);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_realm(authenticate), "atlanta.com");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_domain(authenticate), "sip:boxesbybob.com");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_nonce(authenticate), "c60f3082ee1212b402a21831ae");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_algorithm(authenticate), "MD5");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_opaque(authenticate), "1bc7f9097684320");

	CU_ASSERT_PTR_NOT_NULL_FATAL(qop=belle_sip_header_www_authenticate_get_qop(authenticate));
	CU_ASSERT_STRING_EQUAL((const char*)qop->data, "auth");
	CU_ASSERT_PTR_NOT_NULL_FATAL(qop=qop->next);
	CU_ASSERT_STRING_EQUAL((const char*)qop->data, "auth-int");

	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_qop(authenticate)->data, "auth");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_scheme(authenticate), "Digest");
	CU_ASSERT_EQUAL(belle_sip_header_www_authenticate_is_stale(authenticate),1);
	belle_sip_object_unref(BELLE_SIP_OBJECT(authenticate));
}
Ghislain MARY's avatar
Ghislain MARY committed
420 421

static void test_www_authenticate_header(void) {
jehan's avatar
jehan committed
422
	const char* l_header = "WWW-Authenticate: Digest "
jehan's avatar
jehan committed
423
			"algorithm=MD5, realm=\"atlanta.com\", opaque=\"1bc7f9097684320\","
jehan's avatar
jehan committed
424
			" qop=\"auth,auth-int\", nonce=\"c60f3082ee1212b402a21831ae\", stale=true, domain=\"sip:boxesbybob.com\"";
425
	belle_sip_header_www_authenticate_t* L_tmp;
jehan's avatar
jehan committed
426 427 428 429 430
	belle_sip_header_www_authenticate_t* l_authenticate = belle_sip_header_www_authenticate_parse(l_header);


	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_authenticate));
	belle_sip_object_unref(BELLE_SIP_OBJECT(l_authenticate));
431
	L_tmp = belle_sip_header_www_authenticate_parse(l_raw_header);
jehan's avatar
jehan committed
432
	l_authenticate = BELLE_SIP_HEADER_WWW_AUTHENTICATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
433
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
434
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
435
	check_header_authenticate(l_authenticate);
jehan's avatar
jehan committed
436

jehan's avatar
jehan committed
437 438

}
Ghislain MARY's avatar
Ghislain MARY committed
439 440

static void test_proxy_authenticate_header(void) {
jehan's avatar
jehan committed
441 442 443 444 445
	const char* l_header = "Proxy-Authenticate: Digest "
			"algorithm=MD5, realm=\"atlanta.com\", opaque=\"1bc7f9097684320\","
			" qop=\"auth,auth-int\", nonce=\"c60f3082ee1212b402a21831ae\", stale=true, domain=\"sip:boxesbybob.com\"";
	belle_sip_header_proxy_authenticate_t* L_tmp;
	belle_sip_header_proxy_authenticate_t* L_proxy_authorization = belle_sip_header_proxy_authenticate_parse(l_header);
446
	//belle_sip_list_t* qop;
jehan's avatar
jehan committed
447 448 449 450 451 452 453 454

	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_proxy_authorization));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_proxy_authorization));
	L_tmp = belle_sip_header_proxy_authenticate_parse(l_raw_header);
	L_proxy_authorization = BELLE_SIP_HEADER_PROXY_AUTHENTICATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);
	check_header_authenticate(BELLE_SIP_HEADER_WWW_AUTHENTICATE(L_proxy_authorization));
jehan's avatar
jehan committed
455
}
jehan's avatar
jehan committed
456

Ghislain MARY's avatar
Ghislain MARY committed
457
static void test_max_forwards_header(void) {
jehan's avatar
jehan committed
458
	const char* l_header = "Max-Forwards: 6";
459
	belle_sip_header_max_forwards_t* L_tmp;
jehan's avatar
jehan committed
460
	belle_sip_header_max_forwards_t* L_max_forwards = belle_sip_header_max_forwards_parse(l_header);
461
	char* l_raw_header;
jehan's avatar
jehan committed
462
	belle_sip_header_max_forwards_decrement_max_forwards(L_max_forwards);
463
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_max_forwards));
jehan's avatar
jehan committed
464
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_max_forwards));
465 466 467 468
	L_tmp = belle_sip_header_max_forwards_parse(l_raw_header);
	L_max_forwards = BELLE_SIP_HEADER_MAX_FORWARDS(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));

jehan's avatar
jehan committed
469 470 471 472 473 474
	belle_sip_free(l_raw_header);
	CU_ASSERT_PTR_NOT_NULL(L_max_forwards);
	CU_ASSERT_EQUAL(belle_sip_header_max_forwards_get_max_forwards(L_max_forwards), 5);

	belle_sip_object_unref(BELLE_SIP_OBJECT(L_max_forwards));

475
}
Ghislain MARY's avatar
Ghislain MARY committed
476 477

static void test_user_agent_header(void) {
jehan's avatar
jehan committed
478
	const char* l_header = "User-Agent: Linphone/3.4.99.1 (eXosip2/3.3.0)";
479 480 481
	const char* values[] ={"Linphone/3.4.99.1"
				,"(eXosip2/3.3.0)"};
	belle_sip_list_t* products;
482
	belle_sip_header_user_agent_t* L_tmp;
jehan's avatar
jehan committed
483 484
	belle_sip_header_user_agent_t* L_user_agent = belle_sip_header_user_agent_parse(l_header);
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_user_agent));
485
	int i=0;
jehan's avatar
jehan committed
486
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));
487 488 489 490
	L_tmp = belle_sip_header_user_agent_parse(l_raw_header);
	L_user_agent = BELLE_SIP_HEADER_USER_AGENT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));

jehan's avatar
jehan committed
491 492
	belle_sip_free(l_raw_header);

493
	products = belle_sip_header_user_agent_get_products(L_user_agent);
jehan's avatar
jehan committed
494 495 496 497 498 499 500 501 502 503

	for(i=0;i<2;i++){
		CU_ASSERT_PTR_NOT_NULL(products);
		CU_ASSERT_STRING_EQUAL((const char *)(products->data),values[i]);
		products=products->next;
	}

	belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));

}
Ghislain MARY's avatar
Ghislain MARY committed
504 505

static void test_expires_header(void) {
506
	belle_sip_header_expires_t* L_tmp;
jehan's avatar
jehan committed
507 508 509
	belle_sip_header_expires_t* L_expires = belle_sip_header_expires_parse("Expires: 3600");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_expires));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_expires));
510 511 512
	L_tmp= belle_sip_header_expires_parse(l_raw_header);
	L_expires = BELLE_SIP_HEADER_EXPIRES(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
513 514 515
	belle_sip_free(l_raw_header);
	CU_ASSERT_EQUAL(belle_sip_header_expires_get_expires(L_expires), 3600);
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_expires));
jehan's avatar
jehan committed
516 517 518 519
	/*test factory*/
	L_expires = belle_sip_header_expires_create(600);
	CU_ASSERT_EQUAL(belle_sip_header_expires_get_expires(L_expires), 600);
	belle_sip_object_unref(L_expires);
jehan's avatar
jehan committed
520
}
Ghislain MARY's avatar
Ghislain MARY committed
521 522

static void test_allow_header(void) {
523
	belle_sip_header_allow_t* L_tmp;
jehan's avatar
jehan committed
524 525 526
	belle_sip_header_allow_t* L_allow = belle_sip_header_allow_parse("Allow:INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_allow));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
527 528 529
	L_tmp = belle_sip_header_allow_parse(l_raw_header);
	L_allow = BELLE_SIP_HEADER_ALLOW(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
jehan's avatar
jehan committed
530 531 532 533 534 535
	belle_sip_free(l_raw_header);

	CU_ASSERT_STRING_EQUAL(belle_sip_header_allow_get_method(L_allow), "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
}

Ghislain MARY's avatar
Ghislain MARY committed
536
static void test_address_with_error_header(void) {
jehan's avatar
jehan committed
537 538 539
	belle_sip_header_address_t* laddress = belle_sip_header_address_parse("sip:liblinphone_tester@=auth1.example.org");
	CU_ASSERT_PTR_NULL(laddress);
}
jehan's avatar
jehan committed
540

Ghislain MARY's avatar
Ghislain MARY committed
541
static void test_address_header(void) {
542
	belle_sip_uri_t* L_uri;
jehan's avatar
jehan committed
543 544 545
	belle_sip_header_address_t* laddress = belle_sip_header_address_parse("\"toto\" <sip:liblinphone_tester@81.56.11.2:5060>");
	CU_ASSERT_PTR_NOT_NULL_FATAL(laddress);
	CU_ASSERT_STRING_EQUAL("toto",belle_sip_header_address_get_displayname(laddress))
546
	L_uri = belle_sip_header_address_get_uri(laddress);
jehan's avatar
jehan committed
547 548 549 550 551 552 553

	CU_ASSERT_PTR_NOT_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "81.56.11.2");
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "liblinphone_tester");
	CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060);
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
}
Ghislain MARY's avatar
Ghislain MARY committed
554

555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
static void test_very_long_address_header(void) {
	belle_sip_uri_t* L_uri;
	const char* raw = "<sip:jehan@sip.linphone.org"
					";app-id=622464153529"
					";pn-type=google"
					";pn-tok=APA91bHPVa4PuKOMnr6ppWb3XYUL06QO-ND4eeiw7dG49q4o_Ywzal7BxVRgH-wvqH9iB9V7h6kfb-DCiVdSpnl6CeWO25FAkM4eh6DJyWcbP7SzhKdku_-r9936kJW7-4drI6-Om4qp"
					";pn-msg-str=IM_MSG"
					";pn-call-str=IC_MSG"
					";pn-call-snd=ring.caf"
					";pn-msg-snd=msg.caf"
					";>"; /*not compliant but*/

	belle_sip_header_address_t* laddress = belle_sip_header_address_parse(raw);
	CU_ASSERT_PTR_NOT_NULL_FATAL(laddress);
	L_uri = belle_sip_header_address_get_uri(laddress);

	CU_ASSERT_PTR_NOT_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.linphone.org");
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "jehan");
	CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_uri),"pn-tok")
			,"APA91bHPVa4PuKOMnr6ppWb3XYUL06QO-ND4eeiw7dG49q4o_Ywzal7BxVRgH-wvqH9iB9V7h6kfb-DCiVdSpnl6CeWO25FAkM4eh6DJyWcbP7SzhKdku_-r9936kJW7-4drI6-Om4qp");
	belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
}



Ghislain MARY's avatar
Ghislain MARY committed
581
static void test_subscription_state_header(void) {
jehan's avatar
jehan committed
582 583 584 585 586 587 588 589 590 591 592 593 594
	belle_sip_header_subscription_state_t* L_tmp;
	belle_sip_header_subscription_state_t* L_subscription_state = belle_sip_header_subscription_state_parse("Subscription-State: terminated;expires=600");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_subscription_state));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_subscription_state));
	L_tmp = belle_sip_header_subscription_state_parse(l_raw_header);
	L_subscription_state = BELLE_SIP_HEADER_SUBSCRIPTION_STATE(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);

	CU_ASSERT_STRING_EQUAL(belle_sip_header_subscription_state_get_state(L_subscription_state), "terminated");
	CU_ASSERT_EQUAL(belle_sip_header_subscription_state_get_expires(L_subscription_state), 600);
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_subscription_state));
}
Ghislain MARY's avatar
Ghislain MARY committed
595 596

static void test_refer_to_header(void) {
jehan's avatar
jehan committed
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
	belle_sip_uri_t* L_uri;
	belle_sip_header_refer_to_t* L_refer_to = belle_sip_header_refer_to_parse("Refer-To: <sip:dave@denver.example.org?Replaces=12345%40192.168.118.3%3Bto-tag%3D12345%3Bfrom-tag%3D5FFE-3994>");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_refer_to));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_refer_to));
	L_refer_to = belle_sip_header_refer_to_parse(l_raw_header);
	belle_sip_free(l_raw_header);

	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_refer_to));

	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri),"dave");
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "denver.example.org");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_refer_to));
	/*test factory*/
	L_refer_to = belle_sip_header_refer_to_create(belle_sip_header_address_parse("\"super man\" <sip:titi.com>"));
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_refer_to);
	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_refer_to));
	CU_ASSERT_PTR_NOT_NULL_FATAL(L_uri);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(L_refer_to)), "super man");
	belle_sip_object_unref(L_refer_to);

}
Ghislain MARY's avatar
Ghislain MARY committed
618 619

static void test_referred_by_header(void) {
jehan's avatar
jehan committed
620 621 622 623 624 625 626 627 628 629 630 631 632
	belle_sip_uri_t* L_uri;
	belle_sip_header_referred_by_t* L_referred_by = belle_sip_header_referred_by_parse("Referred-By: sip:r@ref.example;cid=\"2UWQFN309shb3@ref.example\"");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_referred_by));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_referred_by));
	L_referred_by = belle_sip_header_referred_by_parse(l_raw_header);
	belle_sip_free(l_raw_header);

	L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_referred_by));

	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri),"r");
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "ref.example");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_referred_by));
}
Ghislain MARY's avatar
Ghislain MARY committed
633 634

static void test_replaces_header(void) {
jehan's avatar
jehan committed
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
	belle_sip_header_replaces_t* L_tmp;
	belle_sip_header_replaces_t* L_replaces = belle_sip_header_replaces_parse("Replaces: 12345@149.112.118.3;to-tag=12345;from-tag=54321");
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_replaces));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
	L_tmp= belle_sip_header_replaces_parse(l_raw_header);
	L_replaces = BELLE_SIP_HEADER_REPLACES(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);

	CU_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_call_id(L_replaces), "12345@149.112.118.3");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_from_tag(L_replaces), "54321");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_to_tag(L_replaces), "12345");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
}

Ghislain MARY's avatar
Ghislain MARY committed
650
static void test_replaces_escaped_header(void) {
651 652
	belle_sip_header_replaces_t* L_replaces;
	char* escaped_to_string;
653
	char* l_raw_header;
654 655 656
	belle_sip_header_replaces_t* L_tmp = belle_sip_header_replaces_create("12345@192.168.118.3","5FFE-3994","12345");
	escaped_to_string=belle_sip_header_replaces_value_to_escaped_string(L_tmp);
	L_replaces=belle_sip_header_replaces_create2(escaped_to_string);
657
	l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_replaces));
jehan's avatar
jehan committed
658 659 660 661 662
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
	L_tmp= belle_sip_header_replaces_parse(l_raw_header);
	L_replaces = BELLE_SIP_HEADER_REPLACES(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
	belle_sip_free(l_raw_header);
663
	belle_sip_free(escaped_to_string);
jehan's avatar
jehan committed
664 665 666 667

	CU_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_call_id(L_replaces), "12345@192.168.118.3");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_from_tag(L_replaces), "5FFE-3994");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_replaces_get_to_tag(L_replaces), "12345");
668 669 670



671
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
672

jehan's avatar
jehan committed
673
}
jehan's avatar
jehan committed
674

Ghislain MARY's avatar
Ghislain MARY committed
675 676 677

test_t headers_tests[] = {
	{ "Address", test_address_header },
678
	{ "Header address (very long)", test_very_long_address_header },
Ghislain MARY's avatar
Ghislain MARY committed
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
	{ "Address with error", test_address_with_error_header },
	{ "Allow", test_allow_header },
	{ "Authorization", test_authorization_header },
	{ "Call-ID", test_call_id_header },
	{ "Contact (Simple)", test_simple_contact_header },
	{ "Contact (Complex)", test_complex_contact_header },
	{ "Contact (Param-less address spec)", test_contact_header_with_paramless_address_spec },
	{ "Content-Length", test_content_length_header },
	{ "Content-Type", test_content_type_header },
	{ "CSeq", test_cseq_header },
	{ "Expires", test_expires_header },
	{ "From", test_from_header },
	{ "From (Param-less address spec)", test_from_header_with_paramless_address_spec },
	{ "Max-Forwards", test_max_forwards_header },
	{ "Proxy-Authenticate", test_proxy_authenticate_header },
	{ "Proxy-Authorization", test_proxy_authorization_header },
	{ "Record-Route", test_record_route_header },
	{ "Refer-To", test_refer_to_header },
	{ "Referred-By", test_referred_by_header },
	{ "Replaces", test_replaces_header },
	{ "Replaces (Escaped)", test_replaces_escaped_header },
	{ "Route", test_route_header },
	{ "Service-Route", test_service_route_header },
	{ "Subscription-State", test_subscription_state_header },
	{ "To", test_to_header },
	{ "To (Param-less address spec)", test_to_header_with_paramless_address_spec },
	{ "User-Agent", test_user_agent_header },
	{ "Via", test_via_header },
	{ "WWW-Authenticate", test_www_authenticate_header },
	{ "Header extension", test_header_extension }
709

Ghislain MARY's avatar
Ghislain MARY committed
710 711 712 713 714 715 716 717 718 719
};

test_suite_t headers_test_suite = {
	"Headers",
	NULL,
	NULL,
	sizeof(headers_tests) / sizeof(headers_tests[0]),
	headers_tests
};