⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 siptorturetests.cxx

📁 一个著名的SIP协议栈
💻 CXX
📖 第 1 页 / 共 3 页
字号:
      auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
      tassert(0);
   }
   catch (ParseException& e)
   {
   }
   
   tassert_verify(10);
}

void test11()
{
   CritLog( << "2.11 INVITE missing Required Headers");

   const char* txt = ("INVITE sip:user@company.com SIP/2.0\r\n"
                "CSeq: 0 INVITE\r\n"
                "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
                "Content-Type: application/sdp\r\n"
                "\r\n"
                "v=0\r\n"
                "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
                "s=-\r\n"
                "c=IN IP4 135.180.130.88\r\n"
                "t=0 0\r\n"
                "m=audio 492170 RTP/AVP 0 12\r\n"
                "m=video 3227 RTP/AVP 31\r\n"
                "a=rtpmap:31 LPC\r\n"
                "\r\n");
   auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
   tassert_reset();
   tassert(message->isRequest());
   tassert(!message->isResponse());

   tassert(!message->exists(h_CallId));
   tassert(!message->exists(h_From));
   tassert(!message->exists(h_To));
   tassert_verify(11);
}

void test12()
{
   CritLog( << "2.12 INVITE with Duplicate Required Headers");
   //with duplicate headers that are not multi, the first header is kept
   
   const char* txt = ("INVITE sip:user@company.com SIP/2.0\r\n"
                "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
                "Max-Forwards: 70\r\n"
                "CSeq: 0 INVITE\r\n"
                "Call-ID: 98asdh@10.1.1.1\r\n"
                "Call-ID: 98asdh@10.1.1.2\r\n"
                "From: sip:caller@university.edu;tag=3413415\r\n"
                "From: sip:caller@organization.org\r\n"
                "To: sip:user@company.com\r\n"
                "Content-Type: application/sdp\r\n"
                "\r\n"
                "v=0\r\n"
                "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
                "s=-\r\n"
                "c=IN IP4 135.180.130.88\r\n"
                "t=0 0\r\n"
                "m=audio 492170 RTP/AVP 0 12\r\n"
                "m=video 3227 RTP/AVP 31\r\n"
                "a=rtpmap:31 LPC\r\n"
                "\r\n");
   
   tassert_reset();
   try
   {
      auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
   }
   catch (ParseException& e)
   {
      tassert(0);
   }
   tassert_verify(12);
}


void test13()
{
   CritLog( << "2.13 INVITE with lots of header types");
   //with duplicate headers that are not multi, the first header is kept
   
   const char* txt = ("INVITE sip:user@company.com SIP/2.0\r\n"
                "User-Agent: Lame Agent\r\n"
                "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
                "Max-Forwards: 70\r\n"
                "CSeq: 0 INVITE\r\n"
                "Call-ID: 98asdh@10.1.1.2\r\n"
                "From: sip:caller@university.edu;tag=3413415\r\n"
                "From: sip:caller@organization.org\r\n"
                "To: sip:user@company.com\r\n"
                "Content-Type: application/sdp\r\n"
                "\r\n"
                "v=0\r\n"
                "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
                "s=-\r\n"
                "c=IN IP4 135.180.130.88\r\n"
                "t=0 0\r\n"
                "m=audio 492170 RTP/AVP 0 12\r\n"
                "m=video 3227 RTP/AVP 31\r\n"
                "a=rtpmap:31 LPC\r\n"
                "\r\n");
   
   tassert_reset();
   try
   {
      auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));

       tassert(message->header(h_UserAgent).value() == "Lame Agent"); 
       message->header(h_UserAgent).value() = "Foo";
       tassert(message->header(h_UserAgent).value() == "Foo"); 
   }
   catch (ParseException& e)
   {
      tassert(0);
   }
   tassert_verify(13);
}


void test14()
{
   CritLog( << "2.14 Response with lots of headers");
   
   const char* txt = ("SIP/2.0 200 OK\r\n"
                "To: <sip:fluffy@example.org>;tag=fb86ad2694115d75c77dce61523c9f07.ca6e\r\n"
                "From: <sip:fluffy@example.org>;tag=a1fd\r\n"
                "Via: SIP/2.0/UDP cj14:5002;branch=z9hG4bK-c87542-472987176-1;received=1.2.3.4\r\n"
                "Call-ID: 048cec32\r\n"
                "CSeq: 2 REGISTER\r\n"
                "Contact: <sip:fluffy@1.2.3.4:5002>;q=1.00;expires=1951\r\n"
                "Contact: <sip:fluffy@example.com:5002>;q=0.50;expires=10\r\n"
                "Contact: <sip:floppy@example.com:5002>;q=0.00;expires=100\r\n"
                "Server: The Server\r\n"
                "Content-Length: 0\r\n"
                "Warning: junk junk junk \r\n"
                "\r\n");
   
   tassert_reset();
   try
   {
      auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
      
      tassert(  msg->header(h_Contacts).size() == 3 );
      
      resip::ParserContainer<resip::NameAddr>::iterator i =  msg->header(h_Contacts).begin();
      while ( i != msg->header(h_Contacts).end() )
      {
         DebugLog(<< "i=" << *i  );
         i++;
      }
   }
   catch (ParseException& e)
   {
   }
   tassert_verify(14);
}


void test15()
{
   CritLog( << "2.15 Interesting bodies");
   
   const char* txt = (
    "NOTIFY sip:fluffy@212.157.205.40 SIP/2.0\r\n"
    "Via: SIP/2.0/TCP 212.157.205.198:5060;branch=z9hG4bK2367411811584019109\r\n"
    "To: sip:fluffy@212.157.205.40\r\n"
    "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
    "Max-Forwards: 70\r\n"
    "CSeq: 1 NOTIFY\r\n"
    "Call-ID: 28067261571992032320\r\n"
    "Contact: sip:ntt2@212.157.205.198:5060\r\n"
    "Content-Length: 1929\r\n"
    "Content-Type: multipart/signed;\r\n"
    " protocol=\"application/pkcs7-signature\";\r\n"
    " micalg=sha1; boundary=\"----YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\"\r\n"
    "\r\n"
    "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
    "Content-Type: multipart/mixed;boundary=\"----lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\"\r\n"
    "Content-Length: 870\r\n"
    "Content-Disposition: attachment;handling=required\r\n"
    "\r\n"
    "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
    "Content-Type: application/sipfrag\r\n"
    "Content-Length: 320\r\n"
    "\r\n"
    "To: sip:fluffy@212.157.205.40\r\n"
    "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
    "CSeq: 1 NOTIFY\r\n"
    "Call-ID: 28067261571992032320\r\n"
    "Contact: sip:ntt2@212.157.205.198:5060\r\n"
    "Event: presence\r\n"
    "Content-Length: 210\r\n"
    "Content-Type: application/xpidf+xml\r\n"
    "Subscription-State: active\r\n"
    "User-Agent: NTT SecureSession User-Agent\r\n"
    "\r\n"
    "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
    "Content-Type: application/xpidf+xml\r\n"
    "Content-Length: 210\r\n"
    "\r\n"
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
    "<presence xmlns:impp=\"urn:ietf:params:xml:ns:pidf\" entity=\"pres:someone@example.com\">\r\n"
    "<tuple id=\"765\">\r\n"
    "<status>\r\n"
    "<basic>open</basic>\r\n"
    "</status>\r\n"
    "</tuple>\r\n"
    "</presence>\r\n"
    "\r\n"
    "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY--\r\n"
    "\r\n"
    "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
    "Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\r\n"
    "Content-Transfer-Encoding: base64\r\n"
    "Content-Disposition: attachment; filename=\"smime.p7s\"; handling=required\r\n"
    "\r\n"
    "MIIBVgYJKoZIhvcNAQcCoIIBRzCCAUMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3\r\n"
    "DQEHATGCASIwggEeAgEBMHwwcDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlm\r\n"
    "b3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMQ4wDAYDVQQKEwVzaXBpdDEpMCcGA1UE\r\n"
    "CxMgU2lwaXQgVGVzdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkCCAIWABUCBgIVMAkG\r\n"
    "BSsOAwIaBQAwDQYJKoZIhvcNAQEBBQAEgYAer8TPSMtA3ZqweGnXLUYKR51bp52N\r\n"
    "oGBEqHZz7xR0Nhs6DsAOXiSFv19vTR//33u6Se3zpNNHP/zj7NRr+olimI2PeBNB\r\n"
    "tczNdqexoN0pjRW7l7mHZ0e39pqZmI5bhFl+z9CJJu5xW0aSarw84CZxbh5RQaYr\r\n"
    "zhSvTYdki20aiQ==\r\n"
    "\r\n"
    "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC--\r\n"
      );
   
   tassert_reset();
   try
   {
      auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
      
   }
   catch (ParseException& e)
   {
   }
   tassert_verify(15);
}


int
main(int argc, const char*argv[])
{
    Log::Level l = Log::Debug;
    
    if (argc > 1)
    {
        switch(*argv[1])
        {
            case 'd': l = Log::Debug;
                break;
            case 'i': l = Log::Info;
                break;
            case 's': l = Log::Stack;
                break;
            case 'c': l = Log::Crit;
                break;
        }
    }
    
    Log::initialize(Log::Cout, l, argv[0]);
    CritLog(<<"Test Driver Starting");
    tassert_init(14);
    test1();
    test2();
    test3();
    test4();
    test5();
    test6();
    test7();
    test8();
    test9();
    test10();//this should fail as written
    test11();
    test12();
    test13();
    test14();


    tassert_report();

 CritLog(<<"Test Driver Done");
}

/* ====================================================================
 * 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 + -