belle_sip_headers_tester.c 22.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"
jehan's avatar
jehan committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include <stdio.h>
#include "CUnit/Basic.h"

int init_suite1(void) {
      return 0;
}

int clean_suite1(void) {
      return 0;
}


void test_simple_header_contact(void) {

	belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("Contact:sip:titi.com");
jehan's avatar
jehan committed
37 38 39 40 41
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_contact));
	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
42 43 44 45 46
	belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri((belle_sip_header_address_t*)L_contact);

	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
47
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
jehan's avatar
jehan committed
48 49
}

jehan's avatar
jehan committed
50
void test_complex_header_contact(void) {
jehan's avatar
jehan committed
51

jehan's avatar
jehan committed
52
	belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("Contact: \"jremis\" <sip:sip.linphone.org>;expires=3600;q=0.7, sip:titi.com");
jehan's avatar
jehan committed
53 54


jehan's avatar
jehan committed
55 56 57
	belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri((belle_sip_header_address_t*)L_contact);

	CU_ASSERT_PTR_NOT_NULL(L_uri);
jehan's avatar
jehan committed
58
	CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.linphone.org");
jehan's avatar
jehan committed
59 60 61 62

	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);
jehan's avatar
jehan committed
63
	float l_qvalue = belle_sip_header_contact_get_qvalue(L_contact);
64
	CU_ASSERT_EQUAL(l_qvalue,0.7f);
jehan's avatar
jehan committed
65

jehan's avatar
jehan committed
66 67 68 69 70
	belle_sip_header_t* l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_contact));
	belle_sip_header_contact_t* L_next_contact = BELLE_SIP_HEADER_CONTACT(l_next);
	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
71
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
jehan's avatar
jehan committed
72 73

	L_contact = belle_sip_header_contact_parse("Contact: toto <sip:titi.com>;expires=3600; q=0.7");
jehan's avatar
jehan committed
74 75 76 77
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_contact));
	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
78 79

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

jehan's avatar
jehan committed
82 83
}

jehan's avatar
jehan committed
84
void test_simple_header_from(void) {
jehan's avatar
jehan committed
85

jehan's avatar
jehan committed
86
	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
87 88 89 90 91
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_from));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
	L_from = belle_sip_header_from_parse(l_raw_header);
	belle_sip_free(l_raw_header);

jehan's avatar
jehan committed
92 93 94 95 96 97 98 99 100 101 102
	belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from));

	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));
}

void test_simple_header_to(void) {

	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
103 104 105 106 107
	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);

jehan's avatar
jehan committed
108 109 110 111 112 113 114
	belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to));

	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));
}
115 116 117
void test_header_via(void) {

	belle_sip_header_via_t* 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");
jehan's avatar
jehan committed
118 119 120 121 122
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_via));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
	L_via = belle_sip_header_via_parse(l_raw_header);
	belle_sip_free(l_raw_header);

123 124 125 126 127 128 129 130 131
	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");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_host(L_via), "192.168.0.19");
	CU_ASSERT_EQUAL(belle_sip_header_via_get_port(L_via),5062);

	CU_ASSERT_TRUE(belle_sip_parameters_is_parameter(BELLE_SIP_PARAMETERS(L_via),"rport"));
	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
132 133 134 135 136 137 138 139 140

	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");

	belle_sip_header_t* l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_via));
	belle_sip_header_via_t* L_next_via = BELLE_SIP_HEADER_VIA(l_next);
	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));

141
}
jehan's avatar
jehan committed
142
void test_header_call_id(void) {
143

jehan's avatar
jehan committed
144
	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
145 146 147 148 149
	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));
	L_call_id = belle_sip_header_call_id_parse(l_raw_header);
	belle_sip_free(l_raw_header);

jehan's avatar
jehan committed
150 151
	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));
152 153 154 155
}
void test_header_cseq(void) {

	belle_sip_header_cseq_t* L_cseq = belle_sip_header_cseq_parse("CSeq: 21 INVITE");
jehan's avatar
jehan committed
156 157 158 159 160
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_cseq));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_cseq));
	L_cseq = belle_sip_header_cseq_parse(l_raw_header);
	belle_sip_free(l_raw_header);

161 162 163 164 165 166 167
	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));
}
void test_header_content_type(void) {

	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
168 169 170 171 172
	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));
	L_content_type = belle_sip_header_content_type_parse(l_raw_header);
	belle_sip_free(l_raw_header);

173 174 175 176
	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
177 178

	L_content_type = belle_sip_header_content_type_parse("Content-Type: application/sdp");
jehan's avatar
jehan committed
179 180 181 182
	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
183 184 185 186 187
	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
188 189 190 191
	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
192 193
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));

194
}
jehan's avatar
jehan committed
195 196 197
void test_header_record_route(void) {

	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
198 199 200 201
	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);
jehan's avatar
jehan committed
202 203 204 205 206
	belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_record_route));
	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
