xref: /aoo41x/main/unoxml/test/domtest.cxx (revision cdf0e10c)
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 // autogenerated file with codegen.pl
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <rtl/ref.hxx>
33*cdf0e10cSrcweir #include <osl/file.hxx>
34*cdf0e10cSrcweir #include <osl/process.h>
35*cdf0e10cSrcweir #include <comphelper/seqstream.hxx>
36*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
37*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
38*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
39*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <com/sun/star/xml/sax/FastToken.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XSAXSerializable.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include "../source/dom/documentbuilder.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace ::DOM;
49*cdf0e10cSrcweir using namespace ::comphelper;
50*cdf0e10cSrcweir using namespace ::com::sun::star;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir namespace
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir // valid xml
56*cdf0e10cSrcweir static const char validTestFile[] =
57*cdf0e10cSrcweir "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
58*cdf0e10cSrcweir  <office:document-content \
59*cdf0e10cSrcweir    xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
60*cdf0e10cSrcweir    xmlns:xlink=\"http://www.w3.org/1999/xlink\" \
61*cdf0e10cSrcweir    office:version=\"1.0\"> \
62*cdf0e10cSrcweir    <office:scripts/> \
63*cdf0e10cSrcweir    <xlink:test/> \
64*cdf0e10cSrcweir    <office:automatic-styles teststyle=\"test\"/> \
65*cdf0e10cSrcweir    <moretest/> \
66*cdf0e10cSrcweir     some text öäü \
67*cdf0e10cSrcweir  </office:document-content> \
68*cdf0e10cSrcweir ";
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir // generates a warning: unsupported xml version, unknown xml:space
71*cdf0e10cSrcweir // value
72*cdf0e10cSrcweir static const char warningTestFile[] =
73*cdf0e10cSrcweir "<?xml version=\"47-11.0\" encoding=\"UTF-8\"?> \
74*cdf0e10cSrcweir  <office:document-content \
75*cdf0e10cSrcweir    xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
76*cdf0e10cSrcweir    xml:space=\"blafasl\" \
77*cdf0e10cSrcweir    office:version=\"1.0\"> \
78*cdf0e10cSrcweir    <office:scripts/> \
79*cdf0e10cSrcweir    <office:automatic-styles/> \
80*cdf0e10cSrcweir  </office:document-content> \
81*cdf0e10cSrcweir ";
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir // <?xml not at start of file
84*cdf0e10cSrcweir static const char errorTestFile[] =
85*cdf0e10cSrcweir " <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
86*cdf0e10cSrcweir  <office:document-content \
87*cdf0e10cSrcweir    xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
88*cdf0e10cSrcweir    office:version=\"1.0\"> \
89*cdf0e10cSrcweir    <office:scripts/> \
90*cdf0e10cSrcweir    <office:automatic-styles/> \
91*cdf0e10cSrcweir  </office:document-content> \
92*cdf0e10cSrcweir ";
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir // plain empty
95*cdf0e10cSrcweir static const char fatalTestFile[] = "";
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir struct ErrorHandler
98*cdf0e10cSrcweir     : public ::cppu::WeakImplHelper1< xml::sax::XErrorHandler >
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     sal_uInt32 mnErrCount;
101*cdf0e10cSrcweir     sal_uInt32 mnFatalCount;
102*cdf0e10cSrcweir     sal_uInt32 mnWarnCount;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     bool noErrors() const { return !mnErrCount && !mnFatalCount && !mnWarnCount; }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     ErrorHandler() : mnErrCount(0), mnFatalCount(0), mnWarnCount(0)
107*cdf0e10cSrcweir     {}
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     virtual void SAL_CALL error( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
110*cdf0e10cSrcweir     {
111*cdf0e10cSrcweir         ++mnErrCount;
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     virtual void SAL_CALL fatalError( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
115*cdf0e10cSrcweir     {
116*cdf0e10cSrcweir         ++mnFatalCount;
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     virtual void SAL_CALL warning( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         ++mnWarnCount;
122*cdf0e10cSrcweir     }
123*cdf0e10cSrcweir };
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir struct DocumentHandler
126*cdf0e10cSrcweir     : public ::cppu::WeakImplHelper1< xml::sax::XFastDocumentHandler >
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     // XFastContextHandler
129*cdf0e10cSrcweir     virtual void SAL_CALL startFastElement( ::sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         OSL_TRACE("Seen element: %c with namespace 0x%x",
132*cdf0e10cSrcweir                   Element & 0xFFFF, Element & 0xFFFF0000);
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     virtual void SAL_CALL startUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
136*cdf0e10cSrcweir     {
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     virtual void SAL_CALL endFastElement( ::sal_Int32 Element ) throw (xml::sax::SAXException, uno::RuntimeException)
140*cdf0e10cSrcweir     {
141*cdf0e10cSrcweir     }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     virtual void SAL_CALL endUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name ) throw (xml::sax::SAXException, uno::RuntimeException)
144*cdf0e10cSrcweir     {
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
148*cdf0e10cSrcweir     {
149*cdf0e10cSrcweir         return this;
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
153*cdf0e10cSrcweir     {
154*cdf0e10cSrcweir         return this;
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (xml::sax::SAXException, uno::RuntimeException)
158*cdf0e10cSrcweir     {
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     // XFastDocumentHandler
162*cdf0e10cSrcweir     virtual void SAL_CALL startDocument(  ) throw (xml::sax::SAXException, uno::RuntimeException)
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     virtual void SAL_CALL endDocument(  ) throw (xml::sax::SAXException, uno::RuntimeException)
167*cdf0e10cSrcweir     {
168*cdf0e10cSrcweir     }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     virtual void SAL_CALL setDocumentLocator( const uno::Reference< xml::sax::XLocator >& xLocator ) throw (xml::sax::SAXException, uno::RuntimeException)
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir     }
173*cdf0e10cSrcweir };
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir struct TokenHandler
176*cdf0e10cSrcweir     : public ::cppu::WeakImplHelper1< xml::sax::XFastTokenHandler >
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir     virtual ::sal_Int32 SAL_CALL getToken( const ::rtl::OUString& Identifier ) throw (uno::RuntimeException)
179*cdf0e10cSrcweir     {
180*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getToken() unexpected call",
181*cdf0e10cSrcweir                                 false );
182*cdf0e10cSrcweir         return -1;
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getIdentifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getIdentifier() unexpected call",
188*cdf0e10cSrcweir                                 false );
189*cdf0e10cSrcweir         return rtl::OUString();
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     virtual ::sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence< ::sal_Int8 >& Identifier ) throw (uno::RuntimeException)
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         OSL_TRACE("getTokenFromUTF8() %s", (const char*)Identifier.getConstArray());
195*cdf0e10cSrcweir         return Identifier.getLength() ? Identifier[0] : 0;
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     virtual uno::Sequence< ::sal_Int8 > SAL_CALL getUTF8Identifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
199*cdf0e10cSrcweir     {
200*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getUTF8Identifier() unexpected call",
201*cdf0e10cSrcweir                                 false );
202*cdf0e10cSrcweir         return uno::Sequence<sal_Int8>();
203*cdf0e10cSrcweir     }
204*cdf0e10cSrcweir };
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir struct BasicTest : public CppUnit::TestFixture
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir     rtl::Reference<CDocumentBuilder>    mxDomBuilder;
209*cdf0e10cSrcweir     rtl::Reference<ErrorHandler>        mxErrHandler;
210*cdf0e10cSrcweir     rtl::Reference<SequenceInputStream> mxValidInStream;
211*cdf0e10cSrcweir     rtl::Reference<SequenceInputStream> mxWarningInStream;
212*cdf0e10cSrcweir     rtl::Reference<SequenceInputStream> mxErrorInStream;
213*cdf0e10cSrcweir     rtl::Reference<SequenceInputStream> mxFatalInStream;
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir     void setUp()
216*cdf0e10cSrcweir     {
217*cdf0e10cSrcweir         // luckily, DOM builder doesn't use service fac, so we need
218*cdf0e10cSrcweir         // not bootstrap uno here
219*cdf0e10cSrcweir         mxErrHandler.set( new ErrorHandler() );
220*cdf0e10cSrcweir         mxDomBuilder.set( new CDocumentBuilder(Reference< XMultiServiceFactory >() ));
221*cdf0e10cSrcweir         mxValidInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)validTestFile,
222*cdf0e10cSrcweir                                                                   sizeof(validTestFile)/sizeof(*validTestFile))) );
223*cdf0e10cSrcweir         mxWarningInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)warningTestFile,
224*cdf0e10cSrcweir                                                                     sizeof(warningTestFile)/sizeof(*warningTestFile))) );
225*cdf0e10cSrcweir         mxErrorInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)errorTestFile,
226*cdf0e10cSrcweir                                                                   sizeof(errorTestFile)/sizeof(*errorTestFile))) );
227*cdf0e10cSrcweir         mxFatalInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)fatalTestFile,
228*cdf0e10cSrcweir                                                                   sizeof(fatalTestFile)/sizeof(*fatalTestFile))) );
229*cdf0e10cSrcweir         mxDomBuilder->setErrorHandler(mxErrHandler.get());
230*cdf0e10cSrcweir     }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir     void validInputTest()
233*cdf0e10cSrcweir     {
234*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #1",
235*cdf0e10cSrcweir                                 mxDomBuilder->parse(
236*cdf0e10cSrcweir                                     uno::Reference<io::XInputStream>(
237*cdf0e10cSrcweir                                         mxValidInStream.get())).is() );
238*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors",
239*cdf0e10cSrcweir                                 mxErrHandler->noErrors() );
240*cdf0e10cSrcweir     }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     void warningInputTest()
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #2",
245*cdf0e10cSrcweir                                 mxDomBuilder->parse(
246*cdf0e10cSrcweir                                     uno::Reference<io::XInputStream>(
247*cdf0e10cSrcweir                                         mxWarningInStream.get())).is() );
248*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "No parse warnings in unclean input file",
249*cdf0e10cSrcweir                                 mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount );
250*cdf0e10cSrcweir     }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir     void errorInputTest()
253*cdf0e10cSrcweir     {
254*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #3",
255*cdf0e10cSrcweir                                 mxDomBuilder->parse(
256*cdf0e10cSrcweir                                     uno::Reference<io::XInputStream>(
257*cdf0e10cSrcweir                                         mxErrorInStream.get())).is() );
258*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "No parse errors in unclean input file",
259*cdf0e10cSrcweir                                 !mxErrHandler->mnWarnCount && mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount );
260*cdf0e10cSrcweir     }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     void fatalInputTest()
263*cdf0e10cSrcweir     {
264*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Broken input file resulted in XDocument",
265*cdf0e10cSrcweir                                 !mxDomBuilder->parse(
266*cdf0e10cSrcweir                                     uno::Reference<io::XInputStream>(
267*cdf0e10cSrcweir                                         mxFatalInStream.get())).is() );
268*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "No fatal parse errors in unclean input file",
269*cdf0e10cSrcweir                                 !mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && mxErrHandler->mnFatalCount );
270*cdf0e10cSrcweir     };
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
273*cdf0e10cSrcweir     // member functions of the current class,
274*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
275*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(BasicTest);
276*cdf0e10cSrcweir     CPPUNIT_TEST(validInputTest);
277*cdf0e10cSrcweir     CPPUNIT_TEST(warningInputTest);
278*cdf0e10cSrcweir     CPPUNIT_TEST(errorInputTest);
279*cdf0e10cSrcweir     CPPUNIT_TEST(fatalInputTest);
280*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
281*cdf0e10cSrcweir };
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir struct SerializerTest : public CppUnit::TestFixture
284*cdf0e10cSrcweir {
285*cdf0e10cSrcweir     SerializerTest() : mbUnoInitialized(false) {}
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     uno::Reference<uno::XComponentContext>                   mxCtx;
288*cdf0e10cSrcweir     rtl::Reference<CDocumentBuilder>                         mxDomBuilder;
289*cdf0e10cSrcweir     rtl::Reference<ErrorHandler>                             mxErrHandler;
290*cdf0e10cSrcweir     rtl::Reference<SequenceInputStream>                      mxInStream;
291*cdf0e10cSrcweir     rtl::Reference<DocumentHandler>                          mxHandler;
292*cdf0e10cSrcweir     rtl::Reference<TokenHandler>                             mxTokHandler;
293*cdf0e10cSrcweir     uno::Sequence< beans::Pair< rtl::OUString, sal_Int32 > > maRegisteredNamespaces;
294*cdf0e10cSrcweir     bool                                                     mbUnoInitialized;
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     void setUp()
297*cdf0e10cSrcweir     {
298*cdf0e10cSrcweir         // need working typelib, bootstrap UNO now
299*cdf0e10cSrcweir         if( !mbUnoInitialized )
300*cdf0e10cSrcweir         {
301*cdf0e10cSrcweir             const char* pArgs( getForwardString() );
302*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE("Test file parameter", pArgs);
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir             const rtl::OUString sBaseDir=rtl::OUString::createFromAscii(pArgs);
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir             // bootstrap UNO
307*cdf0e10cSrcweir             try
308*cdf0e10cSrcweir             {
309*cdf0e10cSrcweir                 ::rtl::OUString aIniUrl;
310*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE(
311*cdf0e10cSrcweir                     "Converting ini file to URL",
312*cdf0e10cSrcweir                     osl_getFileURLFromSystemPath(
313*cdf0e10cSrcweir                         (sBaseDir+rtl::OUString::createFromAscii("unoxml_unittest_test.ini")).pData,
314*cdf0e10cSrcweir                         &aIniUrl.pData ) == osl_File_E_None );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir                 mxCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
317*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE("Getting component context", mxCtx.is());
318*cdf0e10cSrcweir             }
319*cdf0e10cSrcweir             catch( uno::Exception& )
320*cdf0e10cSrcweir             {
321*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE("Bootstrapping UNO", false);
322*cdf0e10cSrcweir             }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir             mbUnoInitialized = true;
325*cdf0e10cSrcweir         }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir         mxErrHandler.set( new ErrorHandler() );
328*cdf0e10cSrcweir         mxDomBuilder.set( new CDocumentBuilder(
329*cdf0e10cSrcweir                               uno::Reference< lang::XMultiServiceFactory >(
330*cdf0e10cSrcweir                                   mxCtx->getServiceManager(),
331*cdf0e10cSrcweir                                   uno::UNO_QUERY )));
332*cdf0e10cSrcweir         mxInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)validTestFile,
333*cdf0e10cSrcweir                                                              sizeof(validTestFile)/sizeof(*validTestFile))) );
334*cdf0e10cSrcweir         mxDomBuilder->setErrorHandler(mxErrHandler.get());
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir         mxHandler.set( new DocumentHandler() );
337*cdf0e10cSrcweir         mxTokHandler.set( new TokenHandler() );
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir         maRegisteredNamespaces.realloc(2);
340*cdf0e10cSrcweir         maRegisteredNamespaces[0] = beans::make_Pair(
341*cdf0e10cSrcweir             rtl::OUString(
342*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
343*cdf0e10cSrcweir                     "urn:oasis:names:tc:opendocument:xmlns:office:1.0") ),
344*cdf0e10cSrcweir             xml::sax::FastToken::NAMESPACE);
345*cdf0e10cSrcweir         maRegisteredNamespaces[1] = beans::make_Pair(
346*cdf0e10cSrcweir             rtl::OUString(
347*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
348*cdf0e10cSrcweir                     "http://www.w3.org/1999/xlink") ),
349*cdf0e10cSrcweir             2*xml::sax::FastToken::NAMESPACE);
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     void serializerTest ()
353*cdf0e10cSrcweir     {
354*cdf0e10cSrcweir         uno::Reference< xml::dom::XDocument > xDoc=
355*cdf0e10cSrcweir             mxDomBuilder->parse(
356*cdf0e10cSrcweir                 uno::Reference<io::XInputStream>(
357*cdf0e10cSrcweir                     mxInStream.get()));
358*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument",
359*cdf0e10cSrcweir                                 xDoc.is() );
360*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors",
361*cdf0e10cSrcweir                                 mxErrHandler->noErrors() );
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir         uno::Reference< xml::sax::XSAXSerializable > xSaxSerializer(
364*cdf0e10cSrcweir             xDoc, uno::UNO_QUERY);
365*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "XSAXSerializable not supported",
366*cdf0e10cSrcweir                                 xSaxSerializer.is() );
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir         uno::Reference< xml::sax::XFastSAXSerializable > xFastSaxSerializer(
369*cdf0e10cSrcweir             xDoc, uno::UNO_QUERY);
370*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "XFastSAXSerializable not supported",
371*cdf0e10cSrcweir                                 xSaxSerializer.is() );
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir         xFastSaxSerializer->fastSerialize( mxHandler.get(),
374*cdf0e10cSrcweir                                            mxTokHandler.get(),
375*cdf0e10cSrcweir                                            uno::Sequence< beans::StringPair >(),
376*cdf0e10cSrcweir                                            maRegisteredNamespaces );
377*cdf0e10cSrcweir     }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
380*cdf0e10cSrcweir     // member functions of the current class,
381*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(SerializerTest);
384*cdf0e10cSrcweir     CPPUNIT_TEST(serializerTest);
385*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
386*cdf0e10cSrcweir };
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir // -----------------------------------------------------------------------------
389*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicTest, "BasicTest");
390*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SerializerTest, "SerializerTest");
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir // -----------------------------------------------------------------------------
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
397*cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
398*cdf0e10cSrcweir NOADDITIONAL;
399*cdf0e10cSrcweir 
400