fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / writerfilter / qa / cppunittests / doctok / testdoctok.cxx
blobe4a04f7fe1ddd8827e106b5e2995d205573758cc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <osl/process.h>
23 #include <ucbhelper/contentbroker.hxx>
24 #include <ucbhelper/std_inputstream.hxx>
25 #include <cppuhelper/bootstrap.hxx>
26 #include "cppunit/TestAssert.h"
27 #include "cppunit/TestFixture.h"
28 #include "cppunit/extensions/HelperMacros.h"
29 #include "cppunit/plugin/TestPlugIn.h"
30 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
31 #include <com/sun/star/io/XInputStream.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
34 #include <com/sun/star/uno/Any.hxx>
35 #include <com/sun/star/container/XNameContainer.hpp>
37 #include <resourcemodel/exceptions.hxx>
38 #include <doctok/WW8Document.hxx>
39 #include <resourcemodel/WW8ResourceModel.hxx>
41 #include <iostream>
43 namespace testdoctok
45 using namespace ::std;
46 using namespace ::writerfilter::doctok;
47 using namespace ::com::sun::star;
49 uno::Reference<io::XInputStream> xStream;
50 uno::Reference<uno::XComponentContext> xContext;
51 WW8Document::Pointer_t pDocument;
52 uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess3 > xSimpleFileAccess;
54 class test : public CppUnit::TestFixture
57 public:
58 // initialise your test code values here.
59 void setUp()
63 void tearDown()
67 void testInitUno()
69 bool bResult = false;
71 // initialise UCB-Broker
72 uno::Reference<uno::XComponentContext>
73 xComponentContext
74 (::cppu::defaultBootstrap_InitialComponentContext());
75 OSL_ASSERT( xComponentContext.is() );
77 xContext = xComponentContext;
79 uno::Reference<lang::XMultiComponentFactory>
80 xFactory(xComponentContext->getServiceManager() );
81 OSL_ASSERT(xFactory.is());
83 uno::Sequence<uno::Any> aUcbInitSequence(2);
84 aUcbInitSequence[0] <<= OUString("Local");
85 aUcbInitSequence[1] <<= OUString("Office");
87 uno::Reference<lang::XMultiServiceFactory>
88 xServiceFactory(xFactory, uno::UNO_QUERY);
89 OSL_ASSERT( xServiceFactory.is() );
91 if (xServiceFactory.is())
93 sal_Bool bRet =
94 ::ucb::ContentBroker::initialize(xServiceFactory,
95 aUcbInitSequence);
97 OSL_ASSERT(bRet);
98 if (bRet)
100 xSimpleFileAccess = ucb::SimpleFileAccess::create(xComponentContext);
101 bResult = true;
105 CPPUNIT_ASSERT_MESSAGE("UNO initialization failed",
106 bResult);
109 // insert your test code here.
110 void testOpenFile()
114 rtl_uString *dir=NULL;
115 osl_getProcessWorkingDir(&dir);
116 rtl_uString *fname=NULL;
117 //rtl_uString_newFromAscii(&fname, "/OpenDocument-v1.doc");
118 rtl_uString_newFromAscii(&fname, "/test.doc");
119 //rtl_uString_newFromAscii(&fname, "/numbers.doc");
120 rtl_uString *absfile=NULL;
121 rtl_uString_newConcat(&absfile, dir, fname);
123 OUString sInputFileURL( absfile );
125 for (sal_uInt32 n = 0; n < sInputFileURL.getLength(); ++n)
127 sal_uChar nC = sInputFileURL[n];
129 if (nC < 0xff && isprint(nC))
130 clog << static_cast<char>(nC);
131 else
132 clog << ".";
135 clog << endl;
137 xStream = xSimpleFileAccess->openFileRead(sInputFileURL);
139 WW8Stream::Pointer_t pStream =
140 WW8DocumentFactory::createStream(xContext, xStream);
142 pDocument = WW8DocumentFactory::createDocument(pStream);
144 catch (writerfilter::Exception e)
146 clog << "Exception!!" << endl;
149 CPPUNIT_ASSERT_MESSAGE("creating document failed",
150 pDocument != NULL);
152 #if 1
155 void testTraversal()
157 #endif
158 sal_uInt32 nResult = 0;
162 WW8DocumentIterator::Pointer_t pIt = pDocument->begin();
163 WW8DocumentIterator::Pointer_t pItEnd = pDocument->end();
165 while (! pIt->equal(*pItEnd))
167 pIt->dump(clog);
169 clog << endl;
171 WW8PropertySet::Pointer_t pAttrs = pIt->getProperties();
173 if (pAttrs != NULL)
175 pAttrs->dump(clog);
178 pIt->getText().dump(clog);
179 ++(*pIt);
180 ++nResult;
183 catch (writerfilter::Exception e)
185 clog << "Exception!!" << endl;
188 char sBuffer[256];
189 snprintf(sBuffer, 255, "%d", nResult);
190 clog << "Iterator steps:" << sBuffer << endl;
192 CPPUNIT_ASSERT_MESSAGE("traversing document failed",
193 nResult > 0);
196 void testEvents()
200 Stream::Pointer_t pStream = doctok::createStreamHandler();
202 pDocument->resolve(*pStream);
204 catch (writerfilter::Exception e)
206 clog << "Exception!!" << endl;
210 void testEnd()
212 ::ucb::ContentBroker::deinitialize();
215 // Change the following lines only, if you add, remove or rename
216 // member functions of the current class,
217 // because these macros are need by auto register mechanism.
219 CPPUNIT_TEST_SUITE(test);
220 CPPUNIT_TEST(testInitUno);
221 CPPUNIT_TEST(testOpenFile);
222 //CPPUNIT_TEST(testTraversal);
223 CPPUNIT_TEST(testEvents);
224 CPPUNIT_TEST(testEnd);
225 CPPUNIT_TEST_SUITE_END();
226 }; // class test
228 // -----------------------------------------------------------------------------
229 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(testdoctok::test, "doctok");
230 } // namespace doctok
232 // -----------------------------------------------------------------------------
234 // this macro creates an empty function, which will called by the RegisterAllFunctions()
235 // to let the user the possibility to also register some functions by hand.
236 NOADDITIONAL;
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */