1b4a4f18cSAndrew Rist /**************************************************************
2b4a4f18cSAndrew Rist  *
3b4a4f18cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b4a4f18cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b4a4f18cSAndrew Rist  * distributed with this work for additional information
6b4a4f18cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b4a4f18cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b4a4f18cSAndrew Rist  * "License"); you may not use this file except in compliance
9b4a4f18cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10b4a4f18cSAndrew Rist  *
11b4a4f18cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b4a4f18cSAndrew Rist  *
13b4a4f18cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b4a4f18cSAndrew Rist  * software distributed under the License is distributed on an
15b4a4f18cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b4a4f18cSAndrew Rist  * KIND, either express or implied.  See the License for the
17b4a4f18cSAndrew Rist  * specific language governing permissions and limitations
18b4a4f18cSAndrew Rist  * under the License.
19b4a4f18cSAndrew Rist  *
20b4a4f18cSAndrew Rist  *************************************************************/
21b4a4f18cSAndrew Rist 
22cdf0e10cSrcweir // autogenerated file with codegen.pl
23cdf0e10cSrcweir 
24977d62f2SDamjan Jovanovic #include "gtest/gtest.h"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <osl/process.h>
27cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
28cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
29cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
31*b63233d8Sdamjan #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
32cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <doctok/WW8Document.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <iostream>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace testdoctok
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     using namespace ::std;
41cdf0e10cSrcweir     using namespace ::com::sun::star;
42977d62f2SDamjan Jovanovic     using namespace ::writerfilter::doctok;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     uno::Reference<io::XInputStream> xStream;
45cdf0e10cSrcweir     uno::Reference<uno::XComponentContext> xContext;
46cdf0e10cSrcweir     WW8Document::Pointer_t pDocument;
47cdf0e10cSrcweir     uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleFileAccess;
48cdf0e10cSrcweir 
49977d62f2SDamjan Jovanovic     class test : public ::testing::Test
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     public:
53cdf0e10cSrcweir         // initialise your test code values here.
SetUp()54977d62f2SDamjan Jovanovic         void SetUp()
55cdf0e10cSrcweir         {
56cdf0e10cSrcweir         }
57cdf0e10cSrcweir 
TearDown()58977d62f2SDamjan Jovanovic         void TearDown()
59cdf0e10cSrcweir         {
60cdf0e10cSrcweir         }
61977d62f2SDamjan Jovanovic     }; // class test
62cdf0e10cSrcweir 
TEST_F(test,testInitUno)63977d62f2SDamjan Jovanovic     TEST_F(test, testInitUno)
64977d62f2SDamjan Jovanovic     {
65977d62f2SDamjan Jovanovic         bool bResult = false;
66cdf0e10cSrcweir 
67977d62f2SDamjan Jovanovic         // initialise UCB-Broker
68977d62f2SDamjan Jovanovic         uno::Reference<uno::XComponentContext>
69977d62f2SDamjan Jovanovic             xComponentContext
70977d62f2SDamjan Jovanovic             (::cppu::defaultBootstrap_InitialComponentContext());
71977d62f2SDamjan Jovanovic         OSL_ASSERT( xComponentContext.is() );
72cdf0e10cSrcweir 
73977d62f2SDamjan Jovanovic         xContext = xComponentContext;
74cdf0e10cSrcweir 
75977d62f2SDamjan Jovanovic         uno::Reference<lang::XMultiComponentFactory>
76977d62f2SDamjan Jovanovic             xFactory(xComponentContext->getServiceManager() );
77977d62f2SDamjan Jovanovic         OSL_ASSERT(xFactory.is());
78cdf0e10cSrcweir 
79977d62f2SDamjan Jovanovic         uno::Sequence<uno::Any> aUcbInitSequence(2);
80977d62f2SDamjan Jovanovic         aUcbInitSequence[0] <<=
81977d62f2SDamjan Jovanovic             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
82977d62f2SDamjan Jovanovic         aUcbInitSequence[1] <<=
83977d62f2SDamjan Jovanovic             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
84cdf0e10cSrcweir 
85977d62f2SDamjan Jovanovic         uno::Reference<lang::XMultiServiceFactory>
86977d62f2SDamjan Jovanovic             xServiceFactory(xFactory, uno::UNO_QUERY);
87977d62f2SDamjan Jovanovic         OSL_ASSERT( xServiceFactory.is() );
88cdf0e10cSrcweir 
89977d62f2SDamjan Jovanovic         if (xServiceFactory.is())
90977d62f2SDamjan Jovanovic         {
91977d62f2SDamjan Jovanovic             sal_Bool bRet =
92977d62f2SDamjan Jovanovic                 ::ucbhelper::ContentBroker::initialize(xServiceFactory,
93977d62f2SDamjan Jovanovic                                                  aUcbInitSequence);
94977d62f2SDamjan Jovanovic 
95977d62f2SDamjan Jovanovic             OSL_ASSERT(bRet);
96977d62f2SDamjan Jovanovic             if (bRet)
97cdf0e10cSrcweir             {
98977d62f2SDamjan Jovanovic                 uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >
99977d62f2SDamjan Jovanovic                     xNameContainer(xFactory->createInstanceWithContext
100977d62f2SDamjan Jovanovic                                    (::rtl::OUString::createFromAscii
101977d62f2SDamjan Jovanovic                                     ("com.sun.star.ucb.SimpleFileAccess" ),
102977d62f2SDamjan Jovanovic                                     xComponentContext), uno::UNO_QUERY );
103cdf0e10cSrcweir 
104977d62f2SDamjan Jovanovic                 if (xNameContainer.is())
105cdf0e10cSrcweir                 {
106977d62f2SDamjan Jovanovic                     xSimpleFileAccess = xNameContainer;
107977d62f2SDamjan Jovanovic 
108977d62f2SDamjan Jovanovic                     bResult = true;
109cdf0e10cSrcweir                 }
110cdf0e10cSrcweir             }
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir 
113977d62f2SDamjan Jovanovic         ASSERT_TRUE(bResult) << "UNO initialization failed";
114977d62f2SDamjan Jovanovic     }
115977d62f2SDamjan Jovanovic 
116977d62f2SDamjan Jovanovic     // insert your test code here.
TEST_F(test,testOpenFile)117977d62f2SDamjan Jovanovic     TEST_F(test, testOpenFile)
118977d62f2SDamjan Jovanovic     {
119977d62f2SDamjan Jovanovic         try
120cdf0e10cSrcweir         {
121977d62f2SDamjan Jovanovic             rtl_uString *dir=NULL;
122977d62f2SDamjan Jovanovic             osl_getProcessWorkingDir(&dir);
123977d62f2SDamjan Jovanovic             rtl_uString *fname=NULL;
124977d62f2SDamjan Jovanovic             //rtl_uString_newFromAscii(&fname, "/OpenDocument-v1.doc");
125977d62f2SDamjan Jovanovic             rtl_uString_newFromAscii(&fname, "/test.doc");
126977d62f2SDamjan Jovanovic             //rtl_uString_newFromAscii(&fname, "/numbers.doc");
127977d62f2SDamjan Jovanovic             rtl_uString *absfile=NULL;
128977d62f2SDamjan Jovanovic             rtl_uString_newConcat(&absfile, dir, fname);
129977d62f2SDamjan Jovanovic 
130977d62f2SDamjan Jovanovic             rtl::OUString sInputFileURL( absfile );
131977d62f2SDamjan Jovanovic 
132*b63233d8Sdamjan             for (sal_Int32 n = 0; n < sInputFileURL.getLength(); ++n)
133cdf0e10cSrcweir             {
134977d62f2SDamjan Jovanovic                 sal_uChar nC = sInputFileURL[n];
135cdf0e10cSrcweir 
136977d62f2SDamjan Jovanovic                 if (nC < 0xff && isprint(nC))
137977d62f2SDamjan Jovanovic                     clog << static_cast<char>(nC);
138977d62f2SDamjan Jovanovic                 else
139977d62f2SDamjan Jovanovic                     clog << ".";
140977d62f2SDamjan Jovanovic             }
141cdf0e10cSrcweir 
142977d62f2SDamjan Jovanovic             clog << endl;
143cdf0e10cSrcweir 
144977d62f2SDamjan Jovanovic             xStream = xSimpleFileAccess->openFileRead(sInputFileURL);
145cdf0e10cSrcweir 
146977d62f2SDamjan Jovanovic             WW8Stream::Pointer_t pStream =
147977d62f2SDamjan Jovanovic                 WW8DocumentFactory::createStream(xContext, xStream);
148cdf0e10cSrcweir 
149*b63233d8Sdamjan             pDocument.reset(WW8DocumentFactory::createDocument(pStream));
150977d62f2SDamjan Jovanovic         }
151977d62f2SDamjan Jovanovic         catch (::writerfilter::Exception e)
152977d62f2SDamjan Jovanovic         {
153977d62f2SDamjan Jovanovic             clog << "Exception!!" << endl;
154977d62f2SDamjan Jovanovic         }
155cdf0e10cSrcweir 
156977d62f2SDamjan Jovanovic         ASSERT_TRUE(pDocument != NULL) << "creating document failed";
157cdf0e10cSrcweir 
158977d62f2SDamjan Jovanovic     }
159cdf0e10cSrcweir 
TEST_F(test,testEvents)160977d62f2SDamjan Jovanovic     TEST_F(test, testEvents)
161977d62f2SDamjan Jovanovic     {
162977d62f2SDamjan Jovanovic         try
163cdf0e10cSrcweir         {
164977d62f2SDamjan Jovanovic             ::writerfilter::Stream::Pointer_t pStream = ::writerfilter::createStreamHandler();
165cdf0e10cSrcweir 
166977d62f2SDamjan Jovanovic             pDocument->resolve(*pStream);
167cdf0e10cSrcweir         }
168977d62f2SDamjan Jovanovic         catch (::writerfilter::Exception e)
169cdf0e10cSrcweir         {
170977d62f2SDamjan Jovanovic             clog << "Exception!!" << endl;
171cdf0e10cSrcweir         }
172977d62f2SDamjan Jovanovic     }
173cdf0e10cSrcweir 
TEST_F(test,testEnd)174977d62f2SDamjan Jovanovic     TEST_F(test, testEnd)
175977d62f2SDamjan Jovanovic     {
176977d62f2SDamjan Jovanovic         ::ucbhelper::ContentBroker::deinitialize();
177977d62f2SDamjan Jovanovic     }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
180977d62f2SDamjan Jovanovic } // namespace doctok
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 
main(int argc,char ** argv)183977d62f2SDamjan Jovanovic int main(int argc, char **argv)
184977d62f2SDamjan Jovanovic {
185977d62f2SDamjan Jovanovic     osl_setCommandArgs(argc, argv);
186977d62f2SDamjan Jovanovic     ::testing::InitGoogleTest(&argc, argv);
187977d62f2SDamjan Jovanovic     return RUN_ALL_TESTS();
188977d62f2SDamjan Jovanovic }
189