reSIProcate/stack  9694
testMultipartMixedContents.cxx
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <memory>
00003 
00004 #include "resip/stack/MultipartMixedContents.hxx"
00005 #include "resip/stack/MultipartRelatedContents.hxx"
00006 #include "resip/stack/PlainContents.hxx"
00007 #include "resip/stack/SipMessage.hxx"
00008 #include "resip/stack/test/TestSupport.hxx"
00009 #include "rutil/ParseBuffer.hxx"
00010 
00011 using namespace resip;
00012 using namespace std;
00013 
00014 int
00015 main()
00016 {
00017    {
00018       const Data txt("--example-1\r\n"
00019                      "Content-Type: text/plain\r\n"
00020                      "Content-ID: <1_950120.aaCC@XIson.com>\r\n"
00021                      "\r\n"
00022                      "25\r\n"
00023                      "10\r\n"
00024                      "34\r\n"
00025                      "10\r\n"
00026                      "25\r\n"
00027                      "21\r\n"
00028                      "26\r\n"
00029                      "10\r\n"
00030                      "--example-1\r\n"
00031                      "Content-Type: text/plain\r\n"
00032                      "Content-Description: The fixed length records\r\n"
00033                      "Content-Transfer-Encoding: base64\r\n"
00034                      "Content-ID: <2_950120.aaCB@XIson.com>\r\n"
00035                      "\r\n"
00036                      "T2xkIE1hY0RvbmFsZCBoYWQgYSBmYXJtCkUgSS\r\n"
00037                      "BFIEkgTwpBbmQgb24gaGlzIGZhcm0gaGUgaGFk\r\n"
00038                      "IHNvbWUgZHVja3MKRSBJIEUgSSBPCldpdGggYS\r\n"
00039                      "BxdWFjayBxdWFjayBoZXJlLAphIHF1YWNrIHF1\r\n"
00040                      "YWNrIHRoZXJlLApldmVyeSB3aGVyZSBhIHF1YW\r\n"
00041                      "NrIHF1YWNrCkUgSSBFIEkgTwo=\r\n"
00042                      "\r\n"
00043                      "--example-1--");
00044 
00045       // "Content-Type: "
00046       const Data contentsTxt = ("Multipart/Related; boundary=example-1\r\n"
00047                                 "        start=\"<950120.aaCC@XIson.com>\";\r\n"
00048                                 "        type=\"Application/X-FixedRecord\"\r\n"
00049                                 "     start-info=\"-o ps\"\r\n");
00050 
00051       ParseBuffer pb(contentsTxt.data(), contentsTxt.size());
00052       Mime contentType;
00053       contentType.parse(pb);
00054 
00055       HeaderFieldValue hfv(txt.data(), txt.size());
00056       MultipartRelatedContents mpc(hfv, contentType);
00057 
00058       assert(mpc.parts().size() == 2);
00059 
00060       PlainContents *f = dynamic_cast<PlainContents*>(mpc.parts().front());
00061       assert(f);
00062       f->getBodyData();
00063 
00064       mpc.encode(resipCerr);
00065    }
00066 
00067    {
00068       const Data txt("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
00069                      "To: <sip:bob@biloxi.com>\r\n"
00070                      "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
00071                      "Call-ID: 314159\r\n"
00072                      "CSeq: 14 INVITE\r\n"
00073                      "Content-Type: Multipart/Related; boundary=example-1;"
00074                      "start=\"<950120.aaCC@XIson.com>\";"
00075                      "type=\"Application/X-FixedRecord\";start-info=\"-o ps\"\r\n"
00076                      "\r\n"
00077                      "--example-1\r\n"
00078                      "Content-Type: text/plain\r\n"
00079                      "Content-ID: <1_950120.aaCC@XIson.com>\r\n"
00080                      "\r\n"
00081                      "25\r\n"
00082                      "10\r\n"
00083                      "34\r\n"
00084                      "10\r\n"
00085                      "25\r\n"
00086                      "21\r\n"
00087                      "26\r\n"
00088                      "10\r\n"
00089                      "--example-1\r\n"
00090                      "Content-Type: text/plain\r\n"
00091                      "Content-Description: The fixed length records\r\n"
00092                      "Content-Transfer-Encoding: base64\r\n"
00093                      "Content-ID: <2_950120.aaCB@XIson.com>\r\n"
00094                      "\r\n"
00095                      "T2xkIE1hY0RvbmFsZCBoYWQgYSBmYXJtCkUgSS\r\n"
00096                      "BFIEkgTwpBbmQgb24gaGlzIGZhcm0gaGUgaGFk\r\n"
00097                      "IHNvbWUgZHVja3MKRSBJIEUgSSBPCldpdGggYS\r\n"
00098                      "BxdWFjayBxdWFjayBoZXJlLAphIHF1YWNrIHF1\r\n"
00099                      "YWNrIHRoZXJlLApldmVyeSB3aGVyZSBhIHF1YW\r\n"
00100                      "NrIHF1YWNrCkUgSSBFIEkgTwo=\r\n"
00101                      "\r\n"
00102                      "--example-1--");
00103 
00104       auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
00105 
00106       MultipartRelatedContents* mpc = dynamic_cast<MultipartRelatedContents*>(msg->getContents());
00107       assert(mpc);
00108       assert(mpc->parts().size() == 2);
00109       PlainContents *f11 = dynamic_cast<PlainContents*>(mpc->parts().front());
00110       assert(f11);
00111       f11->getBodyData();
00112       MultipartRelatedContents::Parts::const_iterator i = mpc->parts().begin(); i++;
00113       PlainContents *f12 = dynamic_cast<PlainContents*>(*i);
00114       assert(f12);
00115       f12->getBodyData();
00116 
00117       Data buff;
00118       {
00119          DataStream str(buff);
00120          str << *msg;
00121       }
00122 
00123       {      
00124          auto_ptr<SipMessage> msg1(TestSupport::makeMessage(buff.c_str()));
00125          MultipartRelatedContents* mpc = dynamic_cast<MultipartRelatedContents*>(msg->getContents());
00126          assert(mpc);
00127          assert(mpc->parts().size() == 2);
00128          PlainContents *f21 = dynamic_cast<PlainContents*>(mpc->parts().front());
00129          assert(f21);
00130          f21->getBodyData();
00131          MultipartRelatedContents::Parts::const_iterator i = mpc->parts().begin(); i++;
00132          PlainContents *f22 = dynamic_cast<PlainContents*>(*i);
00133          assert(f22);
00134          f22->getBodyData();
00135 
00136          assert(f11->getBodyData() == f21->getBodyData());
00137          assert(f12->getBodyData() == f22->getBodyData());
00138       }
00139    }
00140 
00141    cerr << endl << "All OK" << endl;
00142    return 0;
00143 }
00144 
00145 /* ====================================================================
00146  * The Vovida Software License, Version 1.0 
00147  * 
00148  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00149  * 
00150  * Redistribution and use in source and binary forms, with or without
00151  * modification, are permitted provided that the following conditions
00152  * are met:
00153  * 
00154  * 1. Redistributions of source code must retain the above copyright
00155  *    notice, this list of conditions and the following disclaimer.
00156  * 
00157  * 2. Redistributions in binary form must reproduce the above copyright
00158  *    notice, this list of conditions and the following disclaimer in
00159  *    the documentation and/or other materials provided with the
00160  *    distribution.
00161  * 
00162  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00163  *    and "Vovida Open Communication Application Library (VOCAL)" must
00164  *    not be used to endorse or promote products derived from this
00165  *    software without prior written permission. For written
00166  *    permission, please contact vocal@vovida.org.
00167  *
00168  * 4. Products derived from this software may not be called "VOCAL", nor
00169  *    may "VOCAL" appear in their name, without prior written
00170  *    permission of Vovida Networks, Inc.
00171  * 
00172  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00173  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00174  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00175  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00176  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00177  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00178  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00179  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00180  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00181  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00182  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00183  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00184  * DAMAGE.
00185  * 
00186  * ====================================================================
00187  * 
00188  * This software consists of voluntary contributions made by Vovida
00189  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00190  * Inc.  For more information on Vovida Networks, Inc., please see
00191  * <http://www.vovida.org/>.
00192  *
00193  */