207 208 209 210 211 212 213

	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>");
	belle_sip_header_t* l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_record_route));
	belle_sip_header_record_route_t* L_next_route = BELLE_SIP_HEADER_RECORD_ROUTE(l_next);
	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
214 215 216 217
}
void test_header_route(void) {

	belle_sip_header_route_t* L_route = belle_sip_header_route_parse("Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4");
jehan's avatar
jehan committed
218 219 220 221
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_route));
	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);
jehan's avatar
jehan committed
222 223 224 225 226
	belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_route));
	CU_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri));
	CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060);
	CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_route),"charset"),"ISO-8859-4");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
jehan's avatar
jehan committed
227 228 229 230 231 232 233

	L_route = belle_sip_header_route_parse("Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:titi.com>");
	belle_sip_header_t* l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_route));
	belle_sip_header_route_t* L_next_route = BELLE_SIP_HEADER_ROUTE(l_next);
	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
234
}
jehan's avatar
jehan committed
235 236 237
void test_header_content_length(void) {

	belle_sip_header_content_length_t* L_content_length = belle_sip_header_content_length_parse("Content-Length: 3495");
jehan's avatar
jehan committed
238 239 240 241
	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));
	L_content_length = belle_sip_header_content_length_parse(l_raw_header);
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
242 243 244
	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));
}
245 246
void test_header_extention(void) {
	belle_sip_header_extension_t* L_extension = belle_sip_header_extension_parse("toto: titi");
jehan's avatar
jehan committed
247 248 249 250 251
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_extension));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_extension));
	L_extension = belle_sip_header_extension_parse(l_raw_header);
	belle_sip_free(l_raw_header);

252 253 254 255
	CU_ASSERT_STRING_EQUAL(belle_sip_header_extension_get_value(L_extension), "titi");
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_extension));
}
void test_header_authorization(void) {
jehan's avatar
jehan committed
256
	const char* l_header = "Authorization: Digest username=\"0033482532176\", "\
257
			"realm=\"sip.ovh.net\", nonce=\"1bcdcb194b30df5f43973d4c69bdf54f\", uri=\"sip:sip.ovh.net\", response=\"eb36c8d5c8642c1c5f44ec3404613c81\","\
258 259
			"algorithm=MD5, opaque=\"1bc7f9097684320\","
			"\r\n qop=auth, nc=00000001,cnonce=\"0a4f113b\", blabla=\"toto\"";
jehan's avatar
jehan committed
260 261 262 263 264 265
	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));
	L_authorization = belle_sip_header_authorization_parse(l_raw_header);
	belle_sip_free(l_raw_header);

266
	CU_ASSERT_PTR_NOT_NULL(L_authorization);
jehan's avatar
jehan committed
267
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_scheme(L_authorization), "Digest");
268
	CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_username(L_authorization), "0033482532176");
jehan's avatar
jehan committed
269 270 271 272
	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");
273 274 275 276 277 278
	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");
	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\"");
279 280
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
}
281
void test_header_proxy_authorization(void) {
jehan's avatar
jehan committed
282
	const char* l_header = "Proxy-Authorization: Digest username=\"Alice\""
283 284
			", realm=\"atlanta.com\", nonce=\"c60f3082ee1212b402a21831ae\""
			", response=\"245f23415f11432b3434341c022\"";
jehan's avatar
jehan committed
285 286 287 288 289
	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);
290 291 292 293
	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
294 295 296 297
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));

}
void test_header_www_authenticate(void) {
jehan's avatar
jehan committed
298
	const char* l_header = "WWW-Authenticate: Digest "
jehan's avatar
jehan committed
299 300
			"algorithm=MD5, realm=\"atlanta.com\", opaque=\"1bc7f9097684320\","
			" qop=\"auth\", nonce=\"c60f3082ee1212b402a21831ae\", stale=true, domain=\"sip:boxesbybob.com\"";
jehan's avatar
jehan committed
301 302 303 304 305
	belle_sip_header_www_authenticate_t* L_authorization = belle_sip_header_www_authenticate_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_www_authenticate_parse(l_raw_header);
	belle_sip_free(l_raw_header);
jehan's avatar
jehan committed
306 307 308 309 310 311 312 313 314
	CU_ASSERT_PTR_NOT_NULL(L_authorization);
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_realm(L_authorization), "atlanta.com");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_domain(L_authorization), "sip:boxesbybob.com");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_nonce(L_authorization), "c60f3082ee1212b402a21831ae");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_algorithm(L_authorization), "MD5");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_opaque(L_authorization), "1bc7f9097684320");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_qop(L_authorization), "auth");
	CU_ASSERT_STRING_EQUAL(belle_sip_header_www_authenticate_get_scheme(L_authorization), "Digest");
	CU_ASSERT_EQUAL(belle_sip_header_www_authenticate_is_stale(L_authorization),1);
315
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
jehan's avatar
jehan committed
316

jehan's avatar
jehan committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330
}
void test_header_max_forwards(void) {
	const char* l_header = "Max-Forwards: 6";
	belle_sip_header_max_forwards_t* L_max_forwards = belle_sip_header_max_forwards_parse(l_header);
	belle_sip_header_max_forwards_decrement_max_forwards(L_max_forwards);
	char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_max_forwards));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_max_forwards));
	L_max_forwards = belle_sip_header_max_forwards_parse(l_raw_header);
	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));

331
}
jehan's avatar
jehan committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
void test_header_user_agent(void) {
	const char* l_header = "User-Agent: Linphone/3.4.99.1 (eXosip2/3.3.0)";
	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));
	belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));
	L_user_agent = belle_sip_header_user_agent_parse(l_raw_header);
	belle_sip_free(l_raw_header);

	const char* values[] ={"Linphone/3.4.99.1"
				,"(eXosip2/3.3.0)"};
	int i=0;
	belle_sip_list_t* products = belle_sip_header_user_agent_get_products(L_user_agent);

	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));

}
void test_header_expires(void) {

	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));
	L_expires = belle_sip_header_expires_parse(l_raw_header);
	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));
}
void test_header_allow(void) {
	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));
	L_allow = belle_sip_header_allow_parse(l_raw_header);
	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));
}

jehan's avatar
jehan committed
375
int belle_sip_headers_test_suite() {
376
	
jehan's avatar
jehan committed
377 378 379 380 381 382 383 384 385
	   CU_pSuite pSuite = NULL;
	   /* add a suite to the registry */
	   pSuite = CU_add_suite("header_suite", init_suite1, clean_suite1);

	   /* add the tests to the suite */
	   /* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
	   if (NULL == CU_add_test(pSuite, "test of simple contact header", test_simple_header_contact)) {
	      return CU_get_error();
	   }
jehan's avatar
jehan committed
386 387 388
	   if (NULL == CU_add_test(pSuite, "test of complex contact header", test_complex_header_contact)) {
	      return CU_get_error();
	   }
jehan's avatar
jehan committed
389 390 391 392 393 394
	   if (NULL == CU_add_test(pSuite, "test of from header", test_simple_header_from)) {
	      return CU_get_error();
	   }
	   if (NULL == CU_add_test(pSuite, "test of to header", test_simple_header_to)) {
	      return CU_get_error();
	   }
395 396 397
	   if (NULL == CU_add_test(pSuite, "test of via header", test_header_via)) {
	      return CU_get_error();
	   }
jehan's avatar
jehan committed
398
	   if (NULL == CU_add_test(pSuite, "test of call_id header", test_header_call_id)) {
399 400 401 402 403 404 405 406
	      return CU_get_error();
	   }
	   if (NULL == CU_add_test(pSuite, "test of cseq header", test_header_cseq)) {
	      return CU_get_error();
	   }
	   if (NULL == CU_add_test(pSuite, "test of content type header", test_header_content_type)) {
	      return CU_get_error();
	   }
jehan's avatar
jehan committed
407 408 409 410 411 412
	   if (NULL == CU_add_test(pSuite, "test of record route header", test_header_record_route)) {
	      return CU_get_error();
	   }
	   if (NULL == CU_add_test(pSuite, "test of route header", test_header_route)) {
	      return CU_get_error();
	   }
jehan's avatar
jehan committed
413
	   if (NULL == CU_add_test(pSuite, "test of content length", test_header_content_length)) {
jehan's avatar
jehan committed
414 415
	      return CU_get_error();
	   }
416 417 418 419 420 421
	   if (NULL == CU_add_test(pSuite, "test of extension", test_header_extention)) {
	      return CU_get_error();
	   }
	   if (NULL == CU_add_test(pSuite, "test of authorization", test_header_authorization)) {
	      return CU_get_error();
	   }
422 423 424
	   if (NULL == CU_add_test(pSuite, "test of proxy authorization", test_header_proxy_authorization)) {
	      return CU_get_error();
	   }
jehan's avatar
jehan committed
425 426 427
	   if (NULL == CU_add_test(pSuite, "test of www authenticate", test_header_www_authenticate)) {
	      return CU_get_error();
	   }
jehan's avatar
jehan committed
428
	   if (NULL == CU_add_test(pSuite, "test of max forwards", test_header_max_forwards)) {
jehan's avatar
jehan committed
429 430 431 432 433 434 435 436 437 438 439
	      return CU_get_error();
	   }
	   if (NULL == CU_add_test(pSuite, "test of  user agent", test_header_user_agent)) {
	   	  return CU_get_error();
	   }
	   if (NULL == CU_add_test(pSuite, "test of  expires", test_header_expires)) {
	   	  return CU_get_error();
	   	}
	   if (NULL == CU_add_test(pSuite, "test of  allow", test_header_allow)) {
	   	  return CU_get_error();
	   	}
440
	   return 0;
jehan's avatar
jehan committed
441
}