domtest.cxx (e9cbe144) domtest.cxx (af7e73e0)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 9 unchanged lines hidden (view full) ---

18 * under the License.
19 *
20 *************************************************************/
21
22
23
24// autogenerated file with codegen.pl
25
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 9 unchanged lines hidden (view full) ---

18 * under the License.
19 *
20 *************************************************************/
21
22
23
24// autogenerated file with codegen.pl
25
26#include <testshl/simpleheader.hxx>
26#include "gtest/gtest.h"
27
28#include <rtl/ref.hxx>
29#include <osl/file.hxx>
30#include <osl/process.h>
31#include <comphelper/seqstream.hxx>
32#include <comphelper/sequence.hxx>
33#include <cppuhelper/compbase1.hxx>
34#include <cppuhelper/bootstrap.hxx>
35#include <cppuhelper/basemutex.hxx>
36
37#include <com/sun/star/xml/sax/FastToken.hpp>
38#include <com/sun/star/xml/sax/XSAXSerializable.hpp>
39#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
40
27
28#include <rtl/ref.hxx>
29#include <osl/file.hxx>
30#include <osl/process.h>
31#include <comphelper/seqstream.hxx>
32#include <comphelper/sequence.hxx>
33#include <cppuhelper/compbase1.hxx>
34#include <cppuhelper/bootstrap.hxx>
35#include <cppuhelper/basemutex.hxx>
36
37#include <com/sun/star/xml/sax/FastToken.hpp>
38#include <com/sun/star/xml/sax/XSAXSerializable.hpp>
39#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
40
41#include <cstdlib>
42
41#include "../source/dom/documentbuilder.hxx"
42
43
44using namespace ::DOM;
45using namespace ::comphelper;
46using namespace ::com::sun::star;
47
48namespace

--- 119 unchanged lines hidden (view full) ---

168 }
169};
170
171struct TokenHandler
172 : public ::cppu::WeakImplHelper1< xml::sax::XFastTokenHandler >
173{
174 virtual ::sal_Int32 SAL_CALL getToken( const ::rtl::OUString& Identifier ) throw (uno::RuntimeException)
175 {
43#include "../source/dom/documentbuilder.hxx"
44
45
46using namespace ::DOM;
47using namespace ::comphelper;
48using namespace ::com::sun::star;
49
50namespace

--- 119 unchanged lines hidden (view full) ---

170 }
171};
172
173struct TokenHandler
174 : public ::cppu::WeakImplHelper1< xml::sax::XFastTokenHandler >
175{
176 virtual ::sal_Int32 SAL_CALL getToken( const ::rtl::OUString& Identifier ) throw (uno::RuntimeException)
177 {
176 CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getToken() unexpected call",
177 false );
178 EXPECT_TRUE( false ) << "TokenHandler::getToken() unexpected call";
178 return -1;
179 }
180
181 virtual ::rtl::OUString SAL_CALL getIdentifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
182 {
179 return -1;
180 }
181
182 virtual ::rtl::OUString SAL_CALL getIdentifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
183 {
183 CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getIdentifier() unexpected call",
184 false );
184 EXPECT_TRUE( false ) << "TokenHandler::getIdentifier() unexpected call";
185 return rtl::OUString();
186 }
187
188 virtual ::sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence< ::sal_Int8 >& Identifier ) throw (uno::RuntimeException)
189 {
190 OSL_TRACE("getTokenFromUTF8() %s", (const char*)Identifier.getConstArray());
191 return Identifier.getLength() ? Identifier[0] : 0;
192 }
193
194 virtual uno::Sequence< ::sal_Int8 > SAL_CALL getUTF8Identifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
195 {
185 return rtl::OUString();
186 }
187
188 virtual ::sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence< ::sal_Int8 >& Identifier ) throw (uno::RuntimeException)
189 {
190 OSL_TRACE("getTokenFromUTF8() %s", (const char*)Identifier.getConstArray());
191 return Identifier.getLength() ? Identifier[0] : 0;
192 }
193
194 virtual uno::Sequence< ::sal_Int8 > SAL_CALL getUTF8Identifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
195 {
196 CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getUTF8Identifier() unexpected call",
197 false );
196 EXPECT_TRUE( false) << "TokenHandler::getUTF8Identifier() unexpected call";
198 return uno::Sequence<sal_Int8>();
199 }
200};
201
197 return uno::Sequence<sal_Int8>();
198 }
199};
200
202struct BasicTest : public CppUnit::TestFixture
201struct BasicTest : public ::testing::Test
203{
204 rtl::Reference<CDocumentBuilder> mxDomBuilder;
205 rtl::Reference<ErrorHandler> mxErrHandler;
206 rtl::Reference<SequenceInputStream> mxValidInStream;
207 rtl::Reference<SequenceInputStream> mxWarningInStream;
208 rtl::Reference<SequenceInputStream> mxErrorInStream;
209 rtl::Reference<SequenceInputStream> mxFatalInStream;
210
202{
203 rtl::Reference<CDocumentBuilder> mxDomBuilder;
204 rtl::Reference<ErrorHandler> mxErrHandler;
205 rtl::Reference<SequenceInputStream> mxValidInStream;
206 rtl::Reference<SequenceInputStream> mxWarningInStream;
207 rtl::Reference<SequenceInputStream> mxErrorInStream;
208 rtl::Reference<SequenceInputStream> mxFatalInStream;
209
211 void setUp()
210 void SetUp()
212 {
213 // luckily, DOM builder doesn't use service fac, so we need
214 // not bootstrap uno here
215 mxErrHandler.set( new ErrorHandler() );
216 mxDomBuilder.set( new CDocumentBuilder(Reference< XMultiServiceFactory >() ));
217 mxValidInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)validTestFile,
218 sizeof(validTestFile)/sizeof(*validTestFile))) );
219 mxWarningInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)warningTestFile,
220 sizeof(warningTestFile)/sizeof(*warningTestFile))) );
221 mxErrorInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)errorTestFile,
222 sizeof(errorTestFile)/sizeof(*errorTestFile))) );
223 mxFatalInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)fatalTestFile,
224 sizeof(fatalTestFile)/sizeof(*fatalTestFile))) );
225 mxDomBuilder->setErrorHandler(mxErrHandler.get());
226 }
211 {
212 // luckily, DOM builder doesn't use service fac, so we need
213 // not bootstrap uno here
214 mxErrHandler.set( new ErrorHandler() );
215 mxDomBuilder.set( new CDocumentBuilder(Reference< XMultiServiceFactory >() ));
216 mxValidInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)validTestFile,
217 sizeof(validTestFile)/sizeof(*validTestFile))) );
218 mxWarningInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)warningTestFile,
219 sizeof(warningTestFile)/sizeof(*warningTestFile))) );
220 mxErrorInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)errorTestFile,
221 sizeof(errorTestFile)/sizeof(*errorTestFile))) );
222 mxFatalInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)fatalTestFile,
223 sizeof(fatalTestFile)/sizeof(*fatalTestFile))) );
224 mxDomBuilder->setErrorHandler(mxErrHandler.get());
225 }
226};
227
227
228 void validInputTest()
229 {
230 CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #1",
231 mxDomBuilder->parse(
232 uno::Reference<io::XInputStream>(
233 mxValidInStream.get())).is() );
234 CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors",
235 mxErrHandler->noErrors() );
236 }
228TEST_F(BasicTest, validInputTest)
229{
230 ASSERT_TRUE( mxDomBuilder->parse(
231 uno::Reference<io::XInputStream>(
232 mxValidInStream.get())).is() ) << "Valid input file did not result in XDocument #1";
233 ASSERT_TRUE( mxErrHandler->noErrors() ) << "Valid input file resulted in parse errors";
234}
237
235
238 void warningInputTest()
239 {
240 CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #2",
241 mxDomBuilder->parse(
242 uno::Reference<io::XInputStream>(
243 mxWarningInStream.get())).is() );
244 CPPUNIT_ASSERT_MESSAGE( "No parse warnings in unclean input file",
245 mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount );
246 }
236TEST_F(BasicTest, warningInputTest)
237{
238 ASSERT_TRUE( mxDomBuilder->parse(
239 uno::Reference<io::XInputStream>(
240 mxWarningInStream.get())).is() ) << "Valid input file did not result in XDocument #2";
241 ASSERT_TRUE( mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount )
242 << "No parse warnings in unclean input file";
243}
247
244
248 void errorInputTest()
249 {
250 CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #3",
251 mxDomBuilder->parse(
252 uno::Reference<io::XInputStream>(
253 mxErrorInStream.get())).is() );
254 CPPUNIT_ASSERT_MESSAGE( "No parse errors in unclean input file",
255 !mxErrHandler->mnWarnCount && mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount );
256 }
245TEST_F(BasicTest, errorInputTest)
246{
247 ASSERT_TRUE( mxDomBuilder->parse(
248 uno::Reference<io::XInputStream>(
249 mxErrorInStream.get())).is() ) << "Valid input file did not result in XDocument #3";
250 ASSERT_TRUE( !mxErrHandler->mnWarnCount && mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount )
251 << "No parse errors in unclean input file";
252}
257
253
258 void fatalInputTest()
259 {
260 CPPUNIT_ASSERT_MESSAGE( "Broken input file resulted in XDocument",
261 !mxDomBuilder->parse(
262 uno::Reference<io::XInputStream>(
263 mxFatalInStream.get())).is() );
264 CPPUNIT_ASSERT_MESSAGE( "No fatal parse errors in unclean input file",
265 !mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && mxErrHandler->mnFatalCount );
266 };
267
268 // Change the following lines only, if you add, remove or rename
269 // member functions of the current class,
270 // because these macros are need by auto register mechanism.
271 CPPUNIT_TEST_SUITE(BasicTest);
272 CPPUNIT_TEST(validInputTest);
273 CPPUNIT_TEST(warningInputTest);
274 CPPUNIT_TEST(errorInputTest);
275 CPPUNIT_TEST(fatalInputTest);
276 CPPUNIT_TEST_SUITE_END();
254TEST_F(BasicTest, fatalInputTest)
255{
256 ASSERT_TRUE( !mxDomBuilder->parse(
257 uno::Reference<io::XInputStream>(
258 mxFatalInStream.get())).is() ) << "Broken input file resulted in XDocument";
259 ASSERT_TRUE( !mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && mxErrHandler->mnFatalCount )
260 << "No fatal parse errors in unclean input file";
277};
278
261};
262
279struct SerializerTest : public CppUnit::TestFixture
263
264struct SerializerTest : public ::testing::Test
280{
281 SerializerTest() : mbUnoInitialized(false) {}
282
283 uno::Reference<uno::XComponentContext> mxCtx;
284 rtl::Reference<CDocumentBuilder> mxDomBuilder;
285 rtl::Reference<ErrorHandler> mxErrHandler;
286 rtl::Reference<SequenceInputStream> mxInStream;
287 rtl::Reference<DocumentHandler> mxHandler;
288 rtl::Reference<TokenHandler> mxTokHandler;
289 uno::Sequence< beans::Pair< rtl::OUString, sal_Int32 > > maRegisteredNamespaces;
290 bool mbUnoInitialized;
291
265{
266 SerializerTest() : mbUnoInitialized(false) {}
267
268 uno::Reference<uno::XComponentContext> mxCtx;
269 rtl::Reference<CDocumentBuilder> mxDomBuilder;
270 rtl::Reference<ErrorHandler> mxErrHandler;
271 rtl::Reference<SequenceInputStream> mxInStream;
272 rtl::Reference<DocumentHandler> mxHandler;
273 rtl::Reference<TokenHandler> mxTokHandler;
274 uno::Sequence< beans::Pair< rtl::OUString, sal_Int32 > > maRegisteredNamespaces;
275 bool mbUnoInitialized;
276
292 void setUp()
277 void SetUp()
293 {
294 // need working typelib, bootstrap UNO now
295 if( !mbUnoInitialized )
296 {
278 {
279 // need working typelib, bootstrap UNO now
280 if( !mbUnoInitialized )
281 {
297 const char* pArgs( getForwardString() );
298 CPPUNIT_ASSERT_MESSAGE("Test file parameter", pArgs);
282 const char* pArgs( getenv("UNOXML_DOMTEST_FORWARD") );
283 ASSERT_TRUE(pArgs) << "Test file parameter";
299
300 const rtl::OUString sBaseDir=rtl::OUString::createFromAscii(pArgs);
301
302 // bootstrap UNO
303 try
304 {
305 ::rtl::OUString aIniUrl;
284
285 const rtl::OUString sBaseDir=rtl::OUString::createFromAscii(pArgs);
286
287 // bootstrap UNO
288 try
289 {
290 ::rtl::OUString aIniUrl;
306 CPPUNIT_ASSERT_MESSAGE(
307 "Converting ini file to URL",
291 ASSERT_TRUE(
308 osl_getFileURLFromSystemPath(
309 (sBaseDir+rtl::OUString::createFromAscii("unoxml_unittest_test.ini")).pData,
292 osl_getFileURLFromSystemPath(
293 (sBaseDir+rtl::OUString::createFromAscii("unoxml_unittest_test.ini")).pData,
310 &aIniUrl.pData ) == osl_File_E_None );
294 &aIniUrl.pData ) == osl_File_E_None ) << "Converting ini file to URL";
311
312 mxCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
295
296 mxCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
313 CPPUNIT_ASSERT_MESSAGE("Getting component context", mxCtx.is());
297 ASSERT_TRUE(mxCtx.is()) << "Getting component context";
314 }
315 catch( uno::Exception& )
316 {
298 }
299 catch( uno::Exception& )
300 {
317 CPPUNIT_ASSERT_MESSAGE("Bootstrapping UNO", false);
301 ASSERT_TRUE(false) << "Bootstrapping UNO";
318 }
319
320 mbUnoInitialized = true;
321 }
322
323 mxErrHandler.set( new ErrorHandler() );
324 mxDomBuilder.set( new CDocumentBuilder(
325 uno::Reference< lang::XMultiServiceFactory >(

--- 13 unchanged lines hidden (view full) ---

339 "urn:oasis:names:tc:opendocument:xmlns:office:1.0") ),
340 xml::sax::FastToken::NAMESPACE);
341 maRegisteredNamespaces[1] = beans::make_Pair(
342 rtl::OUString(
343 RTL_CONSTASCII_USTRINGPARAM(
344 "http://www.w3.org/1999/xlink") ),
345 2*xml::sax::FastToken::NAMESPACE);
346 }
302 }
303
304 mbUnoInitialized = true;
305 }
306
307 mxErrHandler.set( new ErrorHandler() );
308 mxDomBuilder.set( new CDocumentBuilder(
309 uno::Reference< lang::XMultiServiceFactory >(

--- 13 unchanged lines hidden (view full) ---

323 "urn:oasis:names:tc:opendocument:xmlns:office:1.0") ),
324 xml::sax::FastToken::NAMESPACE);
325 maRegisteredNamespaces[1] = beans::make_Pair(
326 rtl::OUString(
327 RTL_CONSTASCII_USTRINGPARAM(
328 "http://www.w3.org/1999/xlink") ),
329 2*xml::sax::FastToken::NAMESPACE);
330 }
331};
347
332
348 void serializerTest ()
349 {
350 uno::Reference< xml::dom::XDocument > xDoc=
351 mxDomBuilder->parse(
352 uno::Reference<io::XInputStream>(
353 mxInStream.get()));
354 CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument",
355 xDoc.is() );
356 CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors",
357 mxErrHandler->noErrors() );
333TEST_F(SerializerTest, serializerTest)
334{
335 uno::Reference< xml::dom::XDocument > xDoc=
336 mxDomBuilder->parse(
337 uno::Reference<io::XInputStream>(
338 mxInStream.get()));
339 ASSERT_TRUE( xDoc.is() ) << "Valid input file did not result in XDocument";
340 ASSERT_TRUE( mxErrHandler->noErrors() ) << "Valid input file resulted in parse errors";
358
341
359 uno::Reference< xml::sax::XSAXSerializable > xSaxSerializer(
360 xDoc, uno::UNO_QUERY);
361 CPPUNIT_ASSERT_MESSAGE( "XSAXSerializable not supported",
362 xSaxSerializer.is() );
342 uno::Reference< xml::sax::XSAXSerializable > xSaxSerializer(
343 xDoc, uno::UNO_QUERY);
344 ASSERT_TRUE( xSaxSerializer.is() ) << "XSAXSerializable not supported";
363
345
364 uno::Reference< xml::sax::XFastSAXSerializable > xFastSaxSerializer(
365 xDoc, uno::UNO_QUERY);
366 CPPUNIT_ASSERT_MESSAGE( "XFastSAXSerializable not supported",
367 xSaxSerializer.is() );
346 uno::Reference< xml::sax::XFastSAXSerializable > xFastSaxSerializer(
347 xDoc, uno::UNO_QUERY);
348 ASSERT_TRUE( xSaxSerializer.is() ) << "XFastSAXSerializable not supported";
368
349
369 xFastSaxSerializer->fastSerialize( mxHandler.get(),
370 mxTokHandler.get(),
371 uno::Sequence< beans::StringPair >(),
372 maRegisteredNamespaces );
373 }
350 xFastSaxSerializer->fastSerialize( mxHandler.get(),
351 mxTokHandler.get(),
352 uno::Sequence< beans::StringPair >(),
353 maRegisteredNamespaces );
354}
374
355
375 // Change the following lines only, if you add, remove or rename
376 // member functions of the current class,
377 // because these macros are need by auto register mechanism.
378
379 CPPUNIT_TEST_SUITE(SerializerTest);
380 CPPUNIT_TEST(serializerTest);
381 CPPUNIT_TEST_SUITE_END();
382};
383
384// -----------------------------------------------------------------------------
385CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicTest, "BasicTest");
386CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SerializerTest, "SerializerTest");
387}
388
389
356}
357
358
390// -----------------------------------------------------------------------------
391
392// this macro creates an empty function, which will called by the RegisterAllFunctions()
393// to let the user the possibility to also register some functions by hand.
394NOADDITIONAL;
395
359int main(int argc, char **argv)
360{
361 ::testing::InitGoogleTest(&argc, argv);
362 return RUN_ALL_TESTS();
363}