1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
33 #include <smart/com/sun/star/test/XSimpleTest.hxx>
35 #include <rtl/wstring.hxx>
37 //#include <vos/dynload.hxx>
38 //#include <vos/diagnose.hxx>
39 #include <usr/weak.hxx>
40 #include <tools/string.hxx>
41 #include <vos/conditn.hxx>
43 #include <smart/com/sun/star/io/XOutputStream.hxx>
44 #include <smart/com/sun/star/xml/sax/SAXParseException.hxx>
45 #include <smart/com/sun/star/xml/sax/XParser.hxx>
46 #include <smart/com/sun/star/xml/sax/XExtendedDocumentHandler.hxx>
48 #include <smart/com/sun/star/lang/XMultiServiceFactory.hxx> // for the multiservice-factories
49 #include <usr/factoryhlp.hxx>
51 #include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE
53 #include "factory.hxx"
60 #define BUILD_ERROR(expr, Message)\
62 m_seqErrors.realloc( m_seqErrors.getLen() + 1 ); \
63 m_seqExceptions.realloc( m_seqExceptions.getLen() + 1 ); \
74 m_seqErrors.getArray()[ m_seqErrors.getLen()-1] = StringToUString( str , CHARSET_SYSTEM ); \
79 #define WARNING_ASSERT(expr, Message) \
81 m_seqWarnings.realloc( m_seqErrors.getLen() +1 ); \
92 m_seqWarnings.getArray()[ m_seqWarnings.getLen()-1] = StringToUString( str , CHARSET_SYSTEM ); \
97 #define ERROR_ASSERT(expr, Message) \
99 BUILD_ERROR(expr, Message );\
104 #define ERROR_EXCEPTION_ASSERT(expr, Message, Exception) \
106 BUILD_ERROR(expr,Message);\
107 m_seqExceptions.getArray()[ m_seqExceptions.getLen()-1] = UsrAny( Exception );\
121 class OSaxParserTest
:
126 OSaxParserTest( const XMultiServiceFactoryRef
& rFactory
) : m_rFactory( rFactory
)
131 public: // refcounting
132 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
133 void acquire() { OWeakObject::acquire(); }
134 void release() { OWeakObject::release(); }
135 void* getImplementation(Reflection
*p
) { return OWeakObject::getImplementation(p
); }
138 virtual void testInvariant(const UString
& TestName
, const XInterfaceRef
& TestObject
)
139 THROWS( ( IllegalArgumentException
,
140 UsrSystemException
) );
142 virtual INT32
test( const UString
& TestName
,
143 const XInterfaceRef
& TestObject
,
144 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
145 UsrSystemException
) );
147 virtual BOOL
testPassed(void) THROWS( ( UsrSystemException
) );
148 virtual Sequence
< UString
> getErrors(void) THROWS( (UsrSystemException
) );
149 virtual Sequence
< UsrAny
> getErrorExceptions(void) THROWS( (UsrSystemException
) );
150 virtual Sequence
< UString
> getWarnings(void) THROWS( (UsrSystemException
) );
153 void testSimple( const XParserRef
&r
);
154 void testNamespaces( const XParserRef
&r
);
155 void testFile( const XParserRef
&r
);
156 void testEncoding( const XParserRef
&rParser
);
157 void testPerformance( const XParserRef
&rParser
);
160 Sequence
<UsrAny
> m_seqExceptions
;
161 Sequence
<UString
> m_seqErrors
;
162 Sequence
<UString
> m_seqWarnings
;
163 XMultiServiceFactoryRef m_rFactory
;
169 * for external binding
173 XInterfaceRef
OSaxParserTest_CreateInstance( const XMultiServiceFactoryRef
& rSMgr
) THROWS((Exception
))
175 OSaxParserTest
*p
= new OSaxParserTest( rSMgr
);
176 XInterfaceRef xService
= *p
;
181 UString
OSaxParserTest_getServiceName( ) THROWS( () )
183 return L
"test.com.sun.star.xml.sax.Parser";
186 UString
OSaxParserTest_getImplementationName( ) THROWS( () )
188 return L
"test.extensions.xml.sax.Parser";
191 Sequence
<UString
> OSaxParserTest_getSupportedServiceNames( ) THROWS( () )
193 Sequence
<UString
> aRet(1);
195 aRet
.getArray()[0] = OSaxParserTest_getImplementationName( );
201 BOOL
OSaxParserTest::queryInterface( Uik uik
, XInterfaceRef
&rOut
)
203 if( XSimpleTest::getSmartUik() == uik
) {
204 rOut
= (XSimpleTest
*) this;
207 return OWeakObject::queryInterface( uik
, rOut
);
213 void OSaxParserTest::testInvariant( const UString
& TestName
, const XInterfaceRef
& TestObject
)
214 THROWS( ( IllegalArgumentException
,
215 UsrSystemException
) )
217 if( L
"com.sun.star.xml.sax.Parser" == TestName
) {
218 XParserRef
parser( TestObject
, USR_QUERY
);
220 ERROR_ASSERT( parser
.is() , "XDataInputStream cannot be queried" );
225 INT32
OSaxParserTest::test( const UString
& TestName
,
226 const XInterfaceRef
& TestObject
,
227 INT32 hTestHandle
) THROWS( ( IllegalArgumentException
,
228 UsrSystemException
) )
230 if( L
"com.sun.star.xml.sax.Parser" == TestName
) {
232 if( 0 == hTestHandle
) {
233 testInvariant( TestName
, TestObject
);
237 XParserRef
parser( TestObject
, USR_QUERY
);
239 if( 1 == hTestHandle
) {
240 testSimple( parser
);
242 else if( 2 == hTestHandle
) {
243 testNamespaces( parser
);
245 else if( 3 == hTestHandle
) {
246 testEncoding( parser
);
248 else if( 4 == hTestHandle
) {
251 else if( 5 == hTestHandle
) {
252 testPerformance( parser
);
256 catch( Exception
& e
) {
257 BUILD_ERROR( 0 , UStringToString( e
.getName() , CHARSET_SYSTEM
).GetCharStr() );
260 BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" );
265 if( hTestHandle
>= 6) {
266 // all tests finished.
271 BUILD_ERROR( 0 , "service not supported by test." );
278 BOOL
OSaxParserTest::testPassed(void) THROWS( (UsrSystemException
) )
280 return m_seqErrors
.getLen() == 0;
284 Sequence
< UString
> OSaxParserTest::getErrors(void) THROWS( (UsrSystemException
) )
290 Sequence
< UsrAny
> OSaxParserTest::getErrorExceptions(void) THROWS( (UsrSystemException
) )
292 return m_seqExceptions
;
296 Sequence
< UString
> OSaxParserTest::getWarnings(void) THROWS( (UsrSystemException
) )
298 return m_seqWarnings
;
301 XInputStreamRef
createStreamFromSequence( const Sequence
<BYTE
> seqBytes
, XMultiServiceFactoryRef
&xSMgr
)
303 XInterfaceRef xOutStreamService
= xSMgr
->createInstance( L
"com.sun.star.io.Pipe" );
304 OSL_ASSERT( xOutStreamService
.is() );
305 XOutputStreamRef
rOutStream( xOutStreamService
, USR_QUERY
);
306 OSL_ASSERT( rOutStream
.is() );
308 XInputStreamRef
rInStream( xOutStreamService
, USR_QUERY
);
309 OSL_ASSERT( rInStream
.is() );
311 rOutStream
->writeBytes( seqBytes
);
313 rOutStream
->closeOutput();
318 XInputStreamRef
createStreamFromFile( const char *pcFile
, XMultiServiceFactoryRef
&xSMgr
)
320 FILE *f
= fopen( pcFile
, "rb" );
324 fseek( f
, 0 , SEEK_END
);
325 int nLength
= ftell( f
);
326 fseek( f
, 0 , SEEK_SET
);
328 Sequence
<BYTE
> seqIn(nLength
);
329 fread( seqIn
.getArray() , nLength
, 1 , f
);
331 r
= createStreamFromSequence( seqIn
, xSMgr
);
345 #define PCHAR_TO_USTRING(x) StringToUString(String(x),CHARSET_PC_1252)
346 #define USTRING_TO_PCHAR(x) UStringToString(x,CHARSET_PC_437).GetStr()
350 class TestDocumentHandler
:
351 public XExtendedDocumentHandler
,
352 public XEntityResolver
,
353 public XErrorHandler
,
357 TestDocumentHandler( XMultiServiceFactoryRef
&r
, BOOL bPrint
)
365 BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
366 void acquire() { OWeakObject::acquire(); }
367 void release() { OWeakObject::release(); }
368 void* getImplementation(Reflection
*p
) { return OWeakObject::getImplementation(p
); }
371 public: // Error handler
372 virtual void error(const UsrAny
& aSAXParseException
) THROWS( (SAXException
, UsrSystemException
) )
374 printf( "Error !\n" );
375 THROW( SAXException( L
"error from error handler" , XInterfaceRef() , aSAXParseException
) );
377 virtual void fatalError(const UsrAny
& aSAXParseException
) THROWS( (SAXException
, UsrSystemException
) )
379 printf( "Fatal Error !\n" );
381 virtual void warning(const UsrAny
& aSAXParseException
) THROWS( (SAXException
, UsrSystemException
) )
383 printf( "Warning !\n" );
387 public: // ExtendedDocumentHandler
389 virtual void startDocument(void) THROWS( (SAXException
, UsrSystemException
) )
393 m_iAttributeCount
= 0;
394 m_iWhitespaceCount
=0;
397 printf( "document started\n" );
400 virtual void endDocument(void) THROWS( (SAXException
, UsrSystemException
) )
403 printf( "document finished\n" );
404 printf( "(ElementCount %d),(AttributeCount %d),(WhitespaceCount %d),(CharCount %d)\n",
405 m_iElementCount
, m_iAttributeCount
, m_iWhitespaceCount
, m_iCharCount
);
408 virtual void startElement(const UString
& aName
, const XAttributeListRef
& xAttribs
)
409 THROWS( (SAXException
,UsrSystemException
) )
412 if( m_rLocator
.is() ) {
414 printf( "%s(%d):" , USTRING_TO_PCHAR( m_rLocator
->getSystemId() ) ,
415 m_rLocator
->getLineNumber() );
419 for( i
= 0; i
< m_iLevel
; i
++ ) {
422 printf( "<%s> " , USTRING_TO_PCHAR( aName
) );
424 for( i
= 0 ; i
< xAttribs
->getLength() ; i
++ ) {
425 printf( "(%s,%s,'%s')" , USTRING_TO_PCHAR( xAttribs
->getNameByIndex( i
) ) ,
426 USTRING_TO_PCHAR( xAttribs
->getTypeByIndex( i
) ) ,
427 USTRING_TO_PCHAR( xAttribs
->getValueByIndex( i
) ) );
433 m_iAttributeCount
+= xAttribs
->getLength();
435 virtual void endElement(const UString
& aName
) THROWS( (SAXException
,UsrSystemException
) )
437 OSL_ASSERT( m_iLevel
);
441 for( i
= 0; i
< m_iLevel
; i
++ ) {
444 printf( "</%s>\n" , USTRING_TO_PCHAR( aName
) );
448 virtual void characters(const UString
& aChars
) THROWS( (SAXException
,UsrSystemException
) )
452 for( i
= 0; i
< m_iLevel
; i
++ ) {
455 printf( "%s\n" , USTRING_TO_PCHAR( aChars
) );
457 m_iCharCount
+= aChars
.len();
459 virtual void ignorableWhitespace(const UString
& aWhitespaces
) THROWS( (SAXException
,UsrSystemException
) )
461 m_iWhitespaceCount
+= aWhitespaces
.len();
464 virtual void processingInstruction(const UString
& aTarget
, const UString
& aData
) THROWS( (SAXException
,UsrSystemException
) )
467 printf( "PI : %s,%s\n" , USTRING_TO_PCHAR( aTarget
) , USTRING_TO_PCHAR( aData
) );
470 virtual void setDocumentLocator(const XLocatorRef
& xLocator
) THROWS( (SAXException
,UsrSystemException
) )
472 m_rLocator
= xLocator
;
475 virtual InputSource
resolveEntity(const UString
& sPublicId
, const UString
& sSystemId
)
476 THROWS( (SAXException
,UsrSystemException
) )
479 source
.sSystemId
= sSystemId
;
480 source
.sPublicId
= sPublicId
;
481 source
.aInputStream
= createStreamFromFile( USTRING_TO_PCHAR( sSystemId
) , m_xSMgr
);
486 virtual void startCDATA(void) THROWS( (SAXException
,UsrSystemException
) )
489 printf( "CDataStart :\n" );
492 virtual void endCDATA(void) THROWS( (SAXException
,UsrSystemException
) )
495 printf( "CEndStart :\n" );
498 virtual void comment(const UString
& sComment
) THROWS( (SAXException
,UsrSystemException
) )
501 printf( "<!--%s-->\n" , USTRING_TO_PCHAR( sComment
) );
504 virtual void unknown(const UString
& sString
) THROWS( (SAXException
,UsrSystemException
) )
507 printf( "UNKNOWN : {%s}\n" , USTRING_TO_PCHAR( sString
) );
511 virtual void allowLineBreak( void) THROWS( (SAXException
, UsrSystemException
) )
520 int m_iAttributeCount
;
521 int m_iWhitespaceCount
;
525 XMultiServiceFactoryRef m_xSMgr
;
526 XLocatorRef m_rLocator
;
529 BOOL
TestDocumentHandler::queryInterface( Uik aUik
, XInterfaceRef
& rOut
)
531 if( aUik
== XDocumentHandler::getSmartUik() ) {
532 rOut
= (XDocumentHandler
* )this;
534 else if ( aUik
== XExtendedDocumentHandler::getSmartUik() ) {
535 rOut
= (XExtendedDocumentHandler
*) this;
537 else if ( aUik
== XEntityResolver::getSmartUik() ) {
538 rOut
= (XEntityResolver
*) this;
540 else if ( aUik
== XErrorHandler::getSmartUik() ) {
541 rOut
= (XErrorHandler
* ) this;
544 return OWeakObject::queryInterface( aUik
, rOut
);
552 void OSaxParserTest::testSimple( const XParserRef
&rParser
)
556 "<!DOCTYPE personnel [\n"
557 "<!ENTITY testInternal \"internal Test!\">\n"
558 "<!ENTITY test SYSTEM \"external_entity.xml\">\n"
562 "<person> fjklsfdklsdfkl\n"
564 "<?testpi pidata?>\n"
566 "<HUHU x='5' y='kjfd'> blahuhu\n"
568 " <![CDATA[<greeting>Hello, '+1+12world!</greeting>]]>\n"
569 " <!-- huhu <jdk> -->\n"
570 "<?testpi pidata?>\n"
575 "</personnel>\n\n\n";
577 Sequence
<BYTE
> seqBytes( strlen( TestString
) );
578 memcpy( seqBytes
.getArray() , TestString
, strlen( TestString
) );
581 XInputStreamRef rInStream
;
583 rInStream
= createStreamFromSequence( seqBytes
, m_rFactory
);
584 sInput
= UString( L
"internal" );
589 source
.aInputStream
= rInStream
;
590 source
.sSystemId
= sInput
;
592 TestDocumentHandler
*pDocHandler
= new TestDocumentHandler( m_rFactory
, FALSE
);
593 XDocumentHandlerRef
rDocHandler( (XDocumentHandler
*) pDocHandler
, USR_QUERY
);
594 XEntityResolverRef
rEntityResolver( (XEntityResolver
*) pDocHandler
, USR_QUERY
);
596 rParser
->setDocumentHandler( rDocHandler
);
597 rParser
->setEntityResolver( rEntityResolver
);
600 rParser
->parseStream( source
);
601 ERROR_ASSERT( pDocHandler
->m_iElementCount
== 4 , "wrong element count" );
602 ERROR_ASSERT( pDocHandler
->m_iAttributeCount
== 2 , "wrong attribut count" );
603 ERROR_ASSERT( pDocHandler
->m_iCharCount
== 130 , "wrong char count" );
604 ERROR_ASSERT( pDocHandler
->m_iWhitespaceCount
== 0, "wrong whitespace count" );
606 catch( SAXParseException
& e
) {
607 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
609 catch( SAXException
& e
) {
610 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
613 catch( Exception
& e
) {
614 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
617 BUILD_ERROR( 1 , "unknown exception" );
625 void OSaxParserTest::testNamespaces( const XParserRef
&rParser
)
629 "<?xml version='1.0'?>\n"
630 "<!-- all elements here are explicitly in the HTML namespace -->\n"
631 "<html:html xmlns:html='http://www.w3.org/TR/REC-html40'>\n"
632 "<html:head><html:title>Frobnostication</html:title></html:head>\n"
633 "<html:body><html:p>Moved to \n"
634 "<html:a href='http://frob.com'>here.</html:a></html:p></html:body>\n"
637 Sequence
<BYTE
> seqBytes( strlen( TestString
) );
638 memcpy( seqBytes
.getArray() , TestString
, strlen( TestString
) );
641 XInputStreamRef rInStream
;
644 rInStream
= createStreamFromSequence( seqBytes
, m_rFactory
);
645 sInput
= UString( L
"internal" );
650 source
.aInputStream
= rInStream
;
651 source
.sSystemId
= sInput
;
653 TestDocumentHandler
*pDocHandler
= new TestDocumentHandler( m_rFactory
, FALSE
);
654 XDocumentHandlerRef
rDocHandler( (XDocumentHandler
*) pDocHandler
, USR_QUERY
);
655 XEntityResolverRef
rEntityResolver( (XEntityResolver
*) pDocHandler
, USR_QUERY
);
657 rParser
->setDocumentHandler( rDocHandler
);
658 rParser
->setEntityResolver( rEntityResolver
);
661 rParser
->parseStream( source
);
662 ERROR_ASSERT( pDocHandler
->m_iElementCount
== 6 , "wrong element count" );
663 ERROR_ASSERT( pDocHandler
->m_iAttributeCount
== 2 , "wrong attribut count" );
664 ERROR_ASSERT( pDocHandler
->m_iCharCount
== 33, "wrong char count" );
665 ERROR_ASSERT( pDocHandler
->m_iWhitespaceCount
== 0 , "wrong whitespace count" );
667 catch( SAXParseException
& e
) {
668 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
670 catch( SAXException
& e
) {
671 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
674 catch( Exception
& e
) {
675 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
678 BUILD_ERROR( 1 , "unknown exception" );
683 void OSaxParserTest::testEncoding( const XParserRef
&rParser
)
686 "<?xml version='1.0' encoding=\"iso-8859-1\"?>\n"
687 "<!-- all elements here are explicitly in the HTML namespace -->\n"
688 "<html:html xmlns:html='http://www.w3.org/TR/REC-html40'>\n"
689 "<html:head><html:title>Frobnostication</html:title></html:head>\n"
690 "<html:body><html:p>Moved to ß\n"
691 "<html:a href='http://frob.com'>here.</html:a></html:p></html:body>\n"
694 Sequence
<BYTE
> seqBytes( strlen( TestString
) );
695 memcpy( seqBytes
.getArray() , TestString
, strlen( TestString
) );
698 XInputStreamRef rInStream
;
701 rInStream
= createStreamFromSequence( seqBytes
, m_rFactory
);
702 sInput
= UString( L
"internal" );
707 source
.aInputStream
= rInStream
;
708 source
.sSystemId
= sInput
;
710 TestDocumentHandler
*pDocHandler
= new TestDocumentHandler( m_rFactory
, FALSE
);
711 XDocumentHandlerRef
rDocHandler( (XDocumentHandler
*) pDocHandler
, USR_QUERY
);
712 XEntityResolverRef
rEntityResolver( (XEntityResolver
*) pDocHandler
, USR_QUERY
);
714 rParser
->setDocumentHandler( rDocHandler
);
715 rParser
->setEntityResolver( rEntityResolver
);
717 rParser
->parseStream( source
);
719 catch( SAXParseException
& e
) {
720 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
722 catch( SAXException
& e
) {
723 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
726 catch( Exception
& e
) {
727 BUILD_ERROR( 1 , USTRING_TO_PCHAR( e
.Message
) );
730 BUILD_ERROR( 1 , "unknown exception" );
737 void OSaxParserTest::testFile( const XParserRef
& rParser
)
740 XInputStreamRef rInStream
= createStreamFromFile( "testsax.xml" , m_rFactory
);
741 UString sInput
= UString( PCHAR_TO_USTRING( "testsax.xml" ) );
744 if( rParser
.is() && rInStream
.is() ) {
747 source
.aInputStream
= rInStream
;
748 source
.sSystemId
= sInput
;
750 TestDocumentHandler
*pDocHandler
= new TestDocumentHandler( m_rFactory
, TRUE
);
751 XDocumentHandlerRef
rDocHandler( (XDocumentHandler
*) pDocHandler
, USR_QUERY
);
752 XEntityResolverRef
rEntityResolver( (XEntityResolver
*) pDocHandler
, USR_QUERY
);
753 XErrorHandlerRef
rErrorHandler( ( XErrorHandler
* )pDocHandler
, USR_QUERY
);
755 rParser
->setDocumentHandler( rDocHandler
);
756 rParser
->setEntityResolver( rEntityResolver
);
757 rParser
->setErrorHandler( rErrorHandler
);
760 rParser
->parseStream( source
);
762 catch( SAXParseException
& e
) {
764 any
.set( &e
, SAXParseException_getReflection() );
766 SAXParseException
*pEx
;
767 if( any
.getReflection() == SAXParseException_getReflection() ) {
768 pEx
= ( SAXParseException
* ) any
.get();
769 printf( "%s\n" , UStringToString( pEx
->Message
, CHARSET_SYSTEM
).GetStr() );
770 any
= pEx
->WrappedException
;
777 catch( SAXException
& e
) {
778 printf( "%s\n" , UStringToString( e
.Message
, CHARSET_SYSTEM
).GetStr() );
781 catch( Exception
& e
) {
782 printf( "normal exception ! %s\n", e
.getName() );
785 printf( "any exception !!!!\n" );
790 void OSaxParserTest::testPerformance( const XParserRef
& rParser
)
793 XInputStreamRef rInStream
= createStreamFromFile( "testPerformance.xml" , m_rFactory
);
794 UString sInput
= UString( PCHAR_TO_USTRING( "testperformance.xml" ) );
796 if( rParser
.is() && rInStream
.is() ) {
799 source
.aInputStream
= rInStream
;
800 source
.sSystemId
= sInput
;
802 TestDocumentHandler
*pDocHandler
= new TestDocumentHandler( m_rFactory
, FALSE
);
803 XDocumentHandlerRef
rDocHandler( (XDocumentHandler
*) pDocHandler
, USR_QUERY
);
804 XEntityResolverRef
rEntityResolver( (XEntityResolver
*) pDocHandler
, USR_QUERY
);
805 XErrorHandlerRef
rErrorHandler( ( XErrorHandler
* )pDocHandler
, USR_QUERY
);
807 rParser
->setDocumentHandler( rDocHandler
);
808 rParser
->setEntityResolver( rEntityResolver
);
809 rParser
->setErrorHandler( rErrorHandler
);
812 TimeValue aStartTime
, aEndTime
;
813 osl_getSystemTime( &aStartTime
);
814 rParser
->parseStream( source
);
815 osl_getSystemTime( &aEndTime
);
817 double fStart
= (double)aStartTime
.Seconds
+ ((double)aStartTime
.Nanosec
/ 1000000000.0);
818 double fEnd
= (double)aEndTime
.Seconds
+ ((double)aEndTime
.Nanosec
/ 1000000000.0);
820 printf( "Performance reading : %g s\n" , fEnd
- fStart
);
823 catch( SAXParseException
& e
) {
825 any
.set( &e
, SAXParseException_getReflection() );
827 SAXParseException
*pEx
;
828 if( any
.getReflection() == SAXParseException_getReflection() ) {
829 pEx
= ( SAXParseException
* ) any
.get();
830 printf( "%s\n" , UStringToString( pEx
->Message
, CHARSET_SYSTEM
).GetStr() );
831 any
= pEx
->WrappedException
;
838 catch( SAXException
& e
) {
839 printf( "%s\n" , UStringToString( e
.Message
, CHARSET_SYSTEM
).GetStr() );
842 catch( Exception
& e
) {
843 printf( "normal exception ! %s\n", e
.getName() );
846 printf( "any exception !!!!\n" );
855 BOOL EXTERN_SERVICE_CALLTYPE
exService_writeRegEntry(
856 const UNO_INTERFACE(XRegistryKey
)* xUnoKey
)
859 XRegistryKeyRef xKey
;
860 uno2smart(xKey
, *xUnoKey
);
862 UString str
= UString( L
"/" ) + OSaxParserTest_getImplementationName() + UString( L
"/UNO/SERVICES" );
863 XRegistryKeyRef xNewKey
= xKey
->createKey( str
);
864 xNewKey
->createKey( OSaxParserTest_getServiceName() );
866 str
= UString( L
"/" ) + OSaxWriterTest_getImplementationName() + UString( L
"/UNO/SERVICES" );
867 xNewKey
= xKey
->createKey( str
);
868 xNewKey
->createKey( OSaxWriterTest_getServiceName() );
874 UNO_INTERFACE(XInterface
) EXTERN_SERVICE_CALLTYPE exService_getFactory
876 const wchar_t* implementationName
,
877 const UNO_INTERFACE(XMultiServiceFactory
)* xUnoFact
,
878 const UNO_INTERFACE(XRegistryKey
)*
881 UNO_INTERFACE(XInterface
) xUnoRet
= {0, 0};
884 XMultiServiceFactoryRef xSMgr
;
885 UString
aImplementationName(implementationName
);
887 uno2smart(xSMgr
, *xUnoFact
);
889 if (aImplementationName
== OSaxWriterTest_getImplementationName() )
891 xRet
= createSingleFactory( xSMgr
, implementationName
,
892 OSaxWriterTest_CreateInstance
,
893 OSaxWriterTest_getSupportedServiceNames() );
895 else if (aImplementationName
== OSaxParserTest_getImplementationName() )
897 xRet
= createSingleFactory( xSMgr
, implementationName
,
898 OSaxParserTest_CreateInstance
,
899 OSaxParserTest_getSupportedServiceNames() );
903 smart2uno(xRet
, xUnoRet
);