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