reSIProcate/stack  9694
testPlainContents.cxx
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include "config.h"
00003 #endif
00004 
00005 #include "resip/stack/PlainContents.hxx"
00006 
00007 #include <iostream>
00008 #include <fstream>
00009 
00010 using namespace resip;
00011 using namespace std;
00012 
00013 void
00014 setContentsHeaders(Contents& contents)
00015 {
00016     contents.header(h_ContentDisposition).value() = "content-disposition-phrase";
00017     contents.header(h_ContentDescription).value() = "content-description-phrase";
00018     contents.header(h_ContentTransferEncoding).value() = "content-transfer-encoding-phrase";
00019     const char *lang[] = { "en_CA","en_GB","en_US","fr_CA","fr_FR","es_ES.iso88591" };
00020     for(size_t i = 0 ; i < sizeof(lang)/sizeof(*lang); ++i)
00021         contents.header(h_ContentLanguages).push_back(Token(lang[i]));
00022 }
00023 
00024 void
00025 leakCheck(bool verbose)
00026 {
00027 
00028     Data original;
00029     Data alternate;
00030 
00031     { // WIN32 workaround
00032         for (int i = 0 ; i < 100 ; ++i)
00033         {
00034             original += "Original Body by Fischer. -- ";
00035             alternate += "Alternate Body by CheapStandinCo. -- ";
00036         }
00037     }
00038 
00039 #ifndef WIN32
00040 #ifdef RESIP_USE_STL_STREAMS
00041     ofstream devnull("/dev/null");
00042     ostream& os(verbose?cout:devnull);
00043 #else
00044     EncodeStream &os(verbose?resipCout:resipFastNull);
00045 #endif
00046     assert(os.good());
00047 #endif
00048 
00049     for(int i = 0 ; i < 100 ; ++i)
00050     {
00051           Mime type("text", "plain");
00052 
00053           HeaderFieldValue ohfv(original.data(), original.size());
00054           PlainContents originalContents(ohfv, type);
00055           setContentsHeaders(originalContents);
00056 
00057           HeaderFieldValue ahfv(alternate.data(),alternate.size());
00058           PlainContents alternateContents(ahfv, type);
00059           setContentsHeaders(alternateContents);
00060 
00061 #ifndef WIN32
00062           if (verbose && i == 0)
00063           {
00064               originalContents.encodeHeaders(os);
00065               originalContents.encode(os);
00066               os << endl;
00067               alternateContents.encodeHeaders(os);
00068               alternateContents.encode(os);
00069               os << endl;
00070           }
00071 #endif
00072 
00073           // clobber the content-disposition mDisposition variable
00074           alternateContents = originalContents;
00075 
00076 #if 0
00077           alternateContents.encodeHeaders(os);
00078           alternateContents.encode(os);
00079           os << endl;
00080 #endif
00081     }
00082 }
00083 
00084 int
00085 main(int argc, char *argv[])
00086 {
00087    {
00088       const Data txt("some plain text");
00089 
00090       HeaderFieldValue hfv(txt.data(), txt.size());
00091       Mime type("text", "plain");
00092       PlainContents pc(hfv, type);
00093 
00094       cerr << pc.text() << endl;
00095 
00096       assert(pc.text() == "some plain text");
00097    }
00098 
00099    leakCheck(argc > 1);
00100 
00101    cerr << "All OK" << endl;
00102    return 0;
00103 }
00104 
00105 /* ====================================================================
00106  * The Vovida Software License, Version 1.0 
00107  * 
00108  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00109  * 
00110  * Redistribution and use in source and binary forms, with or without
00111  * modification, are permitted provided that the following conditions
00112  * are met:
00113  * 
00114  * 1. Redistributions of source code must retain the above copyright
00115  *    notice, this list of conditions and the following disclaimer.
00116  * 
00117  * 2. Redistributions in binary form must reproduce the above copyright
00118  *    notice, this list of conditions and the following disclaimer in
00119  *    the documentation and/or other materials provided with the
00120  *    distribution.
00121  * 
00122  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00123  *    and "Vovida Open Communication Application Library (VOCAL)" must
00124  *    not be used to endorse or promote products derived from this
00125  *    software without prior written permission. For written
00126  *    permission, please contact vocal@vovida.org.
00127  *
00128  * 4. Products derived from this software may not be called "VOCAL", nor
00129  *    may "VOCAL" appear in their name, without prior written
00130  *    permission of Vovida Networks, Inc.
00131  * 
00132  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00133  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00134  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00135  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00136  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00137  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00138  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00139  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00140  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00141  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00142  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00143  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00144  * DAMAGE.
00145  * 
00146  * ====================================================================
00147  * 
00148  * This software consists of voluntary contributions made by Vovida
00149  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00150  * Inc.  For more information on Vovida Networks, Inc., please see
00151  * <http://www.vovida.org/>.
00152  *
00153  */