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  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // autogenerated file with codegen.pl
23 
24 #include "gtest/gtest.h"
25 
26 #include <osl/process.h>
27 #include <ucbhelper/contentbroker.hxx>
28 #include <cppuhelper/bootstrap.hxx>
29 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 
34 #include <doctok/WW8Document.hxx>
35 
36 #include <iostream>
37 
38 namespace testdoctok
39 {
40     using namespace ::std;
41     using namespace ::com::sun::star;
42     using namespace ::writerfilter::doctok;
43 
44     uno::Reference<io::XInputStream> xStream;
45     uno::Reference<uno::XComponentContext> xContext;
46     WW8Document::Pointer_t pDocument;
47     uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleFileAccess;
48 
49     class test : public ::testing::Test
50     {
51 
52     public:
53         // initialise your test code values here.
SetUp()54         void SetUp()
55         {
56         }
57 
TearDown()58         void TearDown()
59         {
60         }
61     }; // class test
62 
TEST_F(test,testInitUno)63     TEST_F(test, testInitUno)
64     {
65         bool bResult = false;
66 
67         // initialise UCB-Broker
68         uno::Reference<uno::XComponentContext>
69             xComponentContext
70             (::cppu::defaultBootstrap_InitialComponentContext());
71         OSL_ASSERT( xComponentContext.is() );
72 
73         xContext = xComponentContext;
74 
75         uno::Reference<lang::XMultiComponentFactory>
76             xFactory(xComponentContext->getServiceManager() );
77         OSL_ASSERT(xFactory.is());
78 
79         uno::Sequence<uno::Any> aUcbInitSequence(2);
80         aUcbInitSequence[0] <<=
81             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
82         aUcbInitSequence[1] <<=
83             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
84 
85         uno::Reference<lang::XMultiServiceFactory>
86             xServiceFactory(xFactory, uno::UNO_QUERY);
87         OSL_ASSERT( xServiceFactory.is() );
88 
89         if (xServiceFactory.is())
90         {
91             sal_Bool bRet =
92                 ::ucbhelper::ContentBroker::initialize(xServiceFactory,
93                                                  aUcbInitSequence);
94 
95             OSL_ASSERT(bRet);
96             if (bRet)
97             {
98                 uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >
99                     xNameContainer(xFactory->createInstanceWithContext
100                                    (::rtl::OUString::createFromAscii
101                                     ("com.sun.star.ucb.SimpleFileAccess" ),
102                                     xComponentContext), uno::UNO_QUERY );
103 
104                 if (xNameContainer.is())
105                 {
106                     xSimpleFileAccess = xNameContainer;
107 
108                     bResult = true;
109                 }
110             }
111         }
112 
113         ASSERT_TRUE(bResult) << "UNO initialization failed";
114     }
115 
116     // insert your test code here.
TEST_F(test,testOpenFile)117     TEST_F(test, testOpenFile)
118     {
119         try
120         {
121             rtl_uString *dir=NULL;
122             osl_getProcessWorkingDir(&dir);
123             rtl_uString *fname=NULL;
124             //rtl_uString_newFromAscii(&fname, "/OpenDocument-v1.doc");
125             rtl_uString_newFromAscii(&fname, "/test.doc");
126             //rtl_uString_newFromAscii(&fname, "/numbers.doc");
127             rtl_uString *absfile=NULL;
128             rtl_uString_newConcat(&absfile, dir, fname);
129 
130             rtl::OUString sInputFileURL( absfile );
131 
132             for (sal_Int32 n = 0; n < sInputFileURL.getLength(); ++n)
133             {
134                 sal_uChar nC = sInputFileURL[n];
135 
136                 if (nC < 0xff && isprint(nC))
137                     clog << static_cast<char>(nC);
138                 else
139                     clog << ".";
140             }
141 
142             clog << endl;
143 
144             xStream = xSimpleFileAccess->openFileRead(sInputFileURL);
145 
146             WW8Stream::Pointer_t pStream =
147                 WW8DocumentFactory::createStream(xContext, xStream);
148 
149             pDocument.reset(WW8DocumentFactory::createDocument(pStream));
150         }
151         catch (::writerfilter::Exception e)
152         {
153             clog << "Exception!!" << endl;
154         }
155 
156         ASSERT_TRUE(pDocument != NULL) << "creating document failed";
157 
158     }
159 
TEST_F(test,testEvents)160     TEST_F(test, testEvents)
161     {
162         try
163         {
164             ::writerfilter::Stream::Pointer_t pStream = ::writerfilter::createStreamHandler();
165 
166             pDocument->resolve(*pStream);
167         }
168         catch (::writerfilter::Exception e)
169         {
170             clog << "Exception!!" << endl;
171         }
172     }
173 
TEST_F(test,testEnd)174     TEST_F(test, testEnd)
175     {
176         ::ucbhelper::ContentBroker::deinitialize();
177     }
178 
179 
180 } // namespace doctok
181 
182 
main(int argc,char ** argv)183 int main(int argc, char **argv)
184 {
185     osl_setCommandArgs(argc, argv);
186     ::testing::InitGoogleTest(&argc, argv);
187     return RUN_ALL_TESTS();
188 }
189