~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to resip/stack/test/testMultipartMixedContents.cxx

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <iostream>
 
2
#include <memory>
 
3
 
 
4
#include "resip/stack/MultipartMixedContents.hxx"
 
5
#include "resip/stack/MultipartRelatedContents.hxx"
 
6
#include "resip/stack/PlainContents.hxx"
 
7
#include "resip/stack/SipMessage.hxx"
 
8
#include "resip/stack/test/TestSupport.hxx"
 
9
#include "rutil/ParseBuffer.hxx"
 
10
 
 
11
using namespace resip;
 
12
using namespace std;
 
13
 
 
14
int
 
15
main()
 
16
{
 
17
   {
 
18
      const Data txt("--example-1\r\n"
 
19
                     "Content-Type: text/plain\r\n"
 
20
                     "Content-ID: <1_950120.aaCC@XIson.com>\r\n"
 
21
                     "\r\n"
 
22
                     "25\r\n"
 
23
                     "10\r\n"
 
24
                     "34\r\n"
 
25
                     "10\r\n"
 
26
                     "25\r\n"
 
27
                     "21\r\n"
 
28
                     "26\r\n"
 
29
                     "10\r\n"
 
30
                     "--example-1\r\n"
 
31
                     "Content-Type: text/plain\r\n"
 
32
                     "Content-Description: The fixed length records\r\n"
 
33
                     "Content-Transfer-Encoding: base64\r\n"
 
34
                     "Content-ID: <2_950120.aaCB@XIson.com>\r\n"
 
35
                     "\r\n"
 
36
                     "T2xkIE1hY0RvbmFsZCBoYWQgYSBmYXJtCkUgSS\r\n"
 
37
                     "BFIEkgTwpBbmQgb24gaGlzIGZhcm0gaGUgaGFk\r\n"
 
38
                     "IHNvbWUgZHVja3MKRSBJIEUgSSBPCldpdGggYS\r\n"
 
39
                     "BxdWFjayBxdWFjayBoZXJlLAphIHF1YWNrIHF1\r\n"
 
40
                     "YWNrIHRoZXJlLApldmVyeSB3aGVyZSBhIHF1YW\r\n"
 
41
                     "NrIHF1YWNrCkUgSSBFIEkgTwo=\r\n"
 
42
                     "\r\n"
 
43
                     "--example-1--");
 
44
 
 
45
      // "Content-Type: "
 
46
      const Data contentsTxt = ("Multipart/Related; boundary=example-1\r\n"
 
47
                                "        start=\"<950120.aaCC@XIson.com>\";\r\n"
 
48
                                "        type=\"Application/X-FixedRecord\"\r\n"
 
49
                                "     start-info=\"-o ps\"\r\n");
 
50
 
 
51
      ParseBuffer pb(contentsTxt.data(), contentsTxt.size());
 
52
      Mime contentType;
 
53
      contentType.parse(pb);
 
54
 
 
55
      HeaderFieldValue hfv(txt.data(), txt.size());
 
56
      MultipartRelatedContents mpc(hfv, contentType);
 
57
 
 
58
      assert(mpc.parts().size() == 2);
 
59
 
 
60
      PlainContents *f = dynamic_cast<PlainContents*>(mpc.parts().front());
 
61
      assert(f);
 
62
      f->getBodyData();
 
63
 
 
64
      mpc.encode(resipCerr);
 
65
   }
 
66
 
 
67
   {
 
68
      const Data txt("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
 
69
                     "To: <sip:bob@biloxi.com>\r\n"
 
70
                     "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
 
71
                     "Call-ID: 314159\r\n"
 
72
                     "CSeq: 14 INVITE\r\n"
 
73
                     "Content-Type: Multipart/Related; boundary=example-1;"
 
74
                     "start=\"<950120.aaCC@XIson.com>\";"
 
75
                     "type=\"Application/X-FixedRecord\";start-info=\"-o ps\"\r\n"
 
76
                     "\r\n"
 
77
                     "--example-1\r\n"
 
78
                     "Content-Type: text/plain\r\n"
 
79
                     "Content-ID: <1_950120.aaCC@XIson.com>\r\n"
 
80
                     "\r\n"
 
81
                     "25\r\n"
 
82
                     "10\r\n"
 
83
                     "34\r\n"
 
84
                     "10\r\n"
 
85
                     "25\r\n"
 
86
                     "21\r\n"
 
87
                     "26\r\n"
 
88
                     "10\r\n"
 
89
                     "--example-1\r\n"
 
90
                     "Content-Type: text/plain\r\n"
 
91
                     "Content-Description: The fixed length records\r\n"
 
92
                     "Content-Transfer-Encoding: base64\r\n"
 
93
                     "Content-ID: <2_950120.aaCB@XIson.com>\r\n"
 
94
                     "\r\n"
 
95
                     "T2xkIE1hY0RvbmFsZCBoYWQgYSBmYXJtCkUgSS\r\n"
 
96
                     "BFIEkgTwpBbmQgb24gaGlzIGZhcm0gaGUgaGFk\r\n"
 
97
                     "IHNvbWUgZHVja3MKRSBJIEUgSSBPCldpdGggYS\r\n"
 
98
                     "BxdWFjayBxdWFjayBoZXJlLAphIHF1YWNrIHF1\r\n"
 
99
                     "YWNrIHRoZXJlLApldmVyeSB3aGVyZSBhIHF1YW\r\n"
 
100
                     "NrIHF1YWNrCkUgSSBFIEkgTwo=\r\n"
 
101
                     "\r\n"
 
102
                     "--example-1--");
 
103
 
 
104
      auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
 
105
 
 
106
      MultipartRelatedContents* mpc = dynamic_cast<MultipartRelatedContents*>(msg->getContents());
 
107
      assert(mpc);
 
108
      assert(mpc->parts().size() == 2);
 
109
      PlainContents *f11 = dynamic_cast<PlainContents*>(mpc->parts().front());
 
110
      assert(f11);
 
111
      f11->getBodyData();
 
112
      MultipartRelatedContents::Parts::const_iterator i = mpc->parts().begin(); i++;
 
113
      PlainContents *f12 = dynamic_cast<PlainContents*>(*i);
 
114
      assert(f12);
 
115
      f12->getBodyData();
 
116
 
 
117
      Data buff;
 
118
      {
 
119
         DataStream str(buff);
 
120
         str << *msg;
 
121
      }
 
122
 
 
123
      {      
 
124
         auto_ptr<SipMessage> msg1(TestSupport::makeMessage(buff.c_str()));
 
125
         MultipartRelatedContents* mpc = dynamic_cast<MultipartRelatedContents*>(msg->getContents());
 
126
         assert(mpc);
 
127
         assert(mpc->parts().size() == 2);
 
128
         PlainContents *f21 = dynamic_cast<PlainContents*>(mpc->parts().front());
 
129
         assert(f21);
 
130
         f21->getBodyData();
 
131
         MultipartRelatedContents::Parts::const_iterator i = mpc->parts().begin(); i++;
 
132
         PlainContents *f22 = dynamic_cast<PlainContents*>(*i);
 
133
         assert(f22);
 
134
         f22->getBodyData();
 
135
 
 
136
         assert(f11->getBodyData() == f21->getBodyData());
 
137
         assert(f12->getBodyData() == f22->getBodyData());
 
138
      }
 
139
   }
 
140
 
 
141
   cerr << endl << "All OK" << endl;
 
142
   return 0;
 
143
}
 
144
 
 
145
/* ====================================================================
 
146
 * The Vovida Software License, Version 1.0 
 
147
 * 
 
148
 * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
 
149
 * 
 
150
 * Redistribution and use in source and binary forms, with or without
 
151
 * modification, are permitted provided that the following conditions
 
152
 * are met:
 
153
 * 
 
154
 * 1. Redistributions of source code must retain the above copyright
 
155
 *    notice, this list of conditions and the following disclaimer.
 
156
 * 
 
157
 * 2. Redistributions in binary form must reproduce the above copyright
 
158
 *    notice, this list of conditions and the following disclaimer in
 
159
 *    the documentation and/or other materials provided with the
 
160
 *    distribution.
 
161
 * 
 
162
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
 
163
 *    and "Vovida Open Communication Application Library (VOCAL)" must
 
164
 *    not be used to endorse or promote products derived from this
 
165
 *    software without prior written permission. For written
 
166
 *    permission, please contact vocal@vovida.org.
 
167
 *
 
168
 * 4. Products derived from this software may not be called "VOCAL", nor
 
169
 *    may "VOCAL" appear in their name, without prior written
 
170
 *    permission of Vovida Networks, Inc.
 
171
 * 
 
172
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
 
173
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
174
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
 
175
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
 
176
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
 
177
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
 
178
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
179
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
180
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
181
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
182
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 
183
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 
184
 * DAMAGE.
 
185
 * 
 
186
 * ====================================================================
 
187
 * 
 
188
 * This software consists of voluntary contributions made by Vovida
 
189
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
 
190
 * Inc.  For more information on Vovida Networks, Inc., please see
 
191
 * <http://www.vovida.org/>.
 
192
 *
 
193
 */