xref: /AOO41X/main/extensions/test/sax/testwriter.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 
27 //#include <tools/presys.h>
28 #include <vector>
29 //#include <tools/postsys.h>
30 #include <smart/com/sun/star/test/XSimpleTest.hxx>
31 #include <smart/com/sun/star/lang/XMultiServiceFactory.hxx>  // for the multiservice-factories
32 
33 #include <stdio.h>
34 
35 #include <smart/com/sun/star/io/XActiveDataSource.hxx>
36 #include <smart/com/sun/star/io/XOutputStream.hxx>
37 #include <smart/com/sun/star/xml/sax/SAXParseException.hxx>
38 #include <smart/com/sun/star/xml/sax/XParser.hxx>
39 #include <smart/com/sun/star/xml/sax/XExtendedDocumentHandler.hxx>
40 
41 #include <rtl/wstring.hxx>
42 #include <osl/time.h>
43 #include <usr/weak.hxx>
44 #include <tools/string.hxx>
45 
46 #include <usr/factoryhlp.hxx>
47 
48 #include <usr/reflserv.hxx>  // for EXTERN_SERVICE_CALLTYPE
49 
50 using namespace std;
51 using namespace rtl;
52 using namespace vos;
53 using namespace usr;
54 
55 #define BUILD_ERROR(expr, Message)\
56         {\
57             m_seqErrors.realloc( m_seqErrors.getLen() + 1 ); \
58         m_seqExceptions.realloc(  m_seqExceptions.getLen() + 1 ); \
59         String str; \
60         str += __FILE__;\
61         str += " "; \
62         str += "(" ; \
63         str += __LINE__ ;\
64         str += ")\n";\
65         str += "[ " ; \
66         str += #expr; \
67         str += " ] : " ; \
68         str += Message; \
69         m_seqErrors.getArray()[ m_seqErrors.getLen()-1] = StringToUString( str , CHARSET_SYSTEM ); \
70         }\
71         ((void)0)
72 
73 
74 #define WARNING_ASSERT(expr, Message) \
75         if( ! (expr) ) { \
76             m_seqWarnings.realloc( m_seqErrors.getLen() +1 ); \
77             String str;\
78             str += __FILE__;\
79             str += " "; \
80             str += "(" ; \
81             str += __LINE__ ;\
82             str += ")\n";\
83             str += "[ " ; \
84             str += #expr; \
85             str += " ] : " ; \
86             str += Message; \
87             m_seqWarnings.getArray()[ m_seqWarnings.getLen()-1] = StringToUString( str , CHARSET_SYSTEM ); \
88             return; \
89         }\
90         ((void)0)
91 
92 #define ERROR_ASSERT(expr, Message) \
93         if( ! (expr) ) { \
94             BUILD_ERROR(expr, Message );\
95             return; \
96         }\
97         ((void)0)
98 
99 #define ERROR_EXCEPTION_ASSERT(expr, Message, Exception) \
100     if( !(expr)) { \
101         BUILD_ERROR(expr,Message);\
102         m_seqExceptions.getArray()[ m_seqExceptions.getLen()-1] = UsrAny( Exception );\
103         return; \
104     } \
105     ((void)0)
106 
107 /****
108 * test szenarios :
109 *
110 *
111 *
112 ****/
113 
114 
115 class OFileWriter :
116         public XOutputStream,
117         public OWeakObject
118 {
119 public:
120     OFileWriter( char *pcFile ) { strcpy( m_pcFile , pcFile ); m_f = 0; }
121 
122 
123 public: // refcounting
124     BOOL                        queryInterface( Uik aUik, XInterfaceRef & rOut )
125     {
126         if( XOutputStream::getSmartUik() == aUik ) {
127             rOut = (XOutputStream *) this;
128         }
129         else return OWeakObject::queryInterface( aUik , rOut );
130 
131         return TRUE;
132     }
133     void                        acquire()                        { OWeakObject::acquire(); }
134     void                        release()                        { OWeakObject::release(); }
135     void*                       getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); }
136 
137 public:
138     virtual void writeBytes(const Sequence< BYTE >& aData)
139                         THROWS( (NotConnectedException, BufferSizeExceededException, UsrSystemException) );
140     virtual void flush(void)
141                         THROWS( (NotConnectedException, BufferSizeExceededException, UsrSystemException) );
142     virtual void closeOutput(void)
143                         THROWS( (NotConnectedException, BufferSizeExceededException, UsrSystemException) );
144 
145 
146 private:
147     char m_pcFile[256];
148     FILE *m_f;
149 };
150 
151 
152 void OFileWriter::writeBytes(const Sequence< BYTE >& aData)
153             THROWS( (NotConnectedException, BufferSizeExceededException, UsrSystemException) )
154 {
155     if( ! m_f ) {
156         m_f = fopen( m_pcFile , "w" );
157     }
158 
159     fwrite( aData.getConstArray() , 1 , aData.getLen() , m_f );
160 
161 }
162 
163 
164 void OFileWriter::flush(void)
165             THROWS( (NotConnectedException, BufferSizeExceededException, UsrSystemException) )
166 {
167     fflush( m_f );
168 }
169 
170 void OFileWriter::closeOutput(void)
171                         THROWS( (NotConnectedException, BufferSizeExceededException, UsrSystemException) )
172 {
173     fclose( m_f );
174     m_f = 0;
175 }
176 
177 
178 class OSaxWriterTest :
179         public XSimpleTest,
180         public OWeakObject
181 {
182 public:
183     OSaxWriterTest( const XMultiServiceFactoryRef & rFactory ) : m_rFactory( rFactory )
184     {
185 
186     }
187     ~OSaxWriterTest() {}
188 
189 public: // refcounting
190     BOOL                        queryInterface( Uik aUik, XInterfaceRef & rOut );
191     void                        acquire()                        { OWeakObject::acquire(); }
192     void                        release()                        { OWeakObject::release(); }
193     void*                       getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); }
194 
195 public:
196     virtual void testInvariant(const UString& TestName, const XInterfaceRef& TestObject)
197                                                                 THROWS( (   IllegalArgumentException,
198                                                                             UsrSystemException) );
199 
200     virtual INT32 test( const UString& TestName,
201                         const XInterfaceRef& TestObject,
202                         INT32 hTestHandle)                      THROWS( (   IllegalArgumentException,
203                                                                             UsrSystemException) );
204 
205     virtual BOOL testPassed(void)                               THROWS( (   UsrSystemException) );
206     virtual Sequence< UString > getErrors(void)                 THROWS( (UsrSystemException) );
207     virtual Sequence< UsrAny > getErrorExceptions(void)         THROWS( (UsrSystemException) );
208     virtual Sequence< UString > getWarnings(void)               THROWS( (UsrSystemException) );
209 
210 private:
211     void testSimple( const XExtendedDocumentHandlerRef &r );
212     void testExceptions( const XExtendedDocumentHandlerRef &r );
213     void testDTD( const XExtendedDocumentHandlerRef &r );
214     void testPerformance( const XExtendedDocumentHandlerRef &r );
215     void writeParagraph( const XExtendedDocumentHandlerRef &r , const UString & s);
216 
217 private:
218     Sequence<UsrAny>        m_seqExceptions;
219     Sequence<UString>       m_seqErrors;
220     Sequence<UString>       m_seqWarnings;
221     XMultiServiceFactoryRef m_rFactory;
222 
223 };
224 
225 
226 
227 /*----------------------------------------
228 *
229 *   Attributlist implementation
230 *
231 *----------------------------------------*/
232 struct AttributeListImpl_impl;
233 class AttributeListImpl :
234         public XAttributeList,
235         public OWeakObject
236 {
237 public:
238     AttributeListImpl();
239     AttributeListImpl( const AttributeListImpl & );
240     ~AttributeListImpl();
241 
242 public:
243     BOOL                    queryInterface( Uik aUik, XInterfaceRef & rOut );
244     void                    acquire()                        { OWeakObject::acquire(); }
245     void                    release()                        { OWeakObject::release(); }
246     void*                   getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); }
247 
248 public:
249     virtual INT16 getLength(void) THROWS( (UsrSystemException) );
250     virtual UString getNameByIndex(INT16 i) THROWS( (UsrSystemException) );
251     virtual UString getTypeByIndex(INT16 i) THROWS( (UsrSystemException) );
252     virtual UString getTypeByName(const UString& aName) THROWS( (UsrSystemException) );
253     virtual UString getValueByIndex(INT16 i) THROWS( (UsrSystemException) );
254     virtual UString getValueByName(const UString& aName) THROWS( (UsrSystemException) );
255 
256 public:
257     void addAttribute( const UString &sName , const UString &sType , const UString &sValue );
258     void clear();
259 
260 private:
261     struct AttributeListImpl_impl *m_pImpl;
262 };
263 
264 
265 struct TagAttribute
266 {
267     TagAttribute(){}
268     TagAttribute( const UString &sName, const UString &sType , const UString &sValue )
269     {
270         this->sName     = sName;
271         this->sType     = sType;
272         this->sValue    = sValue;
273     }
274 
275     UString sName;
276     UString sType;
277     UString sValue;
278 };
279 
280 struct AttributeListImpl_impl
281 {
282     AttributeListImpl_impl()
283     {
284         // performance improvement during adding
285         vecAttribute.reserve(20);
286     }
287     vector<struct TagAttribute> vecAttribute;
288 };
289 
290 
291 
292 INT16 AttributeListImpl::getLength(void) THROWS( (UsrSystemException) )
293 {
294     return m_pImpl->vecAttribute.size();
295 }
296 
297 
298 AttributeListImpl::AttributeListImpl( const AttributeListImpl &r )
299 {
300     m_pImpl = new AttributeListImpl_impl;
301     *m_pImpl = *(r.m_pImpl);
302 }
303 
304 UString AttributeListImpl::getNameByIndex(INT16 i) THROWS( (UsrSystemException) )
305 {
306     if( i < m_pImpl->vecAttribute.size() ) {
307         return m_pImpl->vecAttribute[i].sName;
308     }
309     return UString();
310 }
311 
312 
313 UString AttributeListImpl::getTypeByIndex(INT16 i) THROWS( (UsrSystemException) )
314 {
315     if( i < m_pImpl->vecAttribute.size() ) {
316         return m_pImpl->vecAttribute[i].sType;
317     }
318     return UString();
319 }
320 
321 UString AttributeListImpl::getValueByIndex(INT16 i) THROWS( (UsrSystemException) )
322 {
323     if( i < m_pImpl->vecAttribute.size() ) {
324         return m_pImpl->vecAttribute[i].sValue;
325     }
326     return UString();
327 
328 }
329 
330 UString AttributeListImpl::getTypeByName( const UString& sName ) THROWS( (UsrSystemException) )
331 {
332     vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
333 
334     for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) {
335         if( (*ii).sName == sName ) {
336             return (*ii).sType;
337         }
338     }
339     return UString();
340 }
341 
342 UString AttributeListImpl::getValueByName(const UString& sName) THROWS( (UsrSystemException) )
343 {
344     vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
345 
346     for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) {
347         if( (*ii).sName == sName ) {
348             return (*ii).sValue;
349         }
350     }
351     return UString();
352 }
353 
354 
355 BOOL AttributeListImpl::queryInterface( Uik aUik, XInterfaceRef & rOut )
356 {
357     if( aUik == XAttributeList::getSmartUik() ) {
358         rOut = (XAttributeList * )this;
359     }
360     else {
361         return OWeakObject::queryInterface( aUik , rOut );
362     }
363     return TRUE;
364 }
365 
366 
367 AttributeListImpl::AttributeListImpl()
368 {
369     m_pImpl = new AttributeListImpl_impl;
370 }
371 
372 
373 
374 AttributeListImpl::~AttributeListImpl()
375 {
376     delete m_pImpl;
377 }
378 
379 
380 void AttributeListImpl::addAttribute(   const UString &sName ,
381                                         const UString &sType ,
382                                         const UString &sValue )
383 {
384     m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
385 }
386 
387 void AttributeListImpl::clear()
388 {
389     vector<struct TagAttribute> dummy;
390     m_pImpl->vecAttribute.swap( dummy );
391 
392     OSL_ASSERT( ! getLength() );
393 }
394 
395 
396 
397 
398 
399 
400 
401 
402 
403 
404 
405 /**
406 * for external binding
407 *
408 *
409 **/
410 XInterfaceRef OSaxWriterTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception))
411 {
412     OSaxWriterTest *p = new OSaxWriterTest( rSMgr );
413     XInterfaceRef xService = *p;
414     return xService;
415 }
416 
417 UString     OSaxWriterTest_getServiceName( ) THROWS( () )
418 {
419     return L"test.com.sun.star.xml.sax.Writer";
420 }
421 
422 UString     OSaxWriterTest_getImplementationName( ) THROWS( () )
423 {
424     return L"test.extensions.xml.sax.Writer";
425 }
426 
427 Sequence<UString> OSaxWriterTest_getSupportedServiceNames( ) THROWS( () )
428 {
429     Sequence<UString> aRet(1);
430 
431     aRet.getArray()[0] = OSaxWriterTest_getImplementationName( );
432 
433     return aRet;
434 }
435 
436 
437 BOOL OSaxWriterTest::queryInterface( Uik uik , XInterfaceRef &rOut )
438 {
439     if( XSimpleTest::getSmartUik() == uik ) {
440         rOut = (XSimpleTest *) this;
441     }
442     else {
443         return OWeakObject::queryInterface( uik , rOut );
444     }
445     return TRUE;
446 }
447 
448 
449 void OSaxWriterTest::testInvariant( const UString& TestName, const XInterfaceRef& TestObject )
450                                                                 THROWS( (   IllegalArgumentException,
451                                                                             UsrSystemException) )
452 {
453     if( L"com.sun.star.xml.sax.Writer" == TestName ) {
454         XDocumentHandlerRef doc( TestObject , USR_QUERY );
455         XExtendedDocumentHandlerRef ext( TestObject , USR_QUERY );
456         XActiveDataSourceRef source( TestObject , USR_QUERY );
457 
458         ERROR_ASSERT( doc.is() , "XDocumentHandler cannot be queried" );
459         ERROR_ASSERT( ext.is() , "XExtendedDocumentHandler cannot be queried" );
460         ERROR_ASSERT( source.is() , "XActiveDataSource cannot be queried" );
461     }
462     else {
463         BUILD_ERROR( 0 , "wrong test" );
464     }
465 }
466 
467 
468 INT32 OSaxWriterTest::test( const UString& TestName,
469                         const XInterfaceRef& TestObject,
470                         INT32 hTestHandle)                      THROWS( (   IllegalArgumentException,
471                                                                             UsrSystemException) )
472 {
473     if( L"com.sun.star.xml.sax.Writer" == TestName )  {
474         try {
475             if( 0 == hTestHandle ) {
476                 testInvariant( TestName , TestObject );
477             }
478             else {
479 
480                 XExtendedDocumentHandlerRef writer( TestObject , USR_QUERY );
481 
482                 if( 1 == hTestHandle ) {
483                     testSimple( writer );
484                 }
485                 else if( 2 == hTestHandle ) {
486                     testExceptions( writer );
487                 }
488                 else if( 3 == hTestHandle ) {
489                     testDTD( writer );
490                 }
491                 else if( 4 == hTestHandle ) {
492                     testPerformance( writer );
493                 }
494             }
495         }
496         catch( Exception& e )  {
497             BUILD_ERROR( 0 , UStringToString( e.getName() , CHARSET_SYSTEM ).GetCharStr() );
498         }
499         catch(...) {
500             BUILD_ERROR( 0 , "unknown exception (Exception is  not base class)" );
501         }
502 
503         hTestHandle ++;
504 
505         if( hTestHandle >= 5) {
506             // all tests finished.
507             hTestHandle = -1;
508         }
509     }
510     else {
511         BUILD_ERROR( 0 , "service not supported by test." );
512     }
513     return hTestHandle;
514 }
515 
516 
517 
518 BOOL OSaxWriterTest::testPassed(void)                                       THROWS( (UsrSystemException) )
519 {
520     return m_seqErrors.getLen() == 0;
521 }
522 
523 
524 Sequence< UString > OSaxWriterTest::getErrors(void)                             THROWS( (UsrSystemException) )
525 {
526     return m_seqErrors;
527 }
528 
529 
530 Sequence< UsrAny > OSaxWriterTest::getErrorExceptions(void)                     THROWS( (UsrSystemException) )
531 {
532     return m_seqExceptions;
533 }
534 
535 
536 Sequence< UString > OSaxWriterTest::getWarnings(void)                       THROWS( (UsrSystemException) )
537 {
538     return m_seqWarnings;
539 }
540 
541 void OSaxWriterTest::writeParagraph( const XExtendedDocumentHandlerRef &r , const UString & s)
542 {
543     int nMax = s.len();
544     int nStart = 0;
545 
546     Sequence<UINT16> seq( s.len() );
547     memcpy( seq.getArray() , s.getStr() , s.len() * sizeof( UINT16 ) );
548 
549     for( int n = 1 ; n < nMax ; n++ ){
550         if( 32 == seq.getArray()[n] ) {
551             r->allowLineBreak();
552             r->characters( s.copy( nStart , n - nStart ) );
553             nStart = n;
554         }
555     }
556     r->allowLineBreak();
557     r->characters( s.copy( nStart , n - nStart ) );
558 
559 
560 }
561 
562 
563 
564 void OSaxWriterTest::testSimple( const XExtendedDocumentHandlerRef &r )
565 {
566     UString testParagraph = L"Dies ist ein bloeder Test um zu uberpruefen, ob der SAXWriter "
567                             L"wohl Zeilenumbrueche halbwegs richtig macht oder ob er die Zeile "
568                             L"bis zum bitteren Ende schreibt.";
569 
570     OFileWriter *pw = new OFileWriter("output.xml");
571     AttributeListImpl *pList = new AttributeListImpl;
572 
573     XAttributeListRef rList( (XAttributeList *) pList , USR_QUERY );
574     XOutputStreamRef ref( ( XOutputStream * ) pw , USR_QUERY );
575 
576     XActiveDataSourceRef source( r , USR_QUERY );
577 
578     ERROR_ASSERT( ref.is() , "no output stream" );
579     ERROR_ASSERT( source.is() , "no active data source" );
580 
581     source->setOutputStream( ref );
582 
583     r->startDocument();
584 
585     pList->addAttribute( L"Arg1" , L"CDATA" , L"bla\n   u" );
586     pList->addAttribute( L"Arg2" , L"CDATA" , L"blub" );
587 
588     r->startElement( L"tag1"  , rList );
589     r->ignorableWhitespace( L"" );
590 
591     r->characters( L"huhu" );
592     r->ignorableWhitespace( L"" );
593 
594     r->startElement( L"hi" , rList );
595     r->ignorableWhitespace( L"" );
596 
597     // the enpassant must be converted & -> &amp;
598     r->characters( L"&#252;" );
599 
600     // Test added for mib. Tests if errors during conversions occurs
601     r->ignorableWhitespace( UString() );
602     sal_Char array[256];
603     for( sal_Int32 n = 32 ; n < 254 ; n ++ ) {
604         array[n-32] = n;
605     }
606     array[254-32] = 0;
607     r->characters(
608         StringToUString( array , RTL_TEXTENCODING_SYMBOL )
609         );
610     r->ignorableWhitespace( UString() );
611 
612     // '>' must not be converted
613     r->startCDATA();
614     r->characters( L">fsfsdf<" );
615     r->endCDATA();
616     r->ignorableWhitespace( UString() );
617 
618     writeParagraph( r , testParagraph );
619 
620 
621     r->ignorableWhitespace( UString() );
622     r->comment( L"Dies ist ein Kommentar !" );
623     r->ignorableWhitespace( UString() );
624 
625     r->startElement( L"emptytagtest"  , rList );
626     r->endElement( L"emptytagtest" );
627 
628     r->endElement( L"hi" );
629     r->ignorableWhitespace( L"" );
630 
631     r->endElement( L"tag1" );
632     r->endDocument();
633 
634 }
635 
636 void OSaxWriterTest::testExceptions( const XExtendedDocumentHandlerRef & r )
637 {
638 
639     OFileWriter *pw = new OFileWriter("output2.xml");
640     AttributeListImpl *pList = new AttributeListImpl;
641 
642     XAttributeListRef rList( (XAttributeList *) pList , USR_QUERY );
643     XOutputStreamRef ref( ( XOutputStream * ) pw , USR_QUERY );
644 
645     XActiveDataSourceRef source( r , USR_QUERY );
646 
647     ERROR_ASSERT( ref.is() , "no output stream" );
648     ERROR_ASSERT( source.is() , "no active data source" );
649 
650     source->setOutputStream( ref );
651 
652     { // startDocument must be called before start element
653         BOOL bException = TRUE;
654         try {
655             r->startElement( L"huhu" , rList );
656             bException = FALSE;
657         }
658         catch( SAXException& e ) {
659 
660         }
661         ERROR_ASSERT( bException , "expected exception not thrown !" );
662     }
663 
664     r->startDocument();
665 
666     r->startElement( L"huhu" , rList );
667     r->startCDATA();
668 
669     {
670         BOOL bException = TRUE;
671         try {
672             r->startElement( L"huhu" , rList );
673             bException = FALSE;
674         }
675         catch( SAXException& e ) {
676 
677         }
678         ERROR_ASSERT( bException , "expected exception not thrown !" );
679     }
680 
681     r->endCDATA();
682     r->endElement( L"hi" );
683 
684     r->endDocument();
685 }
686 
687 
688 void OSaxWriterTest::testDTD(const  XExtendedDocumentHandlerRef &r )
689 {
690     OFileWriter *pw = new OFileWriter("outputDTD.xml");
691     AttributeListImpl *pList = new AttributeListImpl;
692 
693     XAttributeListRef rList( (XAttributeList *) pList , USR_QUERY );
694     XOutputStreamRef ref( ( XOutputStream * ) pw , USR_QUERY );
695 
696     XActiveDataSourceRef source( r , USR_QUERY );
697 
698     ERROR_ASSERT( ref.is() , "no output stream" );
699     ERROR_ASSERT( source.is() , "no active data source" );
700 
701     source->setOutputStream( ref );
702 
703 
704     r->startDocument();
705     r->unknown( L"<!DOCTYPE iCalendar >\n" );
706     r->startElement( L"huhu" , rList );
707 
708     r->endElement( L"huhu" );
709     r->endDocument();
710 }
711 
712 void OSaxWriterTest::testPerformance(const  XExtendedDocumentHandlerRef &r )
713 {
714     OFileWriter *pw = new OFileWriter("testPerformance.xml");
715     AttributeListImpl *pList = new AttributeListImpl;
716 
717     UString testParagraph = L"Dies ist ein bloeder Test um zu uberpruefen, ob der SAXWriter "
718                             L"wohl > Zeilenumbrueche halbwegs richtig macht oder ob er die Zeile "
719                             L"bis zum bitteren Ende schreibt.";
720 
721 
722     XAttributeListRef rList( (XAttributeList *) pList , USR_QUERY );
723     XOutputStreamRef ref( ( XOutputStream * ) pw , USR_QUERY );
724 
725     XActiveDataSourceRef source( r , USR_QUERY );
726 
727     ERROR_ASSERT( ref.is() , "no output stream" );
728     ERROR_ASSERT( source.is() , "no active data source" );
729 
730     source->setOutputStream( ref );
731 
732     TimeValue aStartTime, aEndTime;
733     osl_getSystemTime( &aStartTime );
734 
735 
736     r->startDocument();
737     // just write a bunch of xml tags !
738     // for performance testing
739     sal_Int32 i2;
740     for( i2 = 0 ; i2 < 15 ; i2 ++ )
741     {
742         r->startElement( UString( L"tag" ) + UString::valueOf( i2 ), rList );
743         for( sal_Int32 i = 0 ; i < 450 ; i ++ )
744         {
745             r->ignorableWhitespace( L"");
746             r->startElement( L"huhu" , rList );
747             r->characters( testParagraph );
748 //          writeParagraph( r , testParagraph );
749 
750             r->ignorableWhitespace( L"");
751             r->endElement( L"huhu" );
752         }
753     }
754     for( i2 = 14 ; i2 >= 0  ; i2-- )
755     {
756         r->ignorableWhitespace( L"");
757         r->endElement( UString( L"tag" ) + UString::valueOf( i2 ) );
758     }
759 
760     r->endDocument();
761 
762     osl_getSystemTime( &aEndTime );
763 
764     double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
765     double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
766 
767     printf( "Performance writing : %g s\n" , fEnd - fStart );
768 }
769