📄 testuri.cxx
字号:
} { Uri uri("sip:+1(408) 444-1212:666@gw1"); assert(uri.user() == "+1(408) 444-1212"); assert(uri.password() == "666"); assert(uri.host() == "gw1"); } { Uri uri("sip:fluffy;x-utag=foo@iii.ca"); assert(uri.user() == "fluffy;x-utag=foo"); assert(uri.host() == "iii.ca"); Data out(Data::from(uri)); assert(out == "sip:fluffy;x-utag=foo@iii.ca"); } { Uri uri("sip:fluffy;x-utag=foo:password@iii.ca"); assert(uri.user() == "fluffy;x-utag=foo"); assert(uri.host() == "iii.ca"); assert(uri.password() == "password"); Data out(Data::from(uri)); cerr << "!! " << out << endl; assert(out == "sip:fluffy;x-utag=foo:password@iii.ca"); } { Uri uri("tel:+14086661212"); assert(uri.user() == "+14086661212"); assert(uri.userParameters() == ""); assert(uri.host() == ""); assert(uri.password() == ""); Data out(Data::from(uri)); cerr << "!! " << out << endl; assert(out == "tel:+14086661212"); } { Uri uri("tel:+14086661212;foo=bie"); assert(uri.user() == "+14086661212"); assert(uri.userParameters() == "foo=bie"); assert(uri.host() == ""); assert(uri.password() == ""); Data out(Data::from(uri)); cerr << "!! " << out << endl; assert(out == "tel:+14086661212;foo=bie"); } { Uri uri("tel:+14086661212;"); assert(uri.user() == "+14086661212"); assert(uri.userParameters() == ""); assert(uri.host() == ""); assert(uri.password() == ""); Data out(Data::from(uri)); cerr << "!! " << out << endl; assert(out == "tel:+14086661212"); } { Uri uri("sip:;:@"); cerr << "uri.user() = " << uri.user() << endl; assert(uri.user() == ";"); assert(uri.userParameters() == ""); assert(uri.host() == ""); assert(uri.password() == ""); Data out(Data::from(uri)); cerr << "!! " << out << endl; assert(out == "sip:;"); } { Uri uri("tel:+1 (408) 555-1212"); assert(uri.scheme() == "tel"); } // Tests for user-less uris (was broken accidentally v1.44 Uri.cxx) { Data original("sip:1.2.3.4:5060"); Data encoded; Uri uri(original); DataStream ds(encoded); uri.encode(ds); ds.flush(); cout << "!! original data: " << original << endl; cout << "!! original uri : " << uri << endl; cout << "!! encoded data: " << encoded << endl; assert( encoded == original ); } { // Test order irrelevance of unknown parameters Uri sip1("sip:user@domain;foo=bar;baz=qux"); Uri sip2("sip:user@domain;baz=qux;foo=bar"); assert (sip1 == sip2); assert (sip2 == sip1); } { // Test order irrelevance of known parameters Uri sip1("sip:user@domain;ttl=15;method=foo"); Uri sip2("sip:user@domain;method=foo;ttl=15"); assert (sip1 == sip2); assert (sip2 == sip1); } // tests from 3261 19.1.4 { Uri sip1("sip:alice@atlanta.com;transport=TCP"); Uri sip2("sip:alice@AtLanTa.CoM;Transport=tcp"); assert(sip1 == sip2); assert(sip2 == sip1); } { Uri sip1("sip:carol@chicago.com"); Uri sip2("sip:carol@chicago.com;newparam=5"); Uri sip3("sip:carol@chicago.com;security=on"); assert(sip1 == sip2); assert(sip2 == sip1); assert(sip2 == sip3); assert(sip3 == sip2); assert(sip3 == sip1); assert(sip1 == sip3); } { Uri sip1("sip:biloxi.com;transport=tcp;method=REGISTER?to=sip:bob%40biloxi.com"); Uri sip2("sip:biloxi.com;method=REGISTER;transport=tcp?to=sip:bob%40biloxi.com"); assert(sip1 == sip2); assert(sip2 == sip1); } { Uri sip1("sip:alice@atlanta.com?subject=project%20x&priority=urgent"); Uri sip2("sip:alice@atlanta.com?priority=urgent&subject=project%20x"); assert(sip1 == sip2); assert(sip2 == sip1); } { Uri sip1("SIP:ALICE@AtLanTa.CoM;Transport=udp"); // (different usernames) Uri sip2("sip:alice@AtLanTa.CoM;Transport=UDP"); assert(sip1 != sip2); } { Uri sip1("sip:bob@biloxi.com"); // (can resolve to different ports) Uri sip2("sip:bob@biloxi.com:5060"); assert(sip1 != sip2); } { Uri sip1("sip:bob@biloxi.com"); // (can resolve to different transports) Uri sip2("sip:bob@biloxi.com;transport=udp"); assert(sip1 != sip2); } { Uri sip1("sip:bob@biloxi.com"); // (can resolve to different port and transports) Uri sip2("sip:bob@biloxi.com:6000;transport=tcp"); assert(sip1 != sip2); } // !dlb! we ignore embedded headers at the moment if (false) { Uri sip1("sip:carol@chicago.com"); // (different header component) Uri sip2("sip:carol@chicago.com?Subject=next%20meeting"); assert(sip1 != sip2); } { Uri sip1("sip:bob@phone21.boxesbybob.com"); // (even though that's what phone21.boxesbybob.com resolves to) Uri sip2("sip:bob@192.0.2.4"); assert(sip1 != sip2); } { Uri sip1("sip:carol@chicago.com"); Uri sip2("sip:carol@chicago.com;security=on"); Uri sip3("sip:carol@chicago.com;security=off"); assert(sip1 == sip2); assert(sip1 == sip3); assert(sip2 != sip3); assert(sip3 != sip2); } { Uri sip1("sip:carol@chicago.com"); Uri sip2("sip:carol@chicago.com:5060"); Uri sip3("sip:1.2.3.4"); Uri sip4("sip:1.2.3.4:5070"); Uri sip1a("sip:carol@chicago.com;user=phone;foo=bar"); Uri sip2a("sip:carol@chicago.com:5060;user=phone;foo=bar"); Uri sip3a("sip:1.2.3.4;user=phone;foo=bar"); Uri sip4a("sip:1.2.3.4:5070;user=phone;foo=bar"); DebugLog( << "sip1.getAor==" << sip1.getAor() ); DebugLog( << "sip1.getAorNoPort==" << sip1.getAorNoPort() ); DebugLog( << "sip2.getAor==" << sip2.getAor() ); DebugLog( << "sip2.getAorNoPort==" << sip2.getAorNoPort() ); assert( sip1.getAor() == Data("carol@chicago.com") ); assert( sip2.getAor() == Data("carol@chicago.com:5060") ); assert( sip3.getAor() == Data("1.2.3.4") ); assert( sip4.getAor() == Data("1.2.3.4:5070") ); assert( sip1a.getAor() == Data("carol@chicago.com") ); assert( sip2a.getAor() == Data("carol@chicago.com:5060") ); assert( sip3a.getAor() == Data("1.2.3.4") ); assert( sip4a.getAor() == Data("1.2.3.4:5070") ); assert( sip1.getAorNoPort() == Data("carol@chicago.com") ); assert( sip2.getAorNoPort() == Data("carol@chicago.com") ); assert( sip3.getAorNoPort() == Data("1.2.3.4") ); assert( sip4.getAorNoPort() == Data("1.2.3.4") ); assert( sip1a.getAorNoPort() == Data("carol@chicago.com") ); assert( sip2a.getAorNoPort() == Data("carol@chicago.com") ); assert( sip3a.getAorNoPort() == Data("1.2.3.4") ); assert( sip4a.getAorNoPort() == Data("1.2.3.4") ); } // Displayname parse tests { NameAddr sip1("\"DispName\" <sip:user@host.com>"); NameAddr sip2("\"DispName \"<sip:user@host.com>"); NameAddr sip3("\" DispName\"<sip:user@host.com>"); NameAddr sip4("DispName <sip:user@host.com>"); NameAddr sip5("DispName<sip:user@host.com>"); NameAddr sip6(" DispName <sip:user@host.com>"); NameAddr sip7(" DispName<sip:user@host.com>"); NameAddr sip8(" Disp Name <sip:user@host.com>"); DebugLog( << "sip1.displayName=='" << sip1.displayName() << "'" ); DebugLog( << "sip2.displayName=='" << sip2.displayName() << "'" ); DebugLog( << "sip3.displayName=='" << sip3.displayName() << "'" ); DebugLog( << "sip4.displayName=='" << sip4.displayName() << "'" ); DebugLog( << "sip5.displayName=='" << sip5.displayName() << "'" ); DebugLog( << "sip6.displayName=='" << sip6.displayName() << "'" ); DebugLog( << "sip7.displayName=='" << sip7.displayName() << "'" ); DebugLog( << "sip8.displayName=='" << sip8.displayName() << "'" ); assert( sip1.displayName() == Data("DispName") ); assert( sip2.displayName() == Data("DispName ") ); assert( sip3.displayName() == Data(" DispName") ); assert( sip4.displayName() == Data("DispName") ); assert( sip5.displayName() == Data("DispName") ); assert( sip6.displayName() == Data("DispName") ); assert( sip7.displayName() == Data("DispName") ); assert( sip8.displayName() == Data("Disp Name") ); assert( sip1.uri().getAor() == Data("user@host.com") ); assert( sip2.uri().getAor() == Data("user@host.com") ); assert( sip3.uri().getAor() == Data("user@host.com") ); assert( sip4.uri().getAor() == Data("user@host.com") ); assert( sip5.uri().getAor() == Data("user@host.com") ); assert( sip6.uri().getAor() == Data("user@host.com") ); assert( sip7.uri().getAor() == Data("user@host.com") ); assert( sip8.uri().getAor() == Data("user@host.com") ); } // Embedded header testing { NameAddr addr("sip:user@domain.com?Call-Info=%3csip:192.168.0.1%3e%3banswer-after=0"); //cout << addr << endl; assert(Data::from(addr.uri()) == "sip:user@domain.com?Call-Info=%3csip:192.168.0.1%3e%3banswer-after=0"); //cout << "CallInfo: " << addr.uri().embedded().header(h_CallInfos).front() << endl; assert(Data::from(addr.uri().embedded().header(h_CallInfos).front()) == "<sip:192.168.0.1>;answer-after=0"); } // URI containing special character # // technically, # is meant to be encoded, but some systems (Asterisk, // some Cisco gear) seem to send this un-encoded // Some carriers insert # between a phone number and a billing prefix { Uri uri = Uri("sip:1234#00442031111111@lvdx.com"); //cout << "Encoded correctly: " << uri << endl; assert(Data::from(uri) == "sip:1234%2300442031111111@lvdx.com"); Uri::setUriUserEncoding('#', false); uri = Uri("sip:1234#00442031111111@lvdx.com"); //cout << "Non Encoded # for compatibility: " << uri << endl; assert(Data::from(uri) == "sip:1234#00442031111111@lvdx.com"); } cerr << endl << "All OK" << endl; return 0;}/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -