/[resiprocate]/main/resip/stack/test/testPlainContents.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testPlainContents.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9493 - (show annotations) (download)
Sat Apr 7 10:56:50 2012 UTC (7 years, 7 months ago) by dpocock
File MIME type: text/plain
File size: 4926 byte(s)
Include config.h from even more places where it may be needed
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include "resip/stack/PlainContents.hxx"
6
7 #include <iostream>
8 #include <fstream>
9
10 using namespace resip;
11 using namespace std;
12
13 void
14 setContentsHeaders(Contents& contents)
15 {
16 contents.header(h_ContentDisposition).value() = "content-disposition-phrase";
17 contents.header(h_ContentDescription).value() = "content-description-phrase";
18 contents.header(h_ContentTransferEncoding).value() = "content-transfer-encoding-phrase";
19 const char *lang[] = { "en_CA","en_GB","en_US","fr_CA","fr_FR","es_ES.iso88591" };
20 for(size_t i = 0 ; i < sizeof(lang)/sizeof(*lang); ++i)
21 contents.header(h_ContentLanguages).push_back(Token(lang[i]));
22 }
23
24 void
25 leakCheck(bool verbose)
26 {
27
28 Data original;
29 Data alternate;
30
31 { // WIN32 workaround
32 for (int i = 0 ; i < 100 ; ++i)
33 {
34 original += "Original Body by Fischer. -- ";
35 alternate += "Alternate Body by CheapStandinCo. -- ";
36 }
37 }
38
39 #ifndef WIN32
40 #ifdef RESIP_USE_STL_STREAMS
41 ofstream devnull("/dev/null");
42 ostream& os(verbose?cout:devnull);
43 #else
44 EncodeStream &os(verbose?resipCout:resipFastNull);
45 #endif
46 assert(os.good());
47 #endif
48
49 for(int i = 0 ; i < 100 ; ++i)
50 {
51 Mime type("text", "plain");
52
53 HeaderFieldValue ohfv(original.data(), original.size());
54 PlainContents originalContents(ohfv, type);
55 setContentsHeaders(originalContents);
56
57 HeaderFieldValue ahfv(alternate.data(),alternate.size());
58 PlainContents alternateContents(ahfv, type);
59 setContentsHeaders(alternateContents);
60
61 #ifndef WIN32
62 if (verbose && i == 0)
63 {
64 originalContents.encodeHeaders(os);
65 originalContents.encode(os);
66 os << endl;
67 alternateContents.encodeHeaders(os);
68 alternateContents.encode(os);
69 os << endl;
70 }
71 #endif
72
73 // clobber the content-disposition mDisposition variable
74 alternateContents = originalContents;
75
76 #if 0
77 alternateContents.encodeHeaders(os);
78 alternateContents.encode(os);
79 os << endl;
80 #endif
81 }
82 }
83
84 int
85 main(int argc, char *argv[])
86 {
87 {
88 const Data txt("some plain text");
89
90 HeaderFieldValue hfv(txt.data(), txt.size());
91 Mime type("text", "plain");
92 PlainContents pc(hfv, type);
93
94 cerr << pc.text() << endl;
95
96 assert(pc.text() == "some plain text");
97 }
98
99 leakCheck(argc > 1);
100
101 cerr << "All OK" << endl;
102 return 0;
103 }
104
105 /* ====================================================================
106 * The Vovida Software License, Version 1.0
107 *
108 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
109 *
110 * Redistribution and use in source and binary forms, with or without
111 * modification, are permitted provided that the following conditions
112 * are met:
113 *
114 * 1. Redistributions of source code must retain the above copyright
115 * notice, this list of conditions and the following disclaimer.
116 *
117 * 2. Redistributions in binary form must reproduce the above copyright
118 * notice, this list of conditions and the following disclaimer in
119 * the documentation and/or other materials provided with the
120 * distribution.
121 *
122 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
123 * and "Vovida Open Communication Application Library (VOCAL)" must
124 * not be used to endorse or promote products derived from this
125 * software without prior written permission. For written
126 * permission, please contact vocal@vovida.org.
127 *
128 * 4. Products derived from this software may not be called "VOCAL", nor
129 * may "VOCAL" appear in their name, without prior written
130 * permission of Vovida Networks, Inc.
131 *
132 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
133 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
134 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
135 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
136 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
137 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
138 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
139 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
140 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
141 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
142 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
143 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
144 * DAMAGE.
145 *
146 * ====================================================================
147 *
148 * This software consists of voluntary contributions made by Vovida
149 * Networks, Inc. and many individuals on behalf of Vovida Networks,
150 * Inc. For more information on Vovida Networks, Inc., please see
151 * <http://www.vovida.org/>.
152 *
153 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27