📄 invitemsgtest.cxx
字号:
Record-Route: <sip:5452@172.19.175.150:5060;maddr=172.19.175.150>,<sip:5452@172.19.175.150:5060;maddr=172.19.175.150>\r\n\Contact: <sip:5451@172.19.174.170:5060>,<sip:6000@172.19.174.170:5060>,<sip:7000@172.19.174.170:5060>\r\n\Content-Length: 228\r\n\User-Agent: Cisco IP Phone/ Rev. 1/ SIP enabled\r\n\Content-Type: application/sdp\r\n\\r\n\v=0\r\n\o=CiscoSystemsSIP-IPPhone-UserAgent 21803 10790 IN IP4 172.19.174.170\r\n\s=SIP Call\r\n\c=IN IP4 172.19.174.170\r\n\t=0 0\r\n\m=audio 28844 RTP/AVP 0 8 18 100\r\n\a=rtpmap:0 pcmu/8000\r\n\a=rtpmap:100 telephone-event/8000\r\n\a=fmtp:100 0-11\r\n\\r\n", "INVITE sip:5452@172.19.174.171:5060 SIP/2.0\r\n\Via: SIP/2.0/UDP 172.19.175.150:5060;branch=78377a23f9fb8014efae61c726ec6e77.4\r\n\Via: SIP/2.0/UDP 172.19.175.150:5060;branch=d1faef3fff22fbedaa794b8ea2abc7e5.2\r\n\Via: SIP/2.0/UDP 172.19.174.170:5060\r\n\From: \"5451\"<sip:5451@172.19.175.150>\r\n\To: <sip:5452@172.19.175.150>\r\n\Call-ID: c4943000-75748-7058-2e323731@172.19.174.170\r\n\CSeq: 101 INVITE\r\n\Expires: 180\r\n\Accept: application/sdp\r\n\Record-Route: <sip:5452@172.19.175.150:5060;maddr=172.19.175.150>,<sip:5452@172.19.175.150:5060;maddr=172.19.175.150>\r\n\Contact: <sip:5451@172.19.174.170:5060>,<sip:6000@172.19.174.170:5060>,<sip:7000@172.19.174.170:5060>\r\n\Content-Length: 228\r\n\User-Agent: Cisco IP Phone/ Rev. 1/ SIP enabled\r\n\Content-Type: application/sdp\r\n\\r\n\v=0\r\n\o=CiscoSystemsSIP-IPPhone-UserAgent 21803 10790 IN IP4 172.19.174.170\r\n\s=SIP Call\r\n\c=IN IP4 172.19.174.170\r\n\t=0 0\r\n\m=audio 28844 RTP/AVP 0 8 18 100\r\n\a=rtpmap:0 pcmu/8000\r\n\a=rtpmap:100 telephone-event/8000\r\n\a=fmtp:100 0-11\r\n", "INVITE sip:bko@bko-lnx:5070 SIP/2.0\rVia: SIP/2.0/UDP 128.107.140.140:5060\rFrom: Phone<sip:6399@128.107.140.140:5060;user=phone>\rTo: bko<sip:bko@bko-lnx:5070>\rCall-ID: 922b14475cfd3fbe10fd3fbec27b0608@128.107.140.140\rCSeq: 1 INVITE\rSubject: VovidaINVITE\rContact: <sip:6399@128.107.140.140:5060;user=phone>\rContent-Length: 230\r\rv=0\ro=- 1943909507 1943909507 IN IP4 128.107.140.140\rs=VOVIDA Session\rc=IN IP4 128.107.140.140\rt=3195510838 0\rm=audio 10000 RTP/AVP 0 101\ra=rtpmap:0 PCMU/8000\ra=rtpmap:101 telephone-event/8000\ra=ptime:20\ra=fmtp:101 0-11\r", 0}; char* contactList[] = { "Contact: <sip:5451@172.19.174.170:5060>\r\n", "Contact: <sip:6000@172.19.174.170:5060>\r\n", "Contact: <sip:7000@172.19.174.170:5060>\r\n", 0};char* viaList[] ={ "Via: SIP/2.0/UDP 172.19.175.150:5060;branch=78377a23f9fb8014efae61c726ec6e77.4\r\n", "Via: SIP/2.0/UDP 172.19.175.150:5060;branch=d1faef3fff22fbedaa794b8ea2abc7e5.2\r\n", "Via: SIP/2.0/UDP 172.19.174.170:5060\r\n", 0};void testDecode(){ { InviteMsg invite(msgtext[2]); } { InviteMsg invite(msgtext[1]); SipContactList list = invite.getContactList(); int j = 0; SipContactList::iterator i; for(i = list.begin(); i != list.end(); ++i) { test_verify((*i)->encode() == contactList[j]); j++; } SipViaList vias = invite.getViaList(); j = 0; SipViaList::iterator k; for(k = vias.begin(); k != vias.end(); ++k) { test_verify((*k)->encode() == viaList[j]); j++; } test_verify(list.begin() != list.end()); test_verify(!list.empty()); Sptr<BaseUrl> burl = invite.getRequestLine().getUrl(); Sptr<SipUrl> url; url.dynamicCast(burl); test_verify(url != 0); } { InviteMsg empty; SipContactList list = empty.getContactList(); test_verify(list.begin() == list.end()); test_verify(list.empty()); } { InviteMsg invite1(msgtext[1]); InviteMsg invite2(msgtext[1]); test_verify(invite1 == invite2); invite2.forceParse(); test_verify(invite1 == invite2); if(invite1 != invite2) { cout << invite1.encode(); cout << "-------------------------------------\n"; cout << invite2.encode(); } SipFrom from = invite2.getFrom(); Sptr<BaseUrl> burl = from.getUrl(); Sptr<SipUrl> url; url.dynamicCast(burl); Sptr<BaseUser> user = new SipUser("asdfasfd"); url->setUser(user); from.setUrl(url); invite2.setFrom(from); test_verify(invite1 != invite2); InviteMsg invite3(msgtext[0]); invite3.encode(); test_verify(invite1 == invite3); } { InviteMsg invite1(msgtext[1]); Data text = invite1.encode(); SipVia via = invite1.getVia(0); invite1.removeVia(0); invite1.setVia(via, 0); test_verify(text == invite1.encode());// cout << "hi" << endl;// cout << invite1.encode() << endl; } { InviteMsg invite1(msgtext[1]); Data text = invite1.encode(); SipVia via = invite1.getVia(1); invite1.removeVia(1); invite1.setVia(via, 1); test_verify(text == invite1.encode());// cout << "hi2" << endl;// cout << invite1.encode() << endl; }}void testDuplicate(){ // test duplication of an InviteMsg Sptr<SipUrl> toUrl = new SipUrl(string("sip:bko@bko-lnx:5070")); InviteMsg msg( toUrl, 5060 ); Sptr<SipContentData> content = msg.getContentData(0); test_verify(content != 0); Sptr<SipSdp> sdp; sdp.dynamicCast(content); test_verify(sdp != 0); { InviteMsg copy(msg); Sptr<SipContentData> copy_content = msg.getContentData(0); test_verify(copy_content != 0); Sptr<SipSdp> copy_sdp; copy_sdp.dynamicCast(copy_content); test_verify(copy_sdp != 0); } { InviteMsg copy; copy = msg; Sptr<SipContentData> copy_content = msg.getContentData(0); test_verify(copy_content != 0);#if 0 // this is not implemented Sptr<SipSdp> copy_sdp; copy_sdp.dynamicCast(copy_content); test_verify(copy_sdp != 0); test_verify(*copy_sdp == *sdp);#endif } { // verify that the message has only a single MIME type test_verify(msg.getContentType() == SipContentType("application", "SDP")); cout << msg.getContentType().encode()<< endl; } { // verify the encoding Data result = msg.encode(); cout << result; } { test_verify(msg == msg); InviteMsg copy(msg); test_verify(copy == msg); InviteMsg copy2; copy2 = msg; test_verify(copy2 == msg); } { InviteMsg copy(msgtext1[5]); test_verify(copy.getFrom().getUser() == "5451"); test_verify(copy.getTo().getUser() == "5452"); SipDiversion dive = copy.getDiversion(); cerr << "REASON:" << dive.getReason().c_str() << endl; Sptr<SipCallLeg> mySipCallLeg = new SipCallLeg(copy.computeCallLeg()); // test_verify(mySipCallLeg->getFrom().getUser() == "5451"); // test_verify(mySipCallLeg->getTo().getUser() == "5452"); }}int main(){ testEncodeDecode(); testDecode(); testDuplicate(); return test_return_code(31);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -