Update ooo320-m1
[ooovba.git] / writerfilter / qa / cppunittests / doctok / testdoctok.cxx
blob77d4b06a5f71b64af2e3e034f9e7f9853ce621e3
1 // autogenerated file with codegen.pl
3 #include <cppunit/simpleheader.hxx>
5 #include <osl/process.h>
6 #include <ucbhelper/contentbroker.hxx>
7 #include <cppuhelper/bootstrap.hxx>
8 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
9 #include <com/sun/star/io/XInputStream.hpp>
10 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
11 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
12 #include <com/sun/star/uno/Any.hxx>
13 #include <com/sun/star/container/XNameContainer.hpp>
15 #include <doctok/exceptions.hxx>
16 #include <doctok/WW8Document.hxx>
17 #include <resourcemodel/WW8ResourceModel.hxx>
19 #include <iostream>
21 namespace testdoctok
23 using namespace ::std;
24 using namespace ::com::sun::star;
25 using namespace doctok;
27 uno::Reference<io::XInputStream> xStream;
28 uno::Reference<uno::XComponentContext> xContext;
29 WW8Document::Pointer_t pDocument;
30 uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleFileAccess;
32 class test : public CppUnit::TestFixture
35 public:
36 // initialise your test code values here.
37 void setUp()
41 void tearDown()
45 void testInitUno()
47 bool bResult = false;
49 // initialise UCB-Broker
50 uno::Reference<uno::XComponentContext>
51 xComponentContext
52 (::cppu::defaultBootstrap_InitialComponentContext());
53 OSL_ASSERT( xComponentContext.is() );
55 xContext = xComponentContext;
57 uno::Reference<lang::XMultiComponentFactory>
58 xFactory(xComponentContext->getServiceManager() );
59 OSL_ASSERT(xFactory.is());
61 uno::Sequence<uno::Any> aUcbInitSequence(2);
62 aUcbInitSequence[0] <<=
63 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
64 aUcbInitSequence[1] <<=
65 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
67 uno::Reference<lang::XMultiServiceFactory>
68 xServiceFactory(xFactory, uno::UNO_QUERY);
69 OSL_ASSERT( xServiceFactory.is() );
71 if (xServiceFactory.is())
73 sal_Bool bRet =
74 ::ucb::ContentBroker::initialize(xServiceFactory,
75 aUcbInitSequence);
77 OSL_ASSERT(bRet);
78 if (bRet)
80 uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >
81 xNameContainer(xFactory->createInstanceWithContext
82 (::rtl::OUString::createFromAscii
83 ("com.sun.star.ucb.SimpleFileAccess" ),
84 xComponentContext), uno::UNO_QUERY );
86 if (xNameContainer.is())
88 xSimpleFileAccess = xNameContainer;
90 bResult = true;
95 CPPUNIT_ASSERT_MESSAGE("UNO initialization failed",
96 bResult);
99 // insert your test code here.
100 void testOpenFile()
102 try
104 rtl_uString *dir=NULL;
105 osl_getProcessWorkingDir(&dir);
106 rtl_uString *fname=NULL;
107 //rtl_uString_newFromAscii(&fname, "/OpenDocument-v1.doc");
108 rtl_uString_newFromAscii(&fname, "/test.doc");
109 //rtl_uString_newFromAscii(&fname, "/numbers.doc");
110 rtl_uString *absfile=NULL;
111 rtl_uString_newConcat(&absfile, dir, fname);
113 rtl::OUString sInputFileURL( absfile );
115 for (sal_uInt32 n = 0; n < sInputFileURL.getLength(); ++n)
117 sal_uChar nC = sInputFileURL[n];
119 if (nC < 0xff && isprint(nC))
120 clog << static_cast<char>(nC);
121 else
122 clog << ".";
125 clog << endl;
127 xStream = xSimpleFileAccess->openFileRead(sInputFileURL);
129 WW8Stream::Pointer_t pStream =
130 WW8DocumentFactory::createStream(xContext, xStream);
132 pDocument = WW8DocumentFactory::createDocument(pStream);
134 catch (doctok::Exception e)
136 clog << "Exception!!" << endl;
139 CPPUNIT_ASSERT_MESSAGE("creating document failed",
140 pDocument != NULL);
142 #if 1
145 void testTraversal()
147 #endif
148 sal_uInt32 nResult = 0;
152 WW8DocumentIterator::Pointer_t pIt = pDocument->begin();
153 WW8DocumentIterator::Pointer_t pItEnd = pDocument->end();
155 while (! pIt->equal(*pItEnd))
157 pIt->dump(clog);
159 clog << endl;
161 WW8PropertySet::Pointer_t pAttrs = pIt->getProperties();
163 if (pAttrs != NULL)
165 pAttrs->dump(clog);
168 pIt->getText().dump(clog);
169 ++(*pIt);
170 ++nResult;
173 catch (doctok::Exception e)
175 clog << "Exception!!" << endl;
178 char sBuffer[256];
179 snprintf(sBuffer, 255, "%d", nResult);
180 clog << "Iterator steps:" << sBuffer << endl;
182 CPPUNIT_ASSERT_MESSAGE("traversing document failed",
183 nResult > 0);
186 void testEvents()
190 Stream::Pointer_t pStream = doctok::createStreamHandler();
192 pDocument->resolve(*pStream);
194 catch (doctok::Exception e)
196 clog << "Exception!!" << endl;
200 void testEnd()
202 ::ucb::ContentBroker::deinitialize();
205 // Change the following lines only, if you add, remove or rename
206 // member functions of the current class,
207 // because these macros are need by auto register mechanism.
209 CPPUNIT_TEST_SUITE(test);
210 CPPUNIT_TEST(testInitUno);
211 CPPUNIT_TEST(testOpenFile);
212 //CPPUNIT_TEST(testTraversal);
213 CPPUNIT_TEST(testEvents);
214 CPPUNIT_TEST(testEnd);
215 CPPUNIT_TEST_SUITE_END();
216 }; // class test
218 // -----------------------------------------------------------------------------
219 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(testdoctok::test, "doctok");
220 } // namespace doctok
223 // -----------------------------------------------------------------------------
225 // this macro creates an empty function, which will called by the RegisterAllFunctions()
226 // to let the user the possibility to also register some functions by hand.
227 NOADDITIONAL;