1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <stdio.h> 28cdf0e10cSrcweir #include <string.h> 29cdf0e10cSrcweir #include <smart/com/sun/star/test/XSimpleTest.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <rtl/wstring.hxx> 32cdf0e10cSrcweir #include <osl/time.h> 33cdf0e10cSrcweir //#include <vos/dynload.hxx> 34cdf0e10cSrcweir //#include <vos/diagnose.hxx> 35cdf0e10cSrcweir #include <usr/weak.hxx> 36cdf0e10cSrcweir #include <tools/string.hxx> 37cdf0e10cSrcweir #include <vos/conditn.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <smart/com/sun/star/io/XOutputStream.hxx> 40cdf0e10cSrcweir #include <smart/com/sun/star/xml/sax/SAXParseException.hxx> 41cdf0e10cSrcweir #include <smart/com/sun/star/xml/sax/XParser.hxx> 42cdf0e10cSrcweir #include <smart/com/sun/star/xml/sax/XExtendedDocumentHandler.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <smart/com/sun/star/lang/XMultiServiceFactory.hxx> // for the multiservice-factories 45cdf0e10cSrcweir #include <usr/factoryhlp.hxx> 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <usr/reflserv.hxx> // for EXTERN_SERVICE_CALLTYPE 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include "factory.hxx" 50cdf0e10cSrcweir 51cdf0e10cSrcweir using namespace rtl; 52cdf0e10cSrcweir using namespace vos; 53cdf0e10cSrcweir using namespace usr; 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir #define BUILD_ERROR(expr, Message)\ 57cdf0e10cSrcweir {\ 58cdf0e10cSrcweir m_seqErrors.realloc( m_seqErrors.getLen() + 1 ); \ 59cdf0e10cSrcweir m_seqExceptions.realloc( m_seqExceptions.getLen() + 1 ); \ 60cdf0e10cSrcweir String str; \ 61cdf0e10cSrcweir str += __FILE__;\ 62cdf0e10cSrcweir str += " "; \ 63cdf0e10cSrcweir str += "(" ; \ 64cdf0e10cSrcweir str += __LINE__ ;\ 65cdf0e10cSrcweir str += ")\n";\ 66cdf0e10cSrcweir str += "[ " ; \ 67cdf0e10cSrcweir str += #expr; \ 68cdf0e10cSrcweir str += " ] : " ; \ 69cdf0e10cSrcweir str += Message; \ 70cdf0e10cSrcweir m_seqErrors.getArray()[ m_seqErrors.getLen()-1] = StringToUString( str , CHARSET_SYSTEM ); \ 71cdf0e10cSrcweir }\ 72cdf0e10cSrcweir ((void)0) 73cdf0e10cSrcweir 74cdf0e10cSrcweir 75cdf0e10cSrcweir #define WARNING_ASSERT(expr, Message) \ 76cdf0e10cSrcweir if( ! (expr) ) { \ 77cdf0e10cSrcweir m_seqWarnings.realloc( m_seqErrors.getLen() +1 ); \ 78cdf0e10cSrcweir String str;\ 79cdf0e10cSrcweir str += __FILE__;\ 80cdf0e10cSrcweir str += " "; \ 81cdf0e10cSrcweir str += "(" ; \ 82cdf0e10cSrcweir str += __LINE__ ;\ 83cdf0e10cSrcweir str += ")\n";\ 84cdf0e10cSrcweir str += "[ " ; \ 85cdf0e10cSrcweir str += #expr; \ 86cdf0e10cSrcweir str += " ] : " ; \ 87cdf0e10cSrcweir str += Message; \ 88cdf0e10cSrcweir m_seqWarnings.getArray()[ m_seqWarnings.getLen()-1] = StringToUString( str , CHARSET_SYSTEM ); \ 89cdf0e10cSrcweir return; \ 90cdf0e10cSrcweir }\ 91cdf0e10cSrcweir ((void)0) 92cdf0e10cSrcweir 93cdf0e10cSrcweir #define ERROR_ASSERT(expr, Message) \ 94cdf0e10cSrcweir if( ! (expr) ) { \ 95cdf0e10cSrcweir BUILD_ERROR(expr, Message );\ 96cdf0e10cSrcweir return; \ 97cdf0e10cSrcweir }\ 98cdf0e10cSrcweir ((void)0) 99cdf0e10cSrcweir 100cdf0e10cSrcweir #define ERROR_EXCEPTION_ASSERT(expr, Message, Exception) \ 101cdf0e10cSrcweir if( !(expr)) { \ 102cdf0e10cSrcweir BUILD_ERROR(expr,Message);\ 103cdf0e10cSrcweir m_seqExceptions.getArray()[ m_seqExceptions.getLen()-1] = UsrAny( Exception );\ 104cdf0e10cSrcweir return; \ 105cdf0e10cSrcweir } \ 106cdf0e10cSrcweir ((void)0) 107cdf0e10cSrcweir 108cdf0e10cSrcweir /**** 109cdf0e10cSrcweir * test szenarios : 110cdf0e10cSrcweir * 111cdf0e10cSrcweir * 112cdf0e10cSrcweir * 113cdf0e10cSrcweir ****/ 114cdf0e10cSrcweir 115cdf0e10cSrcweir 116cdf0e10cSrcweir 117cdf0e10cSrcweir class OSaxParserTest : 118cdf0e10cSrcweir public XSimpleTest, 119cdf0e10cSrcweir public OWeakObject 120cdf0e10cSrcweir { 121cdf0e10cSrcweir public: 122cdf0e10cSrcweir OSaxParserTest( const XMultiServiceFactoryRef & rFactory ) : m_rFactory( rFactory ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir public: // refcounting 128cdf0e10cSrcweir BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); 129cdf0e10cSrcweir void acquire() { OWeakObject::acquire(); } 130cdf0e10cSrcweir void release() { OWeakObject::release(); } 131cdf0e10cSrcweir void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); } 132cdf0e10cSrcweir 133cdf0e10cSrcweir public: 134cdf0e10cSrcweir virtual void testInvariant(const UString& TestName, const XInterfaceRef& TestObject) 135cdf0e10cSrcweir THROWS( ( IllegalArgumentException, 136cdf0e10cSrcweir UsrSystemException) ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir virtual INT32 test( const UString& TestName, 139cdf0e10cSrcweir const XInterfaceRef& TestObject, 140cdf0e10cSrcweir INT32 hTestHandle) THROWS( ( IllegalArgumentException, 141cdf0e10cSrcweir UsrSystemException) ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir virtual BOOL testPassed(void) THROWS( ( UsrSystemException) ); 144cdf0e10cSrcweir virtual Sequence< UString > getErrors(void) THROWS( (UsrSystemException) ); 145cdf0e10cSrcweir virtual Sequence< UsrAny > getErrorExceptions(void) THROWS( (UsrSystemException) ); 146cdf0e10cSrcweir virtual Sequence< UString > getWarnings(void) THROWS( (UsrSystemException) ); 147cdf0e10cSrcweir 148cdf0e10cSrcweir private: 149cdf0e10cSrcweir void testSimple( const XParserRef &r ); 150cdf0e10cSrcweir void testNamespaces( const XParserRef &r ); 151cdf0e10cSrcweir void testFile( const XParserRef &r ); 152cdf0e10cSrcweir void testEncoding( const XParserRef &rParser ); 153cdf0e10cSrcweir void testPerformance( const XParserRef &rParser ); 154cdf0e10cSrcweir 155cdf0e10cSrcweir private: 156cdf0e10cSrcweir Sequence<UsrAny> m_seqExceptions; 157cdf0e10cSrcweir Sequence<UString> m_seqErrors; 158cdf0e10cSrcweir Sequence<UString> m_seqWarnings; 159cdf0e10cSrcweir XMultiServiceFactoryRef m_rFactory; 160cdf0e10cSrcweir }; 161cdf0e10cSrcweir 162cdf0e10cSrcweir 163cdf0e10cSrcweir 164cdf0e10cSrcweir /** 165cdf0e10cSrcweir * for external binding 166cdf0e10cSrcweir * 167cdf0e10cSrcweir * 168cdf0e10cSrcweir **/ 169cdf0e10cSrcweir XInterfaceRef OSaxParserTest_CreateInstance( const XMultiServiceFactoryRef & rSMgr ) THROWS((Exception)) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir OSaxParserTest *p = new OSaxParserTest( rSMgr ); 172cdf0e10cSrcweir XInterfaceRef xService = *p; 173cdf0e10cSrcweir return xService; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir 177cdf0e10cSrcweir UString OSaxParserTest_getServiceName( ) THROWS( () ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir return L"test.com.sun.star.xml.sax.Parser"; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir UString OSaxParserTest_getImplementationName( ) THROWS( () ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir return L"test.extensions.xml.sax.Parser"; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir Sequence<UString> OSaxParserTest_getSupportedServiceNames( ) THROWS( () ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir Sequence<UString> aRet(1); 190cdf0e10cSrcweir 191cdf0e10cSrcweir aRet.getArray()[0] = OSaxParserTest_getImplementationName( ); 192cdf0e10cSrcweir 193cdf0e10cSrcweir return aRet; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir 197cdf0e10cSrcweir BOOL OSaxParserTest::queryInterface( Uik uik , XInterfaceRef &rOut ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir if( XSimpleTest::getSmartUik() == uik ) { 200cdf0e10cSrcweir rOut = (XSimpleTest *) this; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir else { 203cdf0e10cSrcweir return OWeakObject::queryInterface( uik , rOut ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir return TRUE; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir 209cdf0e10cSrcweir void OSaxParserTest::testInvariant( const UString& TestName, const XInterfaceRef& TestObject ) 210cdf0e10cSrcweir THROWS( ( IllegalArgumentException, 211cdf0e10cSrcweir UsrSystemException) ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir if( L"com.sun.star.xml.sax.Parser" == TestName ) { 214cdf0e10cSrcweir XParserRef parser( TestObject , USR_QUERY ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir ERROR_ASSERT( parser.is() , "XDataInputStream cannot be queried" ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir 221cdf0e10cSrcweir INT32 OSaxParserTest::test( const UString& TestName, 222cdf0e10cSrcweir const XInterfaceRef& TestObject, 223cdf0e10cSrcweir INT32 hTestHandle) THROWS( ( IllegalArgumentException, 224cdf0e10cSrcweir UsrSystemException) ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir if( L"com.sun.star.xml.sax.Parser" == TestName ) { 227cdf0e10cSrcweir try { 228cdf0e10cSrcweir if( 0 == hTestHandle ) { 229cdf0e10cSrcweir testInvariant( TestName , TestObject ); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir else { 232cdf0e10cSrcweir 233cdf0e10cSrcweir XParserRef parser( TestObject , USR_QUERY ); 234cdf0e10cSrcweir 235cdf0e10cSrcweir if( 1 == hTestHandle ) { 236cdf0e10cSrcweir testSimple( parser ); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir else if( 2 == hTestHandle ) { 239cdf0e10cSrcweir testNamespaces( parser ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir else if( 3 == hTestHandle ) { 242cdf0e10cSrcweir testEncoding( parser ); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir else if( 4 == hTestHandle ) { 245cdf0e10cSrcweir testFile( parser ); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir else if( 5 == hTestHandle ) { 248cdf0e10cSrcweir testPerformance( parser ); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir } 251cdf0e10cSrcweir } 252cdf0e10cSrcweir catch( Exception& e ) { 253cdf0e10cSrcweir BUILD_ERROR( 0 , UStringToString( e.getName() , CHARSET_SYSTEM ).GetCharStr() ); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir catch(...) { 256cdf0e10cSrcweir BUILD_ERROR( 0 , "unknown exception (Exception is not base class)" ); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir hTestHandle ++; 260cdf0e10cSrcweir 261cdf0e10cSrcweir if( hTestHandle >= 6) { 262cdf0e10cSrcweir // all tests finished. 263cdf0e10cSrcweir hTestHandle = -1; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir } 266cdf0e10cSrcweir else { 267cdf0e10cSrcweir BUILD_ERROR( 0 , "service not supported by test." ); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir return hTestHandle; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir 273cdf0e10cSrcweir 274cdf0e10cSrcweir BOOL OSaxParserTest::testPassed(void) THROWS( (UsrSystemException) ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir return m_seqErrors.getLen() == 0; 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir 280cdf0e10cSrcweir Sequence< UString > OSaxParserTest::getErrors(void) THROWS( (UsrSystemException) ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir return m_seqErrors; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir 286cdf0e10cSrcweir Sequence< UsrAny > OSaxParserTest::getErrorExceptions(void) THROWS( (UsrSystemException) ) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir return m_seqExceptions; 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir 292cdf0e10cSrcweir Sequence< UString > OSaxParserTest::getWarnings(void) THROWS( (UsrSystemException) ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir return m_seqWarnings; 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir XInputStreamRef createStreamFromSequence( const Sequence<BYTE> seqBytes , XMultiServiceFactoryRef &xSMgr ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir XInterfaceRef xOutStreamService = xSMgr->createInstance( L"com.sun.star.io.Pipe" ); 300cdf0e10cSrcweir OSL_ASSERT( xOutStreamService.is() ); 301cdf0e10cSrcweir XOutputStreamRef rOutStream( xOutStreamService , USR_QUERY ); 302cdf0e10cSrcweir OSL_ASSERT( rOutStream.is() ); 303cdf0e10cSrcweir 304cdf0e10cSrcweir XInputStreamRef rInStream( xOutStreamService , USR_QUERY ); 305cdf0e10cSrcweir OSL_ASSERT( rInStream.is() ); 306cdf0e10cSrcweir 307cdf0e10cSrcweir rOutStream->writeBytes( seqBytes ); 308cdf0e10cSrcweir rOutStream->flush(); 309cdf0e10cSrcweir rOutStream->closeOutput(); 310cdf0e10cSrcweir 311cdf0e10cSrcweir return rInStream; 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir XInputStreamRef createStreamFromFile( const char *pcFile , XMultiServiceFactoryRef &xSMgr ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir FILE *f = fopen( pcFile , "rb" ); 317cdf0e10cSrcweir XInputStreamRef r; 318cdf0e10cSrcweir 319cdf0e10cSrcweir if( f ) { 320cdf0e10cSrcweir fseek( f , 0 , SEEK_END ); 321cdf0e10cSrcweir int nLength = ftell( f ); 322cdf0e10cSrcweir fseek( f , 0 , SEEK_SET ); 323cdf0e10cSrcweir 324cdf0e10cSrcweir Sequence<BYTE> seqIn(nLength); 325cdf0e10cSrcweir fread( seqIn.getArray() , nLength , 1 , f ); 326cdf0e10cSrcweir 327cdf0e10cSrcweir r = createStreamFromSequence( seqIn , xSMgr ); 328cdf0e10cSrcweir fclose( f ); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir return r; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir 333cdf0e10cSrcweir 334cdf0e10cSrcweir 335cdf0e10cSrcweir 336cdf0e10cSrcweir 337cdf0e10cSrcweir 338cdf0e10cSrcweir 339cdf0e10cSrcweir 340cdf0e10cSrcweir 341cdf0e10cSrcweir #define PCHAR_TO_USTRING(x) StringToUString(String(x),CHARSET_PC_1252) 342cdf0e10cSrcweir #define USTRING_TO_PCHAR(x) UStringToString(x,CHARSET_PC_437).GetStr() 343cdf0e10cSrcweir 344cdf0e10cSrcweir 345cdf0e10cSrcweir 346cdf0e10cSrcweir class TestDocumentHandler : 347cdf0e10cSrcweir public XExtendedDocumentHandler, 348cdf0e10cSrcweir public XEntityResolver, 349cdf0e10cSrcweir public XErrorHandler, 350cdf0e10cSrcweir public OWeakObject 351cdf0e10cSrcweir { 352cdf0e10cSrcweir public: 353cdf0e10cSrcweir TestDocumentHandler( XMultiServiceFactoryRef &r , BOOL bPrint ) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir m_xSMgr = r; 356cdf0e10cSrcweir m_bPrint = bPrint; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir 360cdf0e10cSrcweir public: 361cdf0e10cSrcweir BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); 362cdf0e10cSrcweir void acquire() { OWeakObject::acquire(); } 363cdf0e10cSrcweir void release() { OWeakObject::release(); } 364cdf0e10cSrcweir void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); } 365cdf0e10cSrcweir 366cdf0e10cSrcweir 367cdf0e10cSrcweir public: // Error handler 368cdf0e10cSrcweir virtual void error(const UsrAny& aSAXParseException) THROWS( (SAXException, UsrSystemException) ) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir printf( "Error !\n" ); 371cdf0e10cSrcweir THROW( SAXException( L"error from error handler" , XInterfaceRef() , aSAXParseException ) ); 372cdf0e10cSrcweir } 373cdf0e10cSrcweir virtual void fatalError(const UsrAny& aSAXParseException) THROWS( (SAXException, UsrSystemException) ) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir printf( "Fatal Error !\n" ); 376cdf0e10cSrcweir } 377cdf0e10cSrcweir virtual void warning(const UsrAny& aSAXParseException) THROWS( (SAXException, UsrSystemException) ) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir printf( "Warning !\n" ); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir 382cdf0e10cSrcweir 383cdf0e10cSrcweir public: // ExtendedDocumentHandler 384cdf0e10cSrcweir 385cdf0e10cSrcweir virtual void startDocument(void) THROWS( (SAXException, UsrSystemException) ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir m_iLevel = 0; 388cdf0e10cSrcweir m_iElementCount = 0; 389cdf0e10cSrcweir m_iAttributeCount = 0; 390cdf0e10cSrcweir m_iWhitespaceCount =0; 391cdf0e10cSrcweir m_iCharCount=0; 392cdf0e10cSrcweir if( m_bPrint ) { 393cdf0e10cSrcweir printf( "document started\n" ); 394cdf0e10cSrcweir } 395cdf0e10cSrcweir } 396cdf0e10cSrcweir virtual void endDocument(void) THROWS( (SAXException, UsrSystemException) ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir if( m_bPrint ) { 399cdf0e10cSrcweir printf( "document finished\n" ); 400cdf0e10cSrcweir printf( "(ElementCount %d),(AttributeCount %d),(WhitespaceCount %d),(CharCount %d)\n", 401cdf0e10cSrcweir m_iElementCount, m_iAttributeCount, m_iWhitespaceCount , m_iCharCount ); 402cdf0e10cSrcweir } 403cdf0e10cSrcweir } 404cdf0e10cSrcweir virtual void startElement(const UString& aName, const XAttributeListRef& xAttribs) 405cdf0e10cSrcweir THROWS( (SAXException,UsrSystemException) ) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir 408cdf0e10cSrcweir if( m_rLocator.is() ) { 409cdf0e10cSrcweir if( m_bPrint ) 410cdf0e10cSrcweir printf( "%s(%d):" , USTRING_TO_PCHAR( m_rLocator->getSystemId() ) , 411cdf0e10cSrcweir m_rLocator->getLineNumber() ); 412cdf0e10cSrcweir } 413cdf0e10cSrcweir if( m_bPrint ) { 414cdf0e10cSrcweir int i; 415cdf0e10cSrcweir for( i = 0; i < m_iLevel ; i ++ ) { 416cdf0e10cSrcweir printf( " " ); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir printf( "<%s> " , USTRING_TO_PCHAR( aName ) ); 419cdf0e10cSrcweir 420cdf0e10cSrcweir for( i = 0 ; i < xAttribs->getLength() ; i ++ ) { 421cdf0e10cSrcweir printf( "(%s,%s,'%s')" , USTRING_TO_PCHAR( xAttribs->getNameByIndex( i ) ) , 422cdf0e10cSrcweir USTRING_TO_PCHAR( xAttribs->getTypeByIndex( i ) ) , 423cdf0e10cSrcweir USTRING_TO_PCHAR( xAttribs->getValueByIndex( i ) ) ); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir printf( "\n" ); 426cdf0e10cSrcweir } 427cdf0e10cSrcweir m_iLevel ++; 428cdf0e10cSrcweir m_iElementCount ++; 429cdf0e10cSrcweir m_iAttributeCount += xAttribs->getLength(); 430cdf0e10cSrcweir } 431cdf0e10cSrcweir virtual void endElement(const UString& aName) THROWS( (SAXException,UsrSystemException) ) 432cdf0e10cSrcweir { 433cdf0e10cSrcweir OSL_ASSERT( m_iLevel ); 434cdf0e10cSrcweir m_iLevel --; 435cdf0e10cSrcweir if( m_bPrint ) { 436cdf0e10cSrcweir int i; 437cdf0e10cSrcweir for( i = 0; i < m_iLevel ; i ++ ) { 438cdf0e10cSrcweir printf( " " ); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir printf( "</%s>\n" , USTRING_TO_PCHAR( aName ) ); 441cdf0e10cSrcweir } 442cdf0e10cSrcweir } 443cdf0e10cSrcweir 444cdf0e10cSrcweir virtual void characters(const UString& aChars) THROWS( (SAXException,UsrSystemException) ) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir if( m_bPrint ) { 447cdf0e10cSrcweir int i; 448cdf0e10cSrcweir for( i = 0; i < m_iLevel ; i ++ ) { 449cdf0e10cSrcweir printf( " " ); 450cdf0e10cSrcweir } 451cdf0e10cSrcweir printf( "%s\n" , USTRING_TO_PCHAR( aChars ) ); 452cdf0e10cSrcweir } 453cdf0e10cSrcweir m_iCharCount += aChars.len(); 454cdf0e10cSrcweir } 455cdf0e10cSrcweir virtual void ignorableWhitespace(const UString& aWhitespaces) THROWS( (SAXException,UsrSystemException) ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir m_iWhitespaceCount += aWhitespaces.len(); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir 460cdf0e10cSrcweir virtual void processingInstruction(const UString& aTarget, const UString& aData) THROWS( (SAXException,UsrSystemException) ) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir if( m_bPrint ) 463cdf0e10cSrcweir printf( "PI : %s,%s\n" , USTRING_TO_PCHAR( aTarget ) , USTRING_TO_PCHAR( aData ) ); 464cdf0e10cSrcweir } 465cdf0e10cSrcweir 466cdf0e10cSrcweir virtual void setDocumentLocator(const XLocatorRef& xLocator) THROWS( (SAXException,UsrSystemException) ) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir m_rLocator = xLocator; 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir virtual InputSource resolveEntity(const UString& sPublicId, const UString& sSystemId) 472cdf0e10cSrcweir THROWS( (SAXException,UsrSystemException) ) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir InputSource source; 475cdf0e10cSrcweir source.sSystemId = sSystemId; 476cdf0e10cSrcweir source.sPublicId = sPublicId; 477cdf0e10cSrcweir source.aInputStream = createStreamFromFile( USTRING_TO_PCHAR( sSystemId ) , m_xSMgr ); 478cdf0e10cSrcweir 479cdf0e10cSrcweir return source; 480cdf0e10cSrcweir } 481cdf0e10cSrcweir 482cdf0e10cSrcweir virtual void startCDATA(void) THROWS( (SAXException,UsrSystemException) ) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir if( m_bPrint ) { 485cdf0e10cSrcweir printf( "CDataStart :\n" ); 486cdf0e10cSrcweir } 487cdf0e10cSrcweir } 488cdf0e10cSrcweir virtual void endCDATA(void) THROWS( (SAXException,UsrSystemException) ) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir if( m_bPrint ) { 491cdf0e10cSrcweir printf( "CEndStart :\n" ); 492cdf0e10cSrcweir } 493cdf0e10cSrcweir } 494cdf0e10cSrcweir virtual void comment(const UString& sComment) THROWS( (SAXException,UsrSystemException) ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir if( m_bPrint ) { 497cdf0e10cSrcweir printf( "<!--%s-->\n" , USTRING_TO_PCHAR( sComment ) ); 498cdf0e10cSrcweir } 499cdf0e10cSrcweir } 500cdf0e10cSrcweir virtual void unknown(const UString& sString) THROWS( (SAXException,UsrSystemException) ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir if( m_bPrint ) { 503cdf0e10cSrcweir printf( "UNKNOWN : {%s}\n" , USTRING_TO_PCHAR( sString ) ); 504cdf0e10cSrcweir } 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir virtual void allowLineBreak( void) THROWS( (SAXException, UsrSystemException ) ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir 510cdf0e10cSrcweir } 511cdf0e10cSrcweir 512cdf0e10cSrcweir 513cdf0e10cSrcweir public: 514cdf0e10cSrcweir int m_iLevel; 515cdf0e10cSrcweir int m_iElementCount; 516cdf0e10cSrcweir int m_iAttributeCount; 517cdf0e10cSrcweir int m_iWhitespaceCount; 518cdf0e10cSrcweir int m_iCharCount; 519cdf0e10cSrcweir BOOL m_bPrint; 520cdf0e10cSrcweir 521cdf0e10cSrcweir XMultiServiceFactoryRef m_xSMgr; 522cdf0e10cSrcweir XLocatorRef m_rLocator; 523cdf0e10cSrcweir }; 524cdf0e10cSrcweir 525cdf0e10cSrcweir BOOL TestDocumentHandler::queryInterface( Uik aUik , XInterfaceRef & rOut ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir if( aUik == XDocumentHandler::getSmartUik() ) { 528cdf0e10cSrcweir rOut = (XDocumentHandler * )this; 529cdf0e10cSrcweir } 530cdf0e10cSrcweir else if ( aUik == XExtendedDocumentHandler::getSmartUik() ) { 531cdf0e10cSrcweir rOut = (XExtendedDocumentHandler *) this; 532cdf0e10cSrcweir } 533cdf0e10cSrcweir else if ( aUik == XEntityResolver::getSmartUik() ) { 534cdf0e10cSrcweir rOut = (XEntityResolver *) this; 535cdf0e10cSrcweir } 536cdf0e10cSrcweir else if ( aUik == XErrorHandler::getSmartUik() ) { 537cdf0e10cSrcweir rOut = (XErrorHandler * ) this; 538cdf0e10cSrcweir } 539cdf0e10cSrcweir else { 540cdf0e10cSrcweir return OWeakObject::queryInterface( aUik , rOut ); 541cdf0e10cSrcweir } 542cdf0e10cSrcweir return TRUE; 543cdf0e10cSrcweir } 544cdf0e10cSrcweir 545cdf0e10cSrcweir 546cdf0e10cSrcweir 547cdf0e10cSrcweir 548cdf0e10cSrcweir void OSaxParserTest::testSimple( const XParserRef &rParser ) 549cdf0e10cSrcweir { 550cdf0e10cSrcweir 551cdf0e10cSrcweir char TestString[] = 552cdf0e10cSrcweir "<!DOCTYPE personnel [\n" 553cdf0e10cSrcweir "<!ENTITY testInternal \"internal Test!\">\n" 554cdf0e10cSrcweir "<!ENTITY test SYSTEM \"external_entity.xml\">\n" 555cdf0e10cSrcweir "]>\n" 556cdf0e10cSrcweir 557cdf0e10cSrcweir "<personnel>\n" 558cdf0e10cSrcweir "<person> fjklsfdklsdfkl\n" 559cdf0e10cSrcweir "fjklsfdklsdfkl\n" 560cdf0e10cSrcweir "<?testpi pidata?>\n" 561cdf0e10cSrcweir "&testInternal;\n" 562cdf0e10cSrcweir "<HUHU x='5' y='kjfd'> blahuhu\n" 563cdf0e10cSrcweir "<HI> blahi\n" 564cdf0e10cSrcweir " <![CDATA[<greeting>Hello, '+1+12world!</greeting>]]>\n" 565cdf0e10cSrcweir " <!-- huhu <jdk> -->\n" 566cdf0e10cSrcweir "<?testpi pidata?>\n" 567cdf0e10cSrcweir "</HI>\n" 568cdf0e10cSrcweir "aus XMLTest\n" 569cdf0e10cSrcweir "</HUHU>\n" 570cdf0e10cSrcweir "</person>\n" 571cdf0e10cSrcweir "</personnel>\n\n\n"; 572cdf0e10cSrcweir 573cdf0e10cSrcweir Sequence<BYTE> seqBytes( strlen( TestString ) ); 574cdf0e10cSrcweir memcpy( seqBytes.getArray() , TestString , strlen( TestString ) ); 575cdf0e10cSrcweir 576cdf0e10cSrcweir 577cdf0e10cSrcweir XInputStreamRef rInStream; 578cdf0e10cSrcweir UString sInput; 579cdf0e10cSrcweir rInStream = createStreamFromSequence( seqBytes , m_rFactory ); 580cdf0e10cSrcweir sInput = UString( L"internal" ); 581cdf0e10cSrcweir 582cdf0e10cSrcweir if( rParser.is() ) { 583cdf0e10cSrcweir InputSource source; 584cdf0e10cSrcweir 585cdf0e10cSrcweir source.aInputStream = rInStream; 586cdf0e10cSrcweir source.sSystemId = sInput; 587cdf0e10cSrcweir 588cdf0e10cSrcweir TestDocumentHandler *pDocHandler = new TestDocumentHandler( m_rFactory , FALSE ); 589cdf0e10cSrcweir XDocumentHandlerRef rDocHandler( (XDocumentHandler *) pDocHandler , USR_QUERY ); 590cdf0e10cSrcweir XEntityResolverRef rEntityResolver( (XEntityResolver *) pDocHandler , USR_QUERY ); 591cdf0e10cSrcweir 592cdf0e10cSrcweir rParser->setDocumentHandler( rDocHandler ); 593cdf0e10cSrcweir rParser->setEntityResolver( rEntityResolver ); 594cdf0e10cSrcweir 595cdf0e10cSrcweir try { 596cdf0e10cSrcweir rParser->parseStream( source ); 597cdf0e10cSrcweir ERROR_ASSERT( pDocHandler->m_iElementCount == 4 , "wrong element count" ); 598cdf0e10cSrcweir ERROR_ASSERT( pDocHandler->m_iAttributeCount == 2 , "wrong attribut count" ); 599cdf0e10cSrcweir ERROR_ASSERT( pDocHandler->m_iCharCount == 130 , "wrong char count" ); 600cdf0e10cSrcweir ERROR_ASSERT( pDocHandler->m_iWhitespaceCount == 0, "wrong whitespace count" ); 601cdf0e10cSrcweir } 602cdf0e10cSrcweir catch( SAXParseException& e ) { 603cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 604cdf0e10cSrcweir } 605cdf0e10cSrcweir catch( SAXException& e ) { 606cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 607cdf0e10cSrcweir 608cdf0e10cSrcweir } 609cdf0e10cSrcweir catch( Exception& e ) { 610cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 611cdf0e10cSrcweir } 612cdf0e10cSrcweir catch(...) { 613cdf0e10cSrcweir BUILD_ERROR( 1 , "unknown exception" ); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir 616cdf0e10cSrcweir } 617cdf0e10cSrcweir 618cdf0e10cSrcweir 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir void OSaxParserTest::testNamespaces( const XParserRef &rParser ) 622cdf0e10cSrcweir { 623cdf0e10cSrcweir 624cdf0e10cSrcweir char TestString[] = 625cdf0e10cSrcweir "<?xml version='1.0'?>\n" 626cdf0e10cSrcweir "<!-- all elements here are explicitly in the HTML namespace -->\n" 627cdf0e10cSrcweir "<html:html xmlns:html='http://www.w3.org/TR/REC-html40'>\n" 628cdf0e10cSrcweir "<html:head><html:title>Frobnostication</html:title></html:head>\n" 629cdf0e10cSrcweir "<html:body><html:p>Moved to \n" 630cdf0e10cSrcweir "<html:a href='http://frob.com'>here.</html:a></html:p></html:body>\n" 631cdf0e10cSrcweir "</html:html>\n"; 632cdf0e10cSrcweir 633cdf0e10cSrcweir Sequence<BYTE> seqBytes( strlen( TestString ) ); 634cdf0e10cSrcweir memcpy( seqBytes.getArray() , TestString , strlen( TestString ) ); 635cdf0e10cSrcweir 636cdf0e10cSrcweir 637cdf0e10cSrcweir XInputStreamRef rInStream; 638cdf0e10cSrcweir UString sInput; 639cdf0e10cSrcweir 640cdf0e10cSrcweir rInStream = createStreamFromSequence( seqBytes , m_rFactory ); 641cdf0e10cSrcweir sInput = UString( L"internal" ); 642cdf0e10cSrcweir 643cdf0e10cSrcweir if( rParser.is() ) { 644cdf0e10cSrcweir InputSource source; 645cdf0e10cSrcweir 646cdf0e10cSrcweir source.aInputStream = rInStream; 647cdf0e10cSrcweir source.sSystemId = sInput; 648cdf0e10cSrcweir 649cdf0e10cSrcweir TestDocumentHandler *pDocHandler = new TestDocumentHandler( m_rFactory , FALSE ); 650cdf0e10cSrcweir XDocumentHandlerRef rDocHandler( (XDocumentHandler *) pDocHandler , USR_QUERY ); 651cdf0e10cSrcweir XEntityResolverRef rEntityResolver( (XEntityResolver *) pDocHandler , USR_QUERY ); 652cdf0e10cSrcweir 653cdf0e10cSrcweir rParser->setDocumentHandler( rDocHandler ); 654cdf0e10cSrcweir rParser->setEntityResolver( rEntityResolver ); 655cdf0e10cSrcweir 656cdf0e10cSrcweir try { 657cdf0e10cSrcweir rParser->parseStream( source ); 658cdf0e10cSrcweir ERROR_ASSERT( pDocHandler->m_iElementCount == 6 , "wrong element count" ); 659cdf0e10cSrcweir ERROR_ASSERT( pDocHandler->m_iAttributeCount == 2 , "wrong attribut count" ); 660cdf0e10cSrcweir ERROR_ASSERT( pDocHandler->m_iCharCount == 33, "wrong char count" ); 661cdf0e10cSrcweir ERROR_ASSERT( pDocHandler->m_iWhitespaceCount == 0 , "wrong whitespace count" ); 662cdf0e10cSrcweir } 663cdf0e10cSrcweir catch( SAXParseException& e ) { 664cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 665cdf0e10cSrcweir } 666cdf0e10cSrcweir catch( SAXException& e ) { 667cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 668cdf0e10cSrcweir 669cdf0e10cSrcweir } 670cdf0e10cSrcweir catch( Exception& e ) { 671cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 672cdf0e10cSrcweir } 673cdf0e10cSrcweir catch(...) { 674cdf0e10cSrcweir BUILD_ERROR( 1 , "unknown exception" ); 675cdf0e10cSrcweir } 676cdf0e10cSrcweir } 677cdf0e10cSrcweir } 678cdf0e10cSrcweir 679cdf0e10cSrcweir void OSaxParserTest::testEncoding( const XParserRef &rParser ) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir char TestString[] = 682cdf0e10cSrcweir "<?xml version='1.0' encoding=\"iso-8859-1\"?>\n" 683cdf0e10cSrcweir "<!-- all elements here are explicitly in the HTML namespace -->\n" 684cdf0e10cSrcweir "<html:html xmlns:html='http://www.w3.org/TR/REC-html40'>\n" 685cdf0e10cSrcweir "<html:head><html:title>Frobnostication</html:title></html:head>\n" 686cdf0e10cSrcweir "<html:body><html:p>Moved to �\n" 687cdf0e10cSrcweir "<html:a href='http://frob.com'>here.</html:a></html:p></html:body>\n" 688cdf0e10cSrcweir "</html:html>\n"; 689cdf0e10cSrcweir 690cdf0e10cSrcweir Sequence<BYTE> seqBytes( strlen( TestString ) ); 691cdf0e10cSrcweir memcpy( seqBytes.getArray() , TestString , strlen( TestString ) ); 692cdf0e10cSrcweir 693cdf0e10cSrcweir 694cdf0e10cSrcweir XInputStreamRef rInStream; 695cdf0e10cSrcweir UString sInput; 696cdf0e10cSrcweir 697cdf0e10cSrcweir rInStream = createStreamFromSequence( seqBytes , m_rFactory ); 698cdf0e10cSrcweir sInput = UString( L"internal" ); 699cdf0e10cSrcweir 700cdf0e10cSrcweir if( rParser.is() ) { 701cdf0e10cSrcweir InputSource source; 702cdf0e10cSrcweir 703cdf0e10cSrcweir source.aInputStream = rInStream; 704cdf0e10cSrcweir source.sSystemId = sInput; 705cdf0e10cSrcweir 706cdf0e10cSrcweir TestDocumentHandler *pDocHandler = new TestDocumentHandler( m_rFactory , FALSE ); 707cdf0e10cSrcweir XDocumentHandlerRef rDocHandler( (XDocumentHandler *) pDocHandler , USR_QUERY ); 708cdf0e10cSrcweir XEntityResolverRef rEntityResolver( (XEntityResolver *) pDocHandler , USR_QUERY ); 709cdf0e10cSrcweir 710cdf0e10cSrcweir rParser->setDocumentHandler( rDocHandler ); 711cdf0e10cSrcweir rParser->setEntityResolver( rEntityResolver ); 712cdf0e10cSrcweir try { 713cdf0e10cSrcweir rParser->parseStream( source ); 714cdf0e10cSrcweir } 715cdf0e10cSrcweir catch( SAXParseException& e ) { 716cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 717cdf0e10cSrcweir } 718cdf0e10cSrcweir catch( SAXException& e ) { 719cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 720cdf0e10cSrcweir 721cdf0e10cSrcweir } 722cdf0e10cSrcweir catch( Exception& e ) { 723cdf0e10cSrcweir BUILD_ERROR( 1 , USTRING_TO_PCHAR( e.Message ) ); 724cdf0e10cSrcweir } 725cdf0e10cSrcweir catch(...) { 726cdf0e10cSrcweir BUILD_ERROR( 1 , "unknown exception" ); 727cdf0e10cSrcweir } 728cdf0e10cSrcweir 729cdf0e10cSrcweir } 730cdf0e10cSrcweir 731cdf0e10cSrcweir } 732cdf0e10cSrcweir 733cdf0e10cSrcweir void OSaxParserTest::testFile( const XParserRef & rParser ) 734cdf0e10cSrcweir { 735cdf0e10cSrcweir 736cdf0e10cSrcweir XInputStreamRef rInStream = createStreamFromFile( "testsax.xml" , m_rFactory ); 737cdf0e10cSrcweir UString sInput = UString( PCHAR_TO_USTRING( "testsax.xml" ) ); 738cdf0e10cSrcweir 739cdf0e10cSrcweir 740cdf0e10cSrcweir if( rParser.is() && rInStream.is() ) { 741cdf0e10cSrcweir InputSource source; 742cdf0e10cSrcweir 743cdf0e10cSrcweir source.aInputStream = rInStream; 744cdf0e10cSrcweir source.sSystemId = sInput; 745cdf0e10cSrcweir 746cdf0e10cSrcweir TestDocumentHandler *pDocHandler = new TestDocumentHandler( m_rFactory , TRUE ); 747cdf0e10cSrcweir XDocumentHandlerRef rDocHandler( (XDocumentHandler *) pDocHandler , USR_QUERY ); 748cdf0e10cSrcweir XEntityResolverRef rEntityResolver( (XEntityResolver *) pDocHandler , USR_QUERY ); 749cdf0e10cSrcweir XErrorHandlerRef rErrorHandler( ( XErrorHandler * )pDocHandler , USR_QUERY ); 750cdf0e10cSrcweir 751cdf0e10cSrcweir rParser->setDocumentHandler( rDocHandler ); 752cdf0e10cSrcweir rParser->setEntityResolver( rEntityResolver ); 753cdf0e10cSrcweir rParser->setErrorHandler( rErrorHandler ); 754cdf0e10cSrcweir 755cdf0e10cSrcweir try { 756cdf0e10cSrcweir rParser->parseStream( source ); 757cdf0e10cSrcweir } 758cdf0e10cSrcweir catch( SAXParseException& e ) { 759cdf0e10cSrcweir UsrAny any; 760cdf0e10cSrcweir any.set( &e , SAXParseException_getReflection() ); 761cdf0e10cSrcweir while(TRUE) { 762cdf0e10cSrcweir SAXParseException *pEx; 763cdf0e10cSrcweir if( any.getReflection() == SAXParseException_getReflection() ) { 764cdf0e10cSrcweir pEx = ( SAXParseException * ) any.get(); 765cdf0e10cSrcweir printf( "%s\n" , UStringToString( pEx->Message , CHARSET_SYSTEM ).GetStr() ); 766cdf0e10cSrcweir any = pEx->WrappedException; 767cdf0e10cSrcweir } 768cdf0e10cSrcweir else { 769cdf0e10cSrcweir break; 770cdf0e10cSrcweir } 771cdf0e10cSrcweir } 772cdf0e10cSrcweir } 773cdf0e10cSrcweir catch( SAXException& e ) { 774cdf0e10cSrcweir printf( "%s\n" , UStringToString( e.Message , CHARSET_SYSTEM ).GetStr() ); 775cdf0e10cSrcweir 776cdf0e10cSrcweir } 777cdf0e10cSrcweir catch( Exception& e ) { 778cdf0e10cSrcweir printf( "normal exception ! %s\n", e.getName() ); 779cdf0e10cSrcweir } 780cdf0e10cSrcweir catch(...) { 781cdf0e10cSrcweir printf( "any exception !!!!\n" ); 782cdf0e10cSrcweir } 783cdf0e10cSrcweir } 784cdf0e10cSrcweir } 785cdf0e10cSrcweir 786cdf0e10cSrcweir void OSaxParserTest::testPerformance( const XParserRef & rParser ) 787cdf0e10cSrcweir { 788cdf0e10cSrcweir 789cdf0e10cSrcweir XInputStreamRef rInStream = createStreamFromFile( "testPerformance.xml" , m_rFactory ); 790cdf0e10cSrcweir UString sInput = UString( PCHAR_TO_USTRING( "testperformance.xml" ) ); 791cdf0e10cSrcweir 792cdf0e10cSrcweir if( rParser.is() && rInStream.is() ) { 793cdf0e10cSrcweir InputSource source; 794cdf0e10cSrcweir 795cdf0e10cSrcweir source.aInputStream = rInStream; 796cdf0e10cSrcweir source.sSystemId = sInput; 797cdf0e10cSrcweir 798cdf0e10cSrcweir TestDocumentHandler *pDocHandler = new TestDocumentHandler( m_rFactory , FALSE ); 799cdf0e10cSrcweir XDocumentHandlerRef rDocHandler( (XDocumentHandler *) pDocHandler , USR_QUERY ); 800cdf0e10cSrcweir XEntityResolverRef rEntityResolver( (XEntityResolver *) pDocHandler , USR_QUERY ); 801cdf0e10cSrcweir XErrorHandlerRef rErrorHandler( ( XErrorHandler * )pDocHandler , USR_QUERY ); 802cdf0e10cSrcweir 803cdf0e10cSrcweir rParser->setDocumentHandler( rDocHandler ); 804cdf0e10cSrcweir rParser->setEntityResolver( rEntityResolver ); 805cdf0e10cSrcweir rParser->setErrorHandler( rErrorHandler ); 806cdf0e10cSrcweir 807cdf0e10cSrcweir try { 808cdf0e10cSrcweir TimeValue aStartTime, aEndTime; 809cdf0e10cSrcweir osl_getSystemTime( &aStartTime ); 810cdf0e10cSrcweir rParser->parseStream( source ); 811cdf0e10cSrcweir osl_getSystemTime( &aEndTime ); 812cdf0e10cSrcweir 813cdf0e10cSrcweir double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0); 814cdf0e10cSrcweir double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0); 815cdf0e10cSrcweir 816cdf0e10cSrcweir printf( "Performance reading : %g s\n" , fEnd - fStart ); 817cdf0e10cSrcweir 818cdf0e10cSrcweir } 819cdf0e10cSrcweir catch( SAXParseException& e ) { 820cdf0e10cSrcweir UsrAny any; 821cdf0e10cSrcweir any.set( &e , SAXParseException_getReflection() ); 822cdf0e10cSrcweir while(TRUE) { 823cdf0e10cSrcweir SAXParseException *pEx; 824cdf0e10cSrcweir if( any.getReflection() == SAXParseException_getReflection() ) { 825cdf0e10cSrcweir pEx = ( SAXParseException * ) any.get(); 826cdf0e10cSrcweir printf( "%s\n" , UStringToString( pEx->Message , CHARSET_SYSTEM ).GetStr() ); 827cdf0e10cSrcweir any = pEx->WrappedException; 828cdf0e10cSrcweir } 829cdf0e10cSrcweir else { 830cdf0e10cSrcweir break; 831cdf0e10cSrcweir } 832cdf0e10cSrcweir } 833cdf0e10cSrcweir } 834cdf0e10cSrcweir catch( SAXException& e ) { 835cdf0e10cSrcweir printf( "%s\n" , UStringToString( e.Message , CHARSET_SYSTEM ).GetStr() ); 836cdf0e10cSrcweir 837cdf0e10cSrcweir } 838cdf0e10cSrcweir catch( Exception& e ) { 839cdf0e10cSrcweir printf( "normal exception ! %s\n", e.getName() ); 840cdf0e10cSrcweir } 841cdf0e10cSrcweir catch(...) { 842cdf0e10cSrcweir printf( "any exception !!!!\n" ); 843cdf0e10cSrcweir } 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir } 847cdf0e10cSrcweir 848cdf0e10cSrcweir 849cdf0e10cSrcweir extern "C" 850cdf0e10cSrcweir { 851cdf0e10cSrcweir BOOL EXTERN_SERVICE_CALLTYPE exService_writeRegEntry( 852cdf0e10cSrcweir const UNO_INTERFACE(XRegistryKey)* xUnoKey) 853cdf0e10cSrcweir 854cdf0e10cSrcweir { 855cdf0e10cSrcweir XRegistryKeyRef xKey; 856cdf0e10cSrcweir uno2smart(xKey, *xUnoKey); 857cdf0e10cSrcweir 858cdf0e10cSrcweir UString str = UString( L"/" ) + OSaxParserTest_getImplementationName() + UString( L"/UNO/SERVICES" ); 859cdf0e10cSrcweir XRegistryKeyRef xNewKey = xKey->createKey( str ); 860cdf0e10cSrcweir xNewKey->createKey( OSaxParserTest_getServiceName() ); 861cdf0e10cSrcweir 862cdf0e10cSrcweir str = UString( L"/" ) + OSaxWriterTest_getImplementationName() + UString( L"/UNO/SERVICES" ); 863cdf0e10cSrcweir xNewKey = xKey->createKey( str ); 864cdf0e10cSrcweir xNewKey->createKey( OSaxWriterTest_getServiceName() ); 865cdf0e10cSrcweir 866cdf0e10cSrcweir return TRUE; 867cdf0e10cSrcweir } 868cdf0e10cSrcweir 869cdf0e10cSrcweir 870cdf0e10cSrcweir UNO_INTERFACE(XInterface) EXTERN_SERVICE_CALLTYPE exService_getFactory 871cdf0e10cSrcweir ( 872cdf0e10cSrcweir const wchar_t* implementationName, 873cdf0e10cSrcweir const UNO_INTERFACE(XMultiServiceFactory)* xUnoFact, 874cdf0e10cSrcweir const UNO_INTERFACE(XRegistryKey)* 875cdf0e10cSrcweir ) 876cdf0e10cSrcweir { 877cdf0e10cSrcweir UNO_INTERFACE(XInterface) xUnoRet = {0, 0}; 878cdf0e10cSrcweir 879cdf0e10cSrcweir XInterfaceRef xRet; 880cdf0e10cSrcweir XMultiServiceFactoryRef xSMgr; 881cdf0e10cSrcweir UString aImplementationName(implementationName); 882cdf0e10cSrcweir 883cdf0e10cSrcweir uno2smart(xSMgr, *xUnoFact); 884cdf0e10cSrcweir 885cdf0e10cSrcweir if (aImplementationName == OSaxWriterTest_getImplementationName() ) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir xRet = createSingleFactory( xSMgr, implementationName, 888cdf0e10cSrcweir OSaxWriterTest_CreateInstance, 889cdf0e10cSrcweir OSaxWriterTest_getSupportedServiceNames() ); 890cdf0e10cSrcweir } 891cdf0e10cSrcweir else if (aImplementationName == OSaxParserTest_getImplementationName() ) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir xRet = createSingleFactory( xSMgr, implementationName, 894cdf0e10cSrcweir OSaxParserTest_CreateInstance, 895cdf0e10cSrcweir OSaxParserTest_getSupportedServiceNames() ); 896cdf0e10cSrcweir } 897cdf0e10cSrcweir if (xRet.is()) 898cdf0e10cSrcweir { 899cdf0e10cSrcweir smart2uno(xRet, xUnoRet); 900cdf0e10cSrcweir } 901cdf0e10cSrcweir 902cdf0e10cSrcweir return xUnoRet; 903cdf0e10cSrcweir } 904cdf0e10cSrcweir 905cdf0e10cSrcweir } 906cdf0e10cSrcweir 907cdf0e10cSrcweir 908