~ubuntu-branches/ubuntu/trusty/libcmis/trusty

« back to all changes in this revision

Viewing changes to qa/libcmis/test-soap.cxx

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2014-02-05 14:41:34 UTC
  • mfrom: (1.1.5) (2.1.6 experimental)
  • Revision ID: package-import@ubuntu.com-20140205144134-ffvov1moblfapn82
Tags: 0.4.1-3ubuntu1
* Resynchronize on Debian, remaining change:
* debian/patches/powerpc64le.diff: build on ppc64el

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libcmis
 
2
 * Version: MPL 1.1 / GPLv2+ / LGPLv2+
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public License Version
 
5
 * 1.1 (the "License"); you may not use this file except in compliance with
 
6
 * the License or as specified alternatively below. You may obtain a copy of
 
7
 * the License at http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS IS" basis,
 
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
 * for the specific language governing rights and limitations under the
 
12
 * License.
 
13
 *
 
14
 * Major Contributor(s):
 
15
 * Copyright (C) 2011 SUSE <cbosdonnat@suse.com>
 
16
 *
 
17
 *
 
18
 * All Rights Reserved.
 
19
 *
 
20
 * For minor contributions see the git repository.
 
21
 *
 
22
 * Alternatively, the contents of this file may be used under the terms of
 
23
 * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
 
24
 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
 
25
 * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
 
26
 * instead of those above.
 
27
 */
 
28
 
 
29
#include <cppunit/extensions/HelperMacros.h>
 
30
#include <cppunit/TestFixture.h>
 
31
#include <cppunit/TestAssert.h>
 
32
#include <cppunit/ui/text/TestRunner.h>
 
33
 
 
34
#include "ws-relatedmultipart.hxx"
 
35
#include "ws-requests.hxx"
 
36
#include "ws-soap.hxx"
 
37
#include "test-helpers.hxx"
 
38
 
 
39
using namespace std;
 
40
 
 
41
class SoapTest : public CppUnit::TestFixture
 
42
{
 
43
    private:
 
44
        map< string, SoapResponseCreator > getTestMapping( );
 
45
        map< string, string > getTestNamespaces( );
 
46
        map< string, SoapFaultDetailCreator > getTestDetailMapping( );
 
47
 
 
48
    public:
 
49
 
 
50
        // Soap Responses tests
 
51
 
 
52
        void createResponseTest( );
 
53
        void parseFaultDetailEmptyTest( );
 
54
        void parseFaultDetailUnknownTest( );
 
55
        void parseFaultDetailValidTest( );
 
56
        void createFaultDefaultTest( );
 
57
        void parseResponseTest( );
 
58
        void parseResponseFaultTest( );
 
59
 
 
60
        // RelatedMultipart tests
 
61
 
 
62
        void serializeMultipartSimpleTest( );
 
63
        void serializeMultipartComplexTest( );
 
64
        void parseMultipartTest( );
 
65
        void getStreamFromNodeXopTest( );
 
66
        void getStreamFromNodeBase64Test( );
 
67
 
 
68
        // CMISM utilities tests
 
69
        void writeCmismStreamTest( );
 
70
 
 
71
        CPPUNIT_TEST_SUITE( SoapTest );
 
72
        CPPUNIT_TEST( createResponseTest );
 
73
        CPPUNIT_TEST( parseFaultDetailEmptyTest );
 
74
        CPPUNIT_TEST( parseFaultDetailUnknownTest );
 
75
        CPPUNIT_TEST( parseFaultDetailValidTest );
 
76
        CPPUNIT_TEST( parseResponseTest );
 
77
        CPPUNIT_TEST( parseResponseFaultTest );
 
78
 
 
79
        CPPUNIT_TEST( serializeMultipartSimpleTest );
 
80
        CPPUNIT_TEST( serializeMultipartComplexTest );
 
81
        CPPUNIT_TEST( parseMultipartTest );
 
82
        CPPUNIT_TEST( getStreamFromNodeXopTest );
 
83
        CPPUNIT_TEST( getStreamFromNodeBase64Test );
 
84
 
 
85
        CPPUNIT_TEST( writeCmismStreamTest );
 
86
 
 
87
        CPPUNIT_TEST_SUITE_END( );
 
88
};
 
89
 
 
90
CPPUNIT_TEST_SUITE_REGISTRATION( SoapTest );
 
91
 
 
92
/** Dummy response class to use for testing
 
93
  */
 
94
class TestResponse : public SoapResponse
 
95
{
 
96
    private:
 
97
        TestResponse( ) { };
 
98
 
 
99
    public:
 
100
 
 
101
        static SoapResponsePtr create( xmlNodePtr, RelatedMultipart&, SoapSession* )
 
102
        {
 
103
            SoapResponsePtr resp ( new TestResponse( ) );
 
104
            return resp;
 
105
        }
 
106
};
 
107
 
 
108
class TestFaultDetail : public SoapFaultDetail
 
109
{
 
110
    private:
 
111
        TestFaultDetail( ) : SoapFaultDetail( ) { };
 
112
 
 
113
    public:
 
114
        ~TestFaultDetail( ) throw ( ) { };
 
115
 
 
116
        static SoapFaultDetailPtr create( xmlNodePtr )
 
117
        {
 
118
            return SoapFaultDetailPtr( new TestFaultDetail( ) );
 
119
        }
 
120
};
 
121
 
 
122
map< string, SoapResponseCreator > SoapTest::getTestMapping( )
 
123
{
 
124
    map< string, SoapResponseCreator > mapping;
 
125
    mapping[ "{test-ns-url}testResponse" ] = &TestResponse::create;
 
126
    return mapping;
 
127
}
 
128
 
 
129
map< string, SoapFaultDetailCreator > SoapTest::getTestDetailMapping( )
 
130
{
 
131
    map< string, SoapFaultDetailCreator > mapping;
 
132
    mapping[ "{test-ns-url}testFault" ] = &TestFaultDetail::create;
 
133
    return mapping;
 
134
}
 
135
 
 
136
map< string, string > SoapTest::getTestNamespaces( )
 
137
{
 
138
    map< string, string > namespaces;
 
139
    namespaces[ "test" ] = "test-ns-url";
 
140
    return namespaces;
 
141
}
 
142
 
 
143
void SoapTest::createResponseTest( )
 
144
{
 
145
    SoapResponseFactory factory;
 
146
    factory.setMapping( getTestMapping() );
 
147
    factory.setNamespaces( getTestNamespaces( ) );
 
148
    factory.setDetailMapping( getTestDetailMapping( ) );
 
149
 
 
150
    string xml = "<n1:testResponse xmlns:n1=\"test-ns-url\"/>";
 
151
    RelatedMultipart multipart; // Multipart won't be used in that test
 
152
 
 
153
    SoapResponsePtr actual = factory.createResponse( test::getXmlNode( xml ), multipart );
 
154
    CPPUNIT_ASSERT_MESSAGE( "Wrong response created", dynamic_cast< TestResponse* >( actual.get( ) ) != NULL );
 
155
}
 
156
 
 
157
void SoapTest::parseFaultDetailEmptyTest( )
 
158
{
 
159
    SoapResponseFactory factory;
 
160
    factory.setMapping( getTestMapping() );
 
161
    factory.setNamespaces( getTestNamespaces( ) );
 
162
    factory.setDetailMapping( getTestDetailMapping( ) );
 
163
 
 
164
    string xml = "<detail/>";
 
165
 
 
166
    vector< SoapFaultDetailPtr > actual = factory.parseFaultDetail( test::getXmlNode( xml ) );
 
167
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shouldn't have any detail", size_t( 0 ), actual.size() );
 
168
}
 
169
 
 
170
void SoapTest::parseFaultDetailUnknownTest( )
 
171
{
 
172
    SoapResponseFactory factory;
 
173
    factory.setMapping( getTestMapping() );
 
174
    factory.setNamespaces( getTestNamespaces( ) );
 
175
    factory.setDetailMapping( getTestDetailMapping( ) );
 
176
 
 
177
    string xml = "<detail><unknown-detail/></detail>";
 
178
 
 
179
    vector< SoapFaultDetailPtr > actual = factory.parseFaultDetail( test::getXmlNode( xml ) );
 
180
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shouldn't have ignored unknonw details", size_t( 0 ), actual.size() );
 
181
}
 
182
void SoapTest::parseFaultDetailValidTest( )
 
183
{
 
184
    SoapResponseFactory factory;
 
185
    factory.setMapping( getTestMapping() );
 
186
    factory.setNamespaces( getTestNamespaces( ) );
 
187
    factory.setDetailMapping( getTestDetailMapping( ) );
 
188
 
 
189
    string xml = "<detail><n1:testFault xmlns:n1=\"test-ns-url\"/></detail>";
 
190
 
 
191
    vector< SoapFaultDetailPtr > actual = factory.parseFaultDetail( test::getXmlNode( xml ) );
 
192
    CPPUNIT_ASSERT_MESSAGE( "Wrong fault detail created",
 
193
            dynamic_cast< TestFaultDetail* >( actual.front( ).get( ) ) != NULL );
 
194
}
 
195
 
 
196
void SoapTest::parseResponseTest( )
 
197
{
 
198
    SoapResponseFactory factory;
 
199
    factory.setMapping( getTestMapping() );
 
200
    factory.setNamespaces( getTestNamespaces( ) );
 
201
    factory.setDetailMapping( getTestDetailMapping( ) );
 
202
 
 
203
    string xml = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body>"
 
204
                 "<test:testResponse xmlns:test=\"test-ns-url\"/>"
 
205
                 "<test:testResponse xmlns:test=\"test-ns-url\"/>"
 
206
                 "</S:Body></S:Envelope>";
 
207
    string name( "name" );
 
208
    string type( "application/xop+xml" );
 
209
    RelatedPartPtr requestPart( new RelatedPart( name, type, xml ) );
 
210
 
 
211
    RelatedMultipart multipart;
 
212
    string cid = multipart.addPart( requestPart );
 
213
    string startInfo( "text/xml" );
 
214
    multipart.setStart( cid, startInfo );
 
215
 
 
216
    vector< SoapResponsePtr > actual = factory.parseResponse( multipart );
 
217
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong number of responses", size_t( 2 ), actual.size( ) );
 
218
}
 
219
 
 
220
void SoapTest::parseResponseFaultTest( )
 
221
{
 
222
    SoapResponseFactory factory;
 
223
    factory.setMapping( getTestMapping() );
 
224
    factory.setNamespaces( getTestNamespaces( ) );
 
225
    factory.setDetailMapping( getTestDetailMapping( ) );
 
226
 
 
227
    string xml = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\""
 
228
                 "            xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\""
 
229
                 "            xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">"
 
230
                 "  <S:Body><S:Fault>"
 
231
                 "      <faultcode xsi:type=\"xsd:string\">S:Client</faultcode>"
 
232
                 "      <faultstring xsi:type=\"xsd:string\">Some Error Message</faultstring>"
 
233
                 "      <detail><n1:testFault xmlns:n1=\"test-ns-url\"/></detail>"
 
234
                 "  </S:Fault></S:Body>"
 
235
                 "</S:Envelope>";
 
236
 
 
237
    string name( "name" );
 
238
    string type( "application/xop+xml" );
 
239
    RelatedPartPtr requestPart( new RelatedPart( name, type, xml ) );
 
240
 
 
241
    RelatedMultipart multipart;
 
242
    string cid = multipart.addPart( requestPart );
 
243
    string startInfo( "text/xml" );
 
244
    multipart.setStart( cid, startInfo );
 
245
   
 
246
    try
 
247
    {
 
248
        factory.parseResponse( multipart );
 
249
        CPPUNIT_FAIL( "Should have thrown the SoapFault" );
 
250
    }
 
251
    catch ( const SoapFault& e )
 
252
    {
 
253
        CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong detail string", string( "Some Error Message" ), e.getFaultstring() );
 
254
        CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong detail string", string( "Client" ), e.getFaultcode() );
 
255
        CPPUNIT_ASSERT_MESSAGE( "Wrong fault detail created",
 
256
                dynamic_cast< TestFaultDetail* >( e.getDetail( ).front( ).get( ) ) != NULL );
 
257
    }
 
258
}
 
259
 
 
260
void SoapTest::serializeMultipartSimpleTest( )
 
261
{
 
262
    string partName = "data";
 
263
    string partType = "text/plain";
 
264
    string partContent = "Some content";
 
265
    string startInfo = "some info";
 
266
 
 
267
 
 
268
    RelatedMultipart multipart;
 
269
    RelatedPartPtr part( new RelatedPart( partName, partType, partContent ) );
 
270
    string cid = multipart.addPart( part );
 
271
    multipart.setStart( cid, startInfo );
 
272
 
 
273
    boost::shared_ptr< istringstream > actual = multipart.toStream( );
 
274
 
 
275
    string boundary = multipart.getBoundary( );
 
276
    string expected = "\r\n--" + boundary + "\r\n" +
 
277
                      "Content-Id: <" + cid + ">\r\n" +
 
278
                      "Content-Type: " + partType + "\r\n" +
 
279
                      "Content-Transfer-Encoding: binary\r\n" +
 
280
                      "\r\n" +
 
281
                      partContent +
 
282
                      "\r\n--" + boundary + "--\r\n";
 
283
 
 
284
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong body", expected, actual->str() );
 
285
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong content type",
 
286
            "multipart/related;start=\"" + cid + "\";type=\"" + partType + "\";boundary=\"" + boundary + "\";start-info=\"" + startInfo + "\"",
 
287
            multipart.getContentType() );
 
288
}
 
289
 
 
290
void SoapTest::serializeMultipartComplexTest( )
 
291
{
 
292
    string rootName = "root";
 
293
    string rootType = "text/plain";
 
294
    string rootContent = "Some content";
 
295
 
 
296
    string part2Name = "part2";
 
297
    string part2Type = "application/octet-stream";
 
298
    string part2Content = "Some content 2";
 
299
    
 
300
    string startInfo = "some info";
 
301
 
 
302
 
 
303
    RelatedMultipart multipart;
 
304
    RelatedPartPtr rootPart( new RelatedPart( rootName, rootType, rootContent ) );
 
305
    string rootCid = multipart.addPart( rootPart );
 
306
 
 
307
    RelatedPartPtr part2( new RelatedPart( part2Name, part2Type, part2Content ) );
 
308
    string part2Cid = multipart.addPart( part2 );
 
309
    
 
310
    multipart.setStart( rootCid, startInfo );
 
311
 
 
312
    boost::shared_ptr< istringstream > actual = multipart.toStream( );
 
313
 
 
314
    string boundary = multipart.getBoundary( );
 
315
    string expected = "\r\n--" + boundary + "\r\n" +
 
316
                      "Content-Id: <" + rootCid + ">\r\n" +
 
317
                      "Content-Type: " + rootType + "\r\n" +
 
318
                      "Content-Transfer-Encoding: binary\r\n" +
 
319
                      "\r\n" +
 
320
                      rootContent +
 
321
                      "\r\n--" + boundary + "\r\n" +
 
322
                      "Content-Id: <" + part2Cid + ">\r\n" +
 
323
                      "Content-Type: " + part2Type + "\r\n" +
 
324
                      "Content-Transfer-Encoding: binary\r\n" +
 
325
                      "\r\n" +
 
326
                      part2Content +
 
327
                      "\r\n--" + boundary + "--\r\n";
 
328
 
 
329
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong body", expected, actual->str() );
 
330
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong content type",
 
331
            "multipart/related;start=\"" + rootCid + "\";type=\"" + rootType + "\";boundary=\"" + boundary + "\";start-info=\"" + startInfo + "\"",
 
332
            multipart.getContentType() );
 
333
}
 
334
 
 
335
void SoapTest::parseMultipartTest( )
 
336
{
 
337
    string rootCid = "root-cid";
 
338
    string rootType = "text/plain";
 
339
    string rootContent = "Some content";
 
340
 
 
341
    string part2Cid = "part2-cid";
 
342
    string part2Type = "application/octet-stream";
 
343
    string part2Content = "Some content 2";
 
344
    
 
345
    string startInfo = "some info";
 
346
 
 
347
    string boundary = "------------ABCDEF-Boundary";
 
348
    string body = "\r\n--" + boundary + "\r\n" +
 
349
                  "Content-Id: <" + rootCid + ">\r\n" +
 
350
                  "Content-Type: " + rootType + "\r\n" +
 
351
                  "Content-Transfer-Encoding: binary\r\n" +
 
352
                  "\r\n" +
 
353
                  rootContent +
 
354
                  "\r\n--" + boundary + "\r\n" +
 
355
                  // Voluntarily make a case-sensitivity error to test the SharePoint case
 
356
                  "Content-ID: <" + part2Cid + ">\r\n" +
 
357
                  "Content-Type: " + part2Type + "\r\n" +
 
358
                  "Content-Transfer-Encoding: binary\r\n" +
 
359
                  "\r\n" +
 
360
                  part2Content +
 
361
                  "\r\n--" + boundary + "--\r\n";
 
362
 
 
363
    // Added a space before one of the items as it may happen 
 
364
    string contentType = "multipart/related; start=\"" + rootCid + "\";type=\"" + rootType + "\";" +
 
365
                         "boundary=\"" + boundary + "\";start-info=\"" + startInfo + "\"";
 
366
 
 
367
    RelatedMultipart multipart( body, contentType );
 
368
 
 
369
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong start Content id", rootCid, multipart.getStartId( ) );
 
370
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong start info", startInfo, multipart.getStartInfo( ) );
 
371
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong boundary", boundary, multipart.getBoundary( ) );
 
372
 
 
373
    vector< string > cids = multipart.getIds( );
 
374
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong number of parts parsed", size_t( 2 ), cids.size( ) );
 
375
 
 
376
    RelatedPartPtr actualRoot = multipart.getPart( rootCid );
 
377
    CPPUNIT_ASSERT_MESSAGE( "No part corresponding to root cid", actualRoot.get( ) != NULL );
 
378
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong root part content type", rootType, actualRoot->getContentType( ) );
 
379
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong root part content", rootContent, actualRoot->getContent( ) );
 
380
    
 
381
    RelatedPartPtr actualPart2 = multipart.getPart( part2Cid );
 
382
    CPPUNIT_ASSERT_MESSAGE( "No part corresponding to part2 cid", actualPart2.get( ) != NULL );
 
383
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong part2 part content type", part2Type, actualPart2->getContentType( ) );
 
384
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong part2 part content", part2Content, actualPart2->getContent( ) );
 
385
}
 
386
 
 
387
void SoapTest::getStreamFromNodeXopTest( )
 
388
{
 
389
    // Create the test multipart
 
390
    string dataCid = "http://data-cid";
 
391
    string dataCidEncoded = "http%3A%2F%2Fdata-cid";
 
392
    string dataContent = "Some transfered content";
 
393
    
 
394
    string boundary = "------------ABCDEF-Boundary";
 
395
    string body = "\r\n--" + boundary + "\r\n" +
 
396
                  "Content-Id: <root-cid>\r\n" +
 
397
                  "Content-Type: text/plain\r\n" +
 
398
                  "Content-Transfer-Encoding: binary\r\n" +
 
399
                  "\r\n" +
 
400
                  "Who cares? we assume, this has been properly extracted in this test" +
 
401
                  "\r\n--" + boundary + "\r\n" +
 
402
                  "Content-Id: " + dataCid + "\r\n" +
 
403
                  "Content-Type: text/plain\r\n" +
 
404
                  "Content-Transfer-Encoding: binary\r\n" +
 
405
                  "\r\n" +
 
406
                  dataContent +
 
407
                  "\r\n--" + boundary + "--\r\n";
 
408
            
 
409
    string contentType = string( "multipart/related;start=\"root-cid\";type=\"text/plain\";" ) +
 
410
                         "boundary=\"" + boundary + "\";start-info=\"info\"";
 
411
 
 
412
    RelatedMultipart multipart( body, contentType );
 
413
 
 
414
    // Create test node
 
415
    stringstream buf;
 
416
    buf << "<stream>"
 
417
        << "  <xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"cid:" << dataCidEncoded << "\"/>"
 
418
        << "</stream>";
 
419
    xmlNodePtr node = test::getXmlNode( buf.str( ) );
 
420
 
 
421
    // Run the tested method
 
422
    boost::shared_ptr< istream > stream = getStreamFromNode( node, multipart );
 
423
 
 
424
    // Checks
 
425
    stringstream out;
 
426
    out << stream->rdbuf( );
 
427
    CPPUNIT_ASSERT_EQUAL( dataContent, out.str( ) );
 
428
}
 
429
 
 
430
void SoapTest::getStreamFromNodeBase64Test( )
 
431
{
 
432
    // Create the test multipart
 
433
    string boundary = "------------ABCDEF-Boundary";
 
434
    string body = "\r\n--" + boundary + "\r\n" +
 
435
                  "Content-Id: <root-cid>\r\n" +
 
436
                  "Content-Type: text/plain\r\n" +
 
437
                  "Content-Transfer-Encoding: binary\r\n" +
 
438
                  "\r\n" +
 
439
                  "Who cares? we assume, this has been properly extracted in this test" +
 
440
                  "\r\n--" + boundary + "--\r\n";
 
441
            
 
442
    string contentType = string( "multipart/related;start=\"root-cid\";type=\"text/plain\";" ) +
 
443
                         "boundary=\"" + boundary + "\";start-info=\"info\"";
 
444
 
 
445
    RelatedMultipart multipart( body, contentType );
 
446
 
 
447
    // Create test node
 
448
    string dataContent = "U29tZSB0cmFuc2ZlcmVkIGNvbnRlbnQ=";
 
449
    string expectedContent = "Some transfered content";
 
450
    
 
451
    stringstream buf;
 
452
    buf << "<stream>" << dataContent << "</stream>";
 
453
    xmlNodePtr node = test::getXmlNode( buf.str( ) );
 
454
 
 
455
    // Run the tested method
 
456
    boost::shared_ptr< istream > stream = getStreamFromNode( node, multipart );
 
457
 
 
458
    // Checks
 
459
    stringstream out;
 
460
    out << stream->rdbuf( );
 
461
    CPPUNIT_ASSERT_EQUAL( expectedContent, out.str( ) );
 
462
}
 
463
 
 
464
void SoapTest::writeCmismStreamTest( )
 
465
{
 
466
    // Initialize the writer
 
467
    xmlBufferPtr buf = xmlBufferCreate( );
 
468
    xmlTextWriterPtr writer = xmlNewTextWriterMemory( buf, 0 );
 
469
    xmlTextWriterStartDocument( writer, NULL, NULL, NULL );
 
470
 
 
471
    // Test writeCmismStream
 
472
    RelatedMultipart multipart;
 
473
    string contentType( "text/plain" );
 
474
    string content( "Expected content" );
 
475
    string filename( "name.txt" );
 
476
    boost::shared_ptr< ostream > os( new stringstream( content ) );
 
477
    writeCmismStream( writer, multipart, os, contentType, filename );
 
478
 
 
479
    // Close the writer and check the results
 
480
    xmlTextWriterEndDocument( writer );
 
481
    string str( ( const char * )xmlBufferContent( buf ) );
 
482
 
 
483
    vector< string > ids = multipart.getIds( );
 
484
    CPPUNIT_ASSERT_EQUAL( size_t( 1 ), ids.size( ) );
 
485
    string partId = ids.front( );
 
486
 
 
487
    RelatedPartPtr part = multipart.getPart( partId );
 
488
    CPPUNIT_ASSERT_MESSAGE( "Missing stream related part", part.get( ) != NULL );
 
489
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Content not properly attached", content, part->getContent( ) );
 
490
 
 
491
    stringstream expectedXml;
 
492
    expectedXml << "<?xml version=\"1.0\"?>\n"
 
493
                << "<cmism:length>" << content.size( ) << "</cmism:length>"
 
494
                << "<cmism:mimeType>" << contentType << "</cmism:mimeType>"
 
495
                << "<cmism:filename>" << filename << "</cmism:filename>"
 
496
                << "<cmism:stream>"
 
497
                << "<xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"cid:" << partId << "\"/>"
 
498
                << "</cmism:stream>\n";
 
499
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Envelope part isn't correct", expectedXml.str( ), str );
 
500
 
 
501
    // Free it all
 
502
    xmlFreeTextWriter( writer );
 
503
    xmlBufferFree( buf );
 
504
}