/[resiprocate]/main/resip/stack/test/testUri.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testUri.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11153 - (show annotations) (download)
Wed Apr 23 17:25:02 2014 UTC (5 years, 6 months ago) by dpetrie
File MIME type: text/plain
File size: 24631 byte(s)
added netns scope/context to Uri and Tuple

1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <memory>
6 #include <iostream>
7
8 #include "TestSupport.hxx"
9 #include "resip/stack/UnknownParameterType.hxx"
10 #include "resip/stack/Uri.hxx"
11 #include "rutil/DataStream.hxx"
12 #include "rutil/Logger.hxx"
13 #include "rutil/DnsUtil.hxx"
14 #include "rutil/ParseBuffer.hxx"
15 #include "resip/stack/SipMessage.hxx"
16 #include "resip/stack/Helper.hxx"
17
18 using namespace resip;
19 using namespace std;
20
21 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
22
23 int
24 main(int argc, char* argv[])
25 {
26 Log::Level l = Log::Debug;
27 Log::initialize(Log::Cerr, l, argv[0]);
28 initNetwork();
29
30 {
31 Uri uri("sip:speedy_AT_home.com@whistler.gloo.net:5062");
32 uri.scheme() = Symbols::Pres;
33 assert(Data::from(uri) == "pres:speedy_AT_home.com@whistler.gloo.net:5062");
34 }
35 {
36 const char * a = "alice";
37 const char * e = "example.com";
38
39 NameAddr alice;
40 alice.uri().user() = a;
41 alice.uri().host() = e;
42
43 NameAddr realm;
44 realm.uri().host() = e;
45
46 NameAddr aliceContact;
47 aliceContact.uri().user() = a;
48 aliceContact.uri().host() = "127.1.0.1";
49 aliceContact.uri().port() = 32678;
50
51
52
53 auto_ptr<SipMessage> msg(Helper::makeRegister(alice,alice,aliceContact));
54
55 cout << *msg << endl;
56
57 // Make the data
58 NameAddr original(aliceContact);
59 original.uri().param(UnknownParameterType("x")) = Data("\"1\"");
60
61 Uri tmp = original.uri();
62 Data buf;
63 DataStream oldNA(buf);
64 oldNA << Symbols::LA_QUOTE;
65 oldNA << original.uri().scheme();
66 oldNA << Symbols::COLON;
67 oldNA << original.uri().getAor();
68 oldNA << Symbols::RA_QUOTE;
69 oldNA.flush();
70
71 NameAddr modified;
72 modified.uri() = tmp; // copy parameters;
73 modified.uri().host() = e;
74 modified.uri().port() = 65530;
75 modified.uri().user() = "alphabet-soup";
76
77 Data gruuData ( Data::from(modified.uri())) ;
78 msg->header(h_Contacts).back().param(p_pubGruu) = gruuData;
79
80
81 cout << *msg << endl;
82
83 Uri s1("sip:alice@example.com;gr=\"foo@example.com\"");
84 Uri s2("sip:alice@example.com;gr=\"foo@example.com\"");
85 assert(s1.param(p_gr) == Data("foo@example.com"));
86 assert(s2.param(p_gr) == Data("foo@example.com"));
87 cout << s1 << endl;
88 cout << s2 << endl;
89 cout << endl;
90 Uri s3("sip:alice@example.com");
91 s3.param(UnknownParameterType("foo")) = Data("value");
92 Uri s4("sip:alice@example.com");
93 s4.param(UnknownParameterType("foo")) = Data("\"value\"");
94 cout << "s3's param =" << s3.param(UnknownParameterType("foo")) << endl;
95 cout << "s4's param =" << s4.param(UnknownParameterType("foo")) << endl;
96 cout << "s3 = " << s3 << endl;
97 cout << "s4 = " << s4 << endl;
98 Uri s5(s4);
99 cout << "s5 = " << s5 << endl;
100 Data s5d(Data::from(s5));
101 cout << "s5d = " << s5d << endl;
102
103 Uri s6("sip:bob@example.com");
104 s6.host();
105
106 Uri s7("sip:testproxy.example.com");
107 assert (s7.user().empty());
108 s7.user() = "test";
109 assert (!s7.user().empty());
110 s7.user().clear();
111 assert (s7.user().empty());
112
113 NameAddr na1;
114 na1.uri().user() = "alice";
115 na1.uri().host() = "example.com";
116
117 Data q("\"");
118 na1.param(UnknownParameterType("foo")) = Data(q + Data::from(s6) +q);
119 NameAddr na2(na1);
120 cout << "na1=" << na1 << endl;
121 cout << "na2=" << na2 << endl;
122
123 }
124 //assert(0);
125 {
126 // Test order irrelevance of known parameters
127 Uri sip1("sip:user@domain;ttl=15;method=foo");
128 Uri sip2("sip:user@domain;method=foo;ttl=15");
129
130 cerr << "!!" << sip1.host() << endl;
131 cerr << "!!" << sip2.host() << endl;
132
133 assert (sip1 == sip2);
134 assert (sip2 == sip1);
135
136 #ifdef USE_NETNS
137 cerr << "Testing NETNS" << endl;
138
139 sip1.netNs() = "ns1";
140 assert(sip1.netNs() == "ns1");
141 assert(!(sip1 == sip2));
142 assert(!(sip2 == sip1));
143 Uri sip3(sip1);
144 assert(sip1 == sip3);
145 assert(!(sip2 == sip3));
146 assert(!(sip3 == sip2));
147 sip2 = sip1;
148 assert(sip1 == sip2);
149 assert(sip2 == sip1);
150 #endif
151 }
152
153 {
154 assert(DnsUtil::isIpV6Address("::1"));
155 }
156
157 #ifdef USE_IPV6
158 {
159 cerr << "!! " << DnsUtil::canonicalizeIpV6Address("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210") << endl;
160 assert(DnsUtil::canonicalizeIpV6Address("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210") ==
161 "fedc:ba98:7654:3210:fedc:ba98:7654:3210");
162 }
163
164 {
165 cerr << "!! " << DnsUtil::canonicalizeIpV6Address("5f1b:df00:ce3e:e200:20:800:121.12.131.12") << endl;
166 assert(DnsUtil::canonicalizeIpV6Address("5f1b:df00:ce3e:e200:20:800:121.12.131.12") ==
167 "5f1b:df00:ce3e:e200:20:800:790c:830c");
168 }
169
170 {
171 cerr << "!! " << DnsUtil::canonicalizeIpV6Address("5f1B::20:800:121.12.131.12") << endl;
172 assert(DnsUtil::canonicalizeIpV6Address("5f1B::20:800:121.12.131.12") ==
173 "5f1b::20:800:790c:830c");
174 }
175
176 {
177 Uri uri("sip:[5f1b:df00:ce3e:e200:20:800:121.12.131.12]");
178
179 cerr << "!! " << uri.host() << endl;
180 assert(uri.host() == "5f1b:df00:ce3e:e200:20:800:121.12.131.12");
181 cerr << "!! " << Data::from(uri) << endl;
182 assert(Data::from(uri) == "sip:[5f1b:df00:ce3e:e200:20:800:121.12.131.12]");
183 }
184
185 {
186 Uri uri("sip:user@[5f1b:df00:ce3e:e200:20:800:121.12.131.12]");
187
188 cerr << "!! " << uri.host() << endl;
189 assert(uri.host() == "5f1b:df00:ce3e:e200:20:800:121.12.131.12");
190 cerr << "!! " << Data::from(uri) << endl;
191 assert(Data::from(uri) == "sip:user@[5f1b:df00:ce3e:e200:20:800:121.12.131.12]");
192 }
193 #endif
194
195 {
196 Uri uri("sips:192.168.2.12");
197
198 assert(uri.scheme() == "sips");
199 assert(uri.password() == "");
200 assert(uri.userParameters() == "");
201 assert(uri.host() == "192.168.2.12");
202 assert(uri.port() == 0);
203 }
204
205 {
206 Uri uri("sips:host.foo.com");
207 assert(uri.scheme() == "sips");
208 assert(uri.password() == "");
209 assert(uri.userParameters() == "");
210 assert(uri.host() == "host.foo.com");
211 assert(uri.port() == 0);
212 }
213
214 {
215 Uri uri("sip:user;x-v17:password@host.com:5555");
216
217 cerr << "user!!" << uri.user() << endl;
218 cerr << "password!!" << uri.password() << endl;
219 cerr << "userParams!!" << uri.userParameters() << endl;
220
221 assert(uri.scheme() == "sip");
222 assert(uri.user() == "user;x-v17");
223 assert(uri.password() == "password");
224 assert(uri.userParameters() == "");
225 assert(uri.host() == "host.com");
226 assert(uri.port() == 5555);
227 }
228
229 {
230 // test bad parses
231 try
232 {
233 Uri("noscheme@foo.com:1202");
234 assert(false);
235 }
236 catch (ParseException& e)
237 {
238 }
239 }
240
241 {
242 Uri w1("sip:wombat@192.168.2.221:5062;transport=Udp");
243 Uri w2("sip:wombat@192.168.2.221:5063;transport=Udp");
244 assert(w1 != w2);
245 assert(w1 < w2);
246 }
247 {
248 Uri tel("tel:+358-555-1234567;pOstd=pP2;isUb=1411");
249 assert(tel.user() == "+358-555-1234567");
250
251 assert(Data::from(tel) == "tel:+358-555-1234567;pOstd=pP2;isUb=1411");
252 }
253
254 {
255 Uri tel("tel:+358-555-1234567;pOstd=pP2;isUb=1411");
256 Uri sip(Uri::fromTel(tel, Uri("sip:company.com")));
257
258 cerr << "!! " << Data::from(sip) << endl;
259 assert(Data::from(sip) == "sip:+358-555-1234567;isub=1411;postd=pp2@company.com;user=phone");
260 }
261
262 {
263 Uri tel("tel:+358-555-1234567;foo=bar;aaaa=baz;pOstd=pP2;isUb=1411");
264 Uri sip(Uri::fromTel(tel, Uri("sip:company.com")));
265
266 cerr << "!! " << Data::from(sip) << endl;
267 assert(Data::from(sip) == "sip:+358-555-1234567;isub=1411;postd=pp2;aaaa=baz;foo=bar@company.com;user=phone");
268 }
269
270 {
271 Uri tel("tel:+358-555-1234567;postd=pp22");
272 Uri sip(Uri::fromTel(tel, Uri("sip:foo.com")));
273 assert(Data::from(sip) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone");
274 }
275 {
276 Uri tel1("tel:+358-555-1234567;postd=pp22");
277 Uri tel2("tel:+358-555-1234567;POSTD=PP22");
278 cerr << "tel1=" << tel1 << " user=" << tel1.user() << endl;
279 cerr << "tel2=" << tel2 << " user=" << tel2.user() << endl;
280 assert (tel1 == tel2);
281 }
282 {
283 Uri tel1("sip:+358-555-1234567;postd=pp22@foo.com;user=phone");
284 Uri tel2("sip:+358-555-1234567;POSTD=PP22@foo.com;user=phone");
285 assert (tel1 != tel2);
286 }
287 {
288 Uri tel1("tel:+358-555-1234567;postd=pp22;isub=1411");
289 Uri tel2("tel:+358-555-1234567;isub=1411;postd=pp22");
290 // requires us to parse the user parameters
291 //assert (tel1 == tel2);
292 }
293 {
294 Uri tel1("sip:+358-555-1234567;postd=pp22;isub=1411@foo.com;user=phone");
295 Uri tel2("sip:+358-555-1234567;isub=1411;postd=pp22@foo.com;user=phone");
296 assert (tel1 != tel2);
297 }
298 {
299 Uri tel1("tel:+358-555-1234567;postd=pp22");
300 Uri tel2("tel:+358-555-1234567;POSTD=PP22");
301 Uri sip1(Uri::fromTel(tel1, Uri("sip:foo.com")));
302 Uri sip2(Uri::fromTel(tel2, Uri("sip:foo.com")));
303 assert (sip1 == sip2);
304 assert (Data::from(sip1) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone");
305 assert (Data::from(sip2) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone");
306 }
307 {
308 Uri tel1("tel:+358-555-1234567;tsp=a.b;phone-context=5");
309 Uri tel2("tel:+358-555-1234567;phone-context=5;tsp=a.b");
310 Uri sip1(Uri::fromTel(tel1, Uri("sip:foo.com")));
311 Uri sip2(Uri::fromTel(tel2, Uri("sip:foo.com")));
312 assert (sip1 == sip2);
313 assert (Data::from(sip1) == "sip:+358-555-1234567;phone-context=5;tsp=a.b@foo.com;user=phone");
314 assert (Data::from(sip2) == "sip:+358-555-1234567;phone-context=5;tsp=a.b@foo.com;user=phone");
315 }
316
317 {
318 Uri uri("sip:fluffy@iii.ca:666");
319 assert(uri.scheme() == "sip");
320 assert(uri.user() == "fluffy");
321 assert(uri.host() == "iii.ca");
322 assert(uri.port() == 666);
323 }
324
325 {
326 Uri uri("sip:fluffy@iii.ca;transport=tcp");
327 assert(uri.param(p_transport) == "tcp");
328 }
329
330 {
331 Uri uri("sips:fluffy@iii.ca;transport=tls");
332 assert(uri.scheme() == "sips");
333 assert(uri.param(p_transport) == "tls");
334 }
335
336 {
337 Uri uri("sip:fluffy@iii.ca;transport=sctp");
338 assert(uri.param(p_transport) == "sctp");
339 }
340
341 {
342 Uri uri("sip:fluffy:password@iii.ca");
343 assert(uri.password() == "password");
344 }
345
346 {
347 Uri uri("sip:fluffy@iii.ca;user=phone;ttl=5;lr;maddr=1.2.3.4");
348 assert(uri.param(p_ttl) == 5);
349 assert(uri.exists(p_lr) == true);
350 assert(uri.param(p_maddr) == "1.2.3.4");
351 assert(uri.param(p_user) == "phone");
352 }
353
354 {
355 Uri uri("sip:fluffy@iii.ca;x-fluffy=foo");
356 assert(uri.exists(UnknownParameterType("x-fluffy")) == true);
357 assert(uri.exists(UnknownParameterType("x-fufu")) == false);
358 assert(uri.param(UnknownParameterType("x-fluffy")) == "foo");
359 }
360
361 {
362 Uri uri("sip:fluffy@iii.ca;method=MESSAGE");
363 assert(uri.param(p_method) == "MESSAGE");
364 }
365
366 {
367 Uri uri("sip:+1(408) 444-1212:666@gw1");
368 assert(uri.user() == "+1(408) 444-1212");
369 assert(uri.password() == "666");
370 assert(uri.host() == "gw1");
371 }
372
373 {
374 Uri uri("sip:fluffy;x-utag=foo@iii.ca");
375 assert(uri.user() == "fluffy;x-utag=foo");
376 assert(uri.host() == "iii.ca");
377
378 Data out(Data::from(uri));
379 assert(out == "sip:fluffy;x-utag=foo@iii.ca");
380 }
381
382 {
383 Uri uri("sip:fluffy;x-utag=foo:password@iii.ca");
384 assert(uri.user() == "fluffy;x-utag=foo");
385 assert(uri.host() == "iii.ca");
386 assert(uri.password() == "password");
387
388 Data out(Data::from(uri));
389 cerr << "!! " << out << endl;
390 assert(out == "sip:fluffy;x-utag=foo:password@iii.ca");
391 }
392
393 {
394 Uri uri("tel:+14086661212");
395 assert(uri.user() == "+14086661212");
396 assert(uri.userParameters() == "");
397 assert(uri.host() == "");
398 assert(uri.password() == "");
399
400 Data out(Data::from(uri));
401 cerr << "!! " << out << endl;
402 assert(out == "tel:+14086661212");
403 }
404
405 {
406 Uri uri("tel:+14086661212;foo=bie");
407 assert(uri.user() == "+14086661212");
408 assert(uri.userParameters() == "foo=bie");
409 assert(uri.host() == "");
410 assert(uri.password() == "");
411
412 Data out(Data::from(uri));
413 cerr << "!! " << out << endl;
414 assert(out == "tel:+14086661212;foo=bie");
415 }
416
417 {
418 Uri uri("tel:+14086661212;");
419 assert(uri.user() == "+14086661212");
420 assert(uri.userParameters() == "");
421 assert(uri.host() == "");
422 assert(uri.password() == "");
423
424 Data out(Data::from(uri));
425 cerr << "!! " << out << endl;
426 assert(out == "tel:+14086661212");
427 }
428
429 {
430 Uri uri("sip:;:@");
431 cerr << "uri.user() = " << uri.user() << endl;
432 assert(uri.user() == ";");
433 assert(uri.userParameters() == "");
434 assert(uri.host() == "");
435 assert(uri.password() == "");
436
437 Data out(Data::from(uri));
438 cerr << "!! " << out << endl;
439 assert(out == "sip:;");
440 }
441
442 {
443 Uri uri("tel:+1 (408) 555-1212");
444 assert(uri.scheme() == "tel");
445 }
446 // Tests for user-less uris (was broken accidentally v1.44 Uri.cxx)
447 {
448 Data original("sip:1.2.3.4:5060");
449 Data encoded;
450 Uri uri(original);
451
452 DataStream ds(encoded);
453 uri.encode(ds);
454 ds.flush();
455 cout << "!! original data: " << original << endl;
456 cout << "!! original uri : " << uri << endl;
457 cout << "!! encoded data: " << encoded << endl;
458
459 assert( encoded == original );
460 }
461
462 {
463 // Test order irrelevance of unknown parameters
464 Uri sip1("sip:user@domain;foo=bar;baz=qux");
465 Uri sip2("sip:user@domain;baz=qux;foo=bar");
466 assert (sip1 == sip2);
467 assert (sip2 == sip1);
468 }
469
470 {
471 // Test order irrelevance of known parameters
472 Uri sip1("sip:user@domain;ttl=15;method=foo");
473 Uri sip2("sip:user@domain;method=foo;ttl=15");
474
475 assert (sip1 == sip2);
476 assert (sip2 == sip1);
477 }
478
479
480 // tests from 3261 19.1.4
481 {
482 Uri sip1("sip:alice@atlanta.com;transport=TCP");
483 Uri sip2("sip:alice@AtLanTa.CoM;Transport=tcp");
484
485 assert(sip1 == sip2);
486 assert(sip2 == sip1);
487 }
488
489 {
490 Uri sip1("sip:carol@chicago.com");
491 Uri sip2("sip:carol@chicago.com;newparam=5");
492 Uri sip3("sip:carol@chicago.com;security=on");
493
494 assert(sip1 == sip2);
495 assert(sip2 == sip1);
496 assert(sip2 == sip3);
497 assert(sip3 == sip2);
498 assert(sip3 == sip1);
499 assert(sip1 == sip3);
500 }
501
502 {
503 Uri sip1("sip:biloxi.com;transport=tcp;method=REGISTER?to=sip:bob%40biloxi.com");
504 Uri sip2("sip:biloxi.com;method=REGISTER;transport=tcp?to=sip:bob%40biloxi.com");
505
506 assert(sip1 == sip2);
507 assert(sip2 == sip1);
508 }
509
510 {
511 Uri sip1("sip:alice@atlanta.com?subject=project%20x&priority=urgent");
512 Uri sip2("sip:alice@atlanta.com?priority=urgent&subject=project%20x");
513
514 assert(sip1 == sip2);
515 assert(sip2 == sip1);
516 }
517
518 {
519 Uri sip1("SIP:ALICE@AtLanTa.CoM;Transport=udp"); // (different usernames)
520 Uri sip2("sip:alice@AtLanTa.CoM;Transport=UDP");
521
522 assert(sip1 != sip2);
523 }
524
525 {
526 Uri sip1("sip:bob@biloxi.com"); // (can resolve to different ports)
527 Uri sip2("sip:bob@biloxi.com:5060");
528
529 assert(sip1 != sip2);
530 }
531
532 {
533 Uri sip1("sip:bob@biloxi.com"); // (can resolve to different transports)
534 Uri sip2("sip:bob@biloxi.com;transport=udp");
535
536 assert(sip1 != sip2);
537 }
538
539 {
540 Uri sip1("sip:bob@biloxi.com"); // (can resolve to different port and transports)
541 Uri sip2("sip:bob@biloxi.com:6000;transport=tcp");
542
543 assert(sip1 != sip2);
544 }
545
546 // !dlb! we ignore embedded headers at the moment
547 if (false)
548 {
549 Uri sip1("sip:carol@chicago.com"); // (different header component)
550 Uri sip2("sip:carol@chicago.com?Subject=next%20meeting");
551
552 assert(sip1 != sip2);
553 }
554
555 {
556 Uri sip1("sip:bob@phone21.boxesbybob.com"); // (even though that's what phone21.boxesbybob.com resolves to)
557 Uri sip2("sip:bob@192.0.2.4");
558
559 assert(sip1 != sip2);
560 }
561
562 {
563 Uri sip1("sip:carol@chicago.com");
564 Uri sip2("sip:carol@chicago.com;security=on");
565 Uri sip3("sip:carol@chicago.com;security=off");
566
567 assert(sip1 == sip2);
568 assert(sip1 == sip3);
569 assert(sip2 != sip3);
570 assert(sip3 != sip2);
571 }
572
573 {
574 Uri sip1("sip:carol@chicago.com");
575 Uri sip2("sip:carol@chicago.com:5060");
576 Uri sip3("sip:1.2.3.4");
577 Uri sip4("sip:1.2.3.4:5070");
578 Uri sip1a("sip:carol@chicago.com;user=phone;foo=bar");
579 Uri sip2a("sip:carol@chicago.com:5060;user=phone;foo=bar");
580 Uri sip3a("sip:1.2.3.4;user=phone;foo=bar");
581 Uri sip4a("sip:1.2.3.4:5070;user=phone;foo=bar");
582
583 DebugLog( << "sip1.getAor==" << sip1.getAor() );
584 DebugLog( << "sip1.getAorNoPort==" << sip1.getAorNoPort() );
585 DebugLog( << "sip2.getAor==" << sip2.getAor() );
586 DebugLog( << "sip2.getAorNoPort==" << sip2.getAorNoPort() );
587
588 assert( sip1.getAor() == Data("carol@chicago.com") );
589 assert( sip2.getAor() == Data("carol@chicago.com:5060") );
590 assert( sip3.getAor() == Data("1.2.3.4") );
591 assert( sip4.getAor() == Data("1.2.3.4:5070") );
592
593 assert( sip1a.getAor() == Data("carol@chicago.com") );
594 assert( sip2a.getAor() == Data("carol@chicago.com:5060") );
595 assert( sip3a.getAor() == Data("1.2.3.4") );
596 assert( sip4a.getAor() == Data("1.2.3.4:5070") );
597
598 assert( sip1.getAorNoPort() == Data("carol@chicago.com") );
599 assert( sip2.getAorNoPort() == Data("carol@chicago.com") );
600 assert( sip3.getAorNoPort() == Data("1.2.3.4") );
601 assert( sip4.getAorNoPort() == Data("1.2.3.4") );
602
603 assert( sip1a.getAorNoPort() == Data("carol@chicago.com") );
604 assert( sip2a.getAorNoPort() == Data("carol@chicago.com") );
605 assert( sip3a.getAorNoPort() == Data("1.2.3.4") );
606 assert( sip4a.getAorNoPort() == Data("1.2.3.4") );
607 }
608
609 // Displayname parse tests
610 {
611 NameAddr sip1("\"DispName\" <sip:user@host.com>");
612 NameAddr sip2("\"DispName \"<sip:user@host.com>");
613 NameAddr sip3("\" DispName\"<sip:user@host.com>");
614 NameAddr sip4("DispName <sip:user@host.com>");
615 NameAddr sip5("DispName<sip:user@host.com>");
616 NameAddr sip6(" DispName <sip:user@host.com>");
617 NameAddr sip7(" DispName<sip:user@host.com>");
618 NameAddr sip8(" Disp Name <sip:user@host.com>");
619
620 DebugLog( << "sip1.displayName=='" << sip1.displayName() << "'" );
621 DebugLog( << "sip2.displayName=='" << sip2.displayName() << "'" );
622 DebugLog( << "sip3.displayName=='" << sip3.displayName() << "'" );
623 DebugLog( << "sip4.displayName=='" << sip4.displayName() << "'" );
624 DebugLog( << "sip5.displayName=='" << sip5.displayName() << "'" );
625 DebugLog( << "sip6.displayName=='" << sip6.displayName() << "'" );
626 DebugLog( << "sip7.displayName=='" << sip7.displayName() << "'" );
627 DebugLog( << "sip8.displayName=='" << sip8.displayName() << "'" );
628
629 assert( sip1.displayName() == Data("DispName") );
630 assert( sip2.displayName() == Data("DispName ") );
631 assert( sip3.displayName() == Data(" DispName") );
632 assert( sip4.displayName() == Data("DispName") );
633 assert( sip5.displayName() == Data("DispName") );
634 assert( sip6.displayName() == Data("DispName") );
635 assert( sip7.displayName() == Data("DispName") );
636 assert( sip8.displayName() == Data("Disp Name") );
637
638 assert( sip1.uri().getAor() == Data("user@host.com") );
639 assert( sip2.uri().getAor() == Data("user@host.com") );
640 assert( sip3.uri().getAor() == Data("user@host.com") );
641 assert( sip4.uri().getAor() == Data("user@host.com") );
642 assert( sip5.uri().getAor() == Data("user@host.com") );
643 assert( sip6.uri().getAor() == Data("user@host.com") );
644 assert( sip7.uri().getAor() == Data("user@host.com") );
645 assert( sip8.uri().getAor() == Data("user@host.com") );
646 }
647
648 // Embedded header testing
649 {
650 NameAddr addr("sip:user@domain.com?Call-Info=%3csip:192.168.0.1%3e%3banswer-after=0");
651 //cout << addr << endl;
652 assert(Data::from(addr.uri()) == "sip:user@domain.com?Call-Info=%3csip:192.168.0.1%3e%3banswer-after=0");
653 //cout << "CallInfo: " << addr.uri().embedded().header(h_CallInfos).front() << endl;
654 assert(Data::from(addr.uri().embedded().header(h_CallInfos).front()) == "<sip:192.168.0.1>;answer-after=0");
655 }
656
657 // URI containing special character #
658 // technically, # is meant to be encoded, but some systems (Asterisk,
659 // some Cisco gear) seem to send this un-encoded
660 // Some carriers insert # between a phone number and a billing prefix
661 {
662 Uri uri = Uri("sip:1234#00442031111111@lvdx.com");
663 //cout << "Encoded correctly: " << uri << endl;
664 assert(Data::from(uri) == "sip:1234%2300442031111111@lvdx.com");
665
666 Uri::setUriUserEncoding('#', false);
667 uri = Uri("sip:1234#00442031111111@lvdx.com");
668 //cout << "Non Encoded # for compatibility: " << uri << endl;
669 assert(Data::from(uri) == "sip:1234#00442031111111@lvdx.com");
670 Uri::setUriUserEncoding('#', true);
671 }
672
673 {
674 Uri uri = Uri("sip:1234#00442031111111;phone-context=+89@lvdx.com");
675 assert(uri.userIsTelephoneSubscriber());
676 Token telSub(uri.getUserAsTelephoneSubscriber());
677 assert(telSub.value()=="1234#00442031111111");
678 static ExtensionParameter p_phoneContext("phone-context");
679 assert(telSub.exists(p_phoneContext));
680 assert(telSub.param(p_phoneContext)=="+89");
681 telSub.param(p_phoneContext)="+98";
682 uri.setUserAsTelephoneSubscriber(telSub);
683 assert(Data::from(uri) == "sip:1234%2300442031111111;phone-context=+98@lvdx.com");
684 }
685
686 {
687 Uri uri = Uri("sip:+1-(234)-00442031111111@lvdx.com");
688 assert(uri.userIsTelephoneSubscriber());
689 Token telSub(uri.getUserAsTelephoneSubscriber());
690 assert(telSub.value()=="+1-(234)-00442031111111");
691 assert(!telSub.exists(p_extension));
692 telSub.param(p_extension)="4545";
693 uri.setUserAsTelephoneSubscriber(telSub);
694 assert(Data::from(uri) == "sip:+1-(234)-00442031111111;ext=4545@lvdx.com");
695 }
696 cerr << endl << "All OK" << endl;
697 return 0;
698 }
699 /* ====================================================================
700 * The Vovida Software License, Version 1.0
701 *
702 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
703 *
704 * Redistribution and use in source and binary forms, with or without
705 * modification, are permitted provided that the following conditions
706 * are met:
707 *
708 * 1. Redistributions of source code must retain the above copyright
709 * notice, this list of conditions and the following disclaimer.
710 *
711 * 2. Redistributions in binary form must reproduce the above copyright
712 * notice, this list of conditions and the following disclaimer in
713 * the documentation and/or other materials provided with the
714 * distribution.
715 *
716 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
717 * and "Vovida Open Communication Application Library (VOCAL)" must
718 * not be used to endorse or promote products derived from this
719 * software without prior written permission. For written
720 * permission, please contact vocal@vovida.org.
721 *
722 * 4. Products derived from this software may not be called "VOCAL", nor
723 * may "VOCAL" appear in their name, without prior written
724 * permission of Vovida Networks, Inc.
725 *
726 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
727 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
728 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
729 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
730 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
731 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
732 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
733 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
734 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
735 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
736 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
737 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
738 * DAMAGE.
739 *
740 * ====================================================================
741 *
742 * This software consists of voluntary contributions made by Vovida
743 * Networks, Inc. and many individuals on behalf of Vovida Networks,
744 * Inc. For more information on Vovida Networks, Inc., please see
745 * <http://www.vovida.org/>.
746 *
747 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27