1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2f86921cSAndrew Rist * distributed with this work for additional information
6*2f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist * with the License. You may obtain a copy of the License at
10*2f86921cSAndrew Rist *
11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist *
13*2f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist * KIND, either express or implied. See the License for the
17*2f86921cSAndrew Rist * specific language governing permissions and limitations
18*2f86921cSAndrew Rist * under the License.
19*2f86921cSAndrew Rist *
20*2f86921cSAndrew Rist *************************************************************/
21*2f86921cSAndrew Rist
22*2f86921cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir TODO
29cdf0e10cSrcweir **************************************************************************
30cdf0e10cSrcweir
31cdf0e10cSrcweir *************************************************************************/
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "test_ftpurl.hxx"
34cdf0e10cSrcweir #include <stdio.h>
35cdf0e10cSrcweir #include <unistd.h>
36cdf0e10cSrcweir
37cdf0e10cSrcweir // #include <osl/process.h>
38cdf0e10cSrcweir // #include <osl/thread.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir // #include <ucbhelper/configurationkeys.hxx>
41cdf0e10cSrcweir // #include <cppuhelper/bootstrap.hxx>
42cdf0e10cSrcweir // #include <cppuhelper/servicefactory.hxx>
43cdf0e10cSrcweir // #include <comphelper/processfactory.hxx>
44cdf0e10cSrcweir // #include <comphelper/regpathhelper.hxx>
45cdf0e10cSrcweir // #include <com/sun/star/lang/XComponent.hpp>
46cdf0e10cSrcweir // #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47cdf0e10cSrcweir // #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
48cdf0e10cSrcweir // #include <com/sun/star/ucb/XContent.hpp>
49cdf0e10cSrcweir // #include <com/sun/star/ucb/XContentProvider.hpp>
50cdf0e10cSrcweir // #include <com/sun/star/ucb/XCommandProcessor.hpp>
51cdf0e10cSrcweir // #include <com/sun/star/ucb/OpenMode.hpp>
52cdf0e10cSrcweir // #include <com/sun/star/ucb/Command.hpp>
53cdf0e10cSrcweir // #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
54cdf0e10cSrcweir // #include <com/sun/star/io/XActiveDataSink.hpp>
55cdf0e10cSrcweir // #include <com/sun/star/beans/Property.hpp>
56cdf0e10cSrcweir
57cdf0e10cSrcweir
58cdf0e10cSrcweir // #include "debughelper.hxx"
59cdf0e10cSrcweir // #include "test_activedatasink.hxx"
60cdf0e10cSrcweir // #include "test_ftpurl.hxx"
61cdf0e10cSrcweir // #include "test_multiservicefac.hxx"
62cdf0e10cSrcweir // #include "ftpcontentprovider.hxx"
63cdf0e10cSrcweir // #include "ftpcontentidentifier.hxx"
64cdf0e10cSrcweir
65cdf0e10cSrcweir
66cdf0e10cSrcweir // using namespace test_ftp;
67cdf0e10cSrcweir // using namespace rtl;
68cdf0e10cSrcweir // using namespace com::sun::star::uno;
69cdf0e10cSrcweir // using namespace com::sun::star::lang;
70cdf0e10cSrcweir // using namespace com::sun::star::ucb;
71cdf0e10cSrcweir // using namespace com::sun::star::beans;
72cdf0e10cSrcweir // using namespace com::sun::star::io;
73cdf0e10cSrcweir
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir // class FTPThread
77cdf0e10cSrcweir // : public osl::Thread
78cdf0e10cSrcweir // {
79cdf0e10cSrcweir // public:
80cdf0e10cSrcweir
81cdf0e10cSrcweir // FTPThread();
82cdf0e10cSrcweir
83cdf0e10cSrcweir // int number_of_errors() { return _number_of_errors; }
84cdf0e10cSrcweir
85cdf0e10cSrcweir // protected:
86cdf0e10cSrcweir
87cdf0e10cSrcweir // void SAL_CALL run();
88cdf0e10cSrcweir
89cdf0e10cSrcweir
90cdf0e10cSrcweir // private:
91cdf0e10cSrcweir
92cdf0e10cSrcweir // ftp::FTPContentProvider *pProvider;
93cdf0e10cSrcweir // Reference<XContentProvider> xProvider;
94cdf0e10cSrcweir // Reference<XMultiServiceFactory> xFac;
95cdf0e10cSrcweir
96cdf0e10cSrcweir // int _number_of_errors;
97cdf0e10cSrcweir // };
98cdf0e10cSrcweir
99cdf0e10cSrcweir
100cdf0e10cSrcweir // Reference< XMultiServiceFactory > createApplicationServiceManager()
101cdf0e10cSrcweir // {
102cdf0e10cSrcweir // try
103cdf0e10cSrcweir // {
104cdf0e10cSrcweir // Reference<XComponentContext> xComponentContext =
105cdf0e10cSrcweir // ::cppu::defaultBootstrap_InitialComponentContext();
106cdf0e10cSrcweir // Reference<XMultiServiceFactory> xMS(
107cdf0e10cSrcweir // xComponentContext->getServiceManager(),
108cdf0e10cSrcweir // UNO_QUERY);
109cdf0e10cSrcweir
110cdf0e10cSrcweir // return xMS;
111cdf0e10cSrcweir // }
112cdf0e10cSrcweir // catch( ::com::sun::star::uno::Exception& )
113cdf0e10cSrcweir // {
114cdf0e10cSrcweir // return Reference< XMultiServiceFactory >();
115cdf0e10cSrcweir // }
116cdf0e10cSrcweir // }
117cdf0e10cSrcweir
118cdf0e10cSrcweir
119cdf0e10cSrcweir // FTPThread::FTPThread()
120cdf0e10cSrcweir // : _number_of_errors(0),
121cdf0e10cSrcweir // xFac(createApplicationServiceManager())
122cdf0e10cSrcweir // {
123cdf0e10cSrcweir // pProvider = new ftp::FTPContentProvider(xFac);
124cdf0e10cSrcweir // xProvider = Reference<XContentProvider>(pProvider);
125cdf0e10cSrcweir
126cdf0e10cSrcweir // if(!xProvider.is())
127cdf0e10cSrcweir // ++_number_of_errors;
128cdf0e10cSrcweir // }
129cdf0e10cSrcweir
130cdf0e10cSrcweir
131cdf0e10cSrcweir // void FTPThread::run() {
132cdf0e10cSrcweir // if(!xFac.is()) {
133cdf0e10cSrcweir // ++_number_of_errors;
134cdf0e10cSrcweir // exit(1);
135cdf0e10cSrcweir // }
136cdf0e10cSrcweir
137cdf0e10cSrcweir // Reference<XContentIdentifier> xIdent(
138cdf0e10cSrcweir // new ftp::FTPContentIdentifier(
139cdf0e10cSrcweir // rtl::OUString::createFromAscii("ftp://abi:psswd@abi-1/file"),
140cdf0e10cSrcweir // pProvider));
141cdf0e10cSrcweir
142cdf0e10cSrcweir // Reference<XContent> xContent = xProvider->queryContent(xIdent);
143cdf0e10cSrcweir // if(!xContent.is())
144cdf0e10cSrcweir // {
145cdf0e10cSrcweir // err_msg("no content",OUString());
146cdf0e10cSrcweir // exit(1);
147cdf0e10cSrcweir // }
148cdf0e10cSrcweir
149cdf0e10cSrcweir
150cdf0e10cSrcweir // Reference<XActiveDataSink> xActDS(new Test_ActiveDataSink());
151cdf0e10cSrcweir // OpenCommandArgument2 aOpenCommand(OpenMode::DOCUMENT,
152cdf0e10cSrcweir // 0,
153cdf0e10cSrcweir // Reference<XInterface>(xActDS,UNO_QUERY),
154cdf0e10cSrcweir // Sequence<Property>(0),
155cdf0e10cSrcweir // Sequence<NumberedSortingInfo>(0));
156cdf0e10cSrcweir // Any aAny; aAny <<= aOpenCommand;
157cdf0e10cSrcweir
158cdf0e10cSrcweir // Command aCommand(OUString::createFromAscii("open"),
159cdf0e10cSrcweir // -1,
160cdf0e10cSrcweir // aAny);
161cdf0e10cSrcweir
162cdf0e10cSrcweir // Reference<XCommandProcessor> xCommandProcessor(xContent,UNO_QUERY);
163cdf0e10cSrcweir // if(!xCommandProcessor.is())
164cdf0e10cSrcweir // {
165cdf0e10cSrcweir // err_msg("no command_processor",OUString());
166cdf0e10cSrcweir // exit(1);
167cdf0e10cSrcweir // }
168cdf0e10cSrcweir // xCommandProcessor->execute(aCommand,
169cdf0e10cSrcweir // 0,Reference<XCommandEnvironment>(0));
170cdf0e10cSrcweir
171cdf0e10cSrcweir // Reference<XInputStream> xInputStream = xActDS->getInputStream();
172cdf0e10cSrcweir // if(!xInputStream.is())
173cdf0e10cSrcweir // ;
174cdf0e10cSrcweir // }
175cdf0e10cSrcweir
176cdf0e10cSrcweir
main(int argc,char * argv[])177cdf0e10cSrcweir int main(int argc,char* argv[])
178cdf0e10cSrcweir {
179cdf0e10cSrcweir // FTPThread aThread;
180cdf0e10cSrcweir // aThread.create();
181cdf0e10cSrcweir // aThread.join();
182cdf0e10cSrcweir
183cdf0e10cSrcweir typedef int (*INT_FUNC)(void);
184cdf0e10cSrcweir INT_FUNC tests[] = { test_ftpurl,
185cdf0e10cSrcweir test_ftpparent,
186cdf0e10cSrcweir test_ftpproperties,
187cdf0e10cSrcweir test_ftpopen,
188cdf0e10cSrcweir test_ftplist,
189cdf0e10cSrcweir 0 }; // don't remove ending zero
190cdf0e10cSrcweir
191cdf0e10cSrcweir int err_level = 0;
192cdf0e10cSrcweir
193cdf0e10cSrcweir fprintf(stderr,"------- Testing ----------\n");
194cdf0e10cSrcweir
195cdf0e10cSrcweir int i = -1;
196cdf0e10cSrcweir do {
197cdf0e10cSrcweir INT_FUNC f = tests[++i];
198cdf0e10cSrcweir if(f) {
199cdf0e10cSrcweir err_level += (*f)();
200cdf0e10cSrcweir fprintf(stderr,".");
201cdf0e10cSrcweir } else
202cdf0e10cSrcweir break;
203cdf0e10cSrcweir } while(true);
204cdf0e10cSrcweir
205cdf0e10cSrcweir if(err_level) {
206cdf0e10cSrcweir fprintf(stderr,"number of failed tests: %d\n",err_level);
207cdf0e10cSrcweir fprintf(stderr,"----------------------------------\n");
208cdf0e10cSrcweir } else
209cdf0e10cSrcweir fprintf(stderr,"no errors\n");
210cdf0e10cSrcweir
211cdf0e10cSrcweir return err_level;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir
215cdf0e10cSrcweir
216cdf0e10cSrcweir // char *scefile = 0;
217cdf0e10cSrcweir // if(strcmp(argv[1],"-sce") == 0)
218cdf0e10cSrcweir // scefile = argv[2];
219cdf0e10cSrcweir
220cdf0e10cSrcweir // if(!scefile) {
221cdf0e10cSrcweir // fprintf(stderr,"usage: ftptest -sce filename\n");
222cdf0e10cSrcweir // return 1;
223cdf0e10cSrcweir // }
224cdf0e10cSrcweir
225cdf0e10cSrcweir // rtl::OUString sceurl;
226cdf0e10cSrcweir // osl::FileBase::RC err =
227cdf0e10cSrcweir // osl::FileBase::getFileURLFromSystemPath(
228cdf0e10cSrcweir // rtl::OUString(scefile,
229cdf0e10cSrcweir // strlen(scefile),
230cdf0e10cSrcweir // RTL_TEXTENCODING_UTF8),
231cdf0e10cSrcweir // sceurl);
232cdf0e10cSrcweir
233cdf0e10cSrcweir // osl::File aFile(sceurl);
234cdf0e10cSrcweir // err = aFile.open(OpenFlag_Read);
235cdf0e10cSrcweir // if(err != osl::FileBase::E_None) {
236cdf0e10cSrcweir // fprintf(stderr,"could not open sce-file %s\n",scefile);
237cdf0e10cSrcweir // return 1;
238cdf0e10cSrcweir // }
239cdf0e10cSrcweir
240cdf0e10cSrcweir // sal_uInt64 n;
241cdf0e10cSrcweir // char buffer[256];
242cdf0e10cSrcweir // rtl::OUStringBuffer bff;
243cdf0e10cSrcweir // do {
244cdf0e10cSrcweir // err = aFile.read((void*)buffer,256,n);
245cdf0e10cSrcweir // bff.appendAscii(buffer,sal_Int32(n));
246cdf0e10cSrcweir // } while(err == osl::FileBase::E_None && n == 256);
247cdf0e10cSrcweir
248cdf0e10cSrcweir // aFile.close();
249cdf0e10cSrcweir
250cdf0e10cSrcweir // rtl::OUString sce = bff.makeStringAndClear();
251cdf0e10cSrcweir
252cdf0e10cSrcweir // fprintf(stderr,rtl::OString(sce.getStr(),
253cdf0e10cSrcweir // sce.getLength(),
254cdf0e10cSrcweir // RTL_TEXTENCODING_UTF8).getStr());
255cdf0e10cSrcweir
256cdf0e10cSrcweir // rtl::OUString lib,tmp,testlib;
257cdf0e10cSrcweir // std::vector<rtl::OUString> tests;
258cdf0e10cSrcweir // sal_Int32 TEST = sce.indexOf(rtl::OUString::createFromAscii("TEST"));
259cdf0e10cSrcweir // sal_Int32 WITH = sce.indexOf(rtl::OUString::createFromAscii("WITH"));
260cdf0e10cSrcweir // sal_Int32 FROM = sce.indexOf(rtl::OUString::createFromAscii("FROM"));
261cdf0e10cSrcweir // lib = sce.copy(TEST+4,WITH-TEST-4).trim();
262cdf0e10cSrcweir
263cdf0e10cSrcweir // tmp = sce.copy(WITH+4,FROM-WITH-4).trim();
264cdf0e10cSrcweir // sal_Int32 nIndex = 0;
265cdf0e10cSrcweir // do
266cdf0e10cSrcweir // {
267cdf0e10cSrcweir // rtl::OUString token = tmp.getToken(0,';',nIndex).trim();
268cdf0e10cSrcweir // if(token.getLength())
269cdf0e10cSrcweir // tests.push_back(token);
270cdf0e10cSrcweir // } while(nIndex >= 0);
271cdf0e10cSrcweir
272cdf0e10cSrcweir // testlib = sce.copy(FROM+4).trim();
273cdf0e10cSrcweir
274cdf0e10cSrcweir // // fprintf(stderr,"%s\n",
275cdf0e10cSrcweir // // rtl::OString(token.getStr(),
276cdf0e10cSrcweir // // token.getLength(),
277cdf0e10cSrcweir // // RTL_TEXTENCODING_UTF8).getStr());
278cdf0e10cSrcweir
279cdf0e10cSrcweir // osl::Module testLib;
280cdf0e10cSrcweir // if(!testLib.load(testlib)) {
281cdf0e10cSrcweir // fprintf(stderr,"library not found: %s\n",
282cdf0e10cSrcweir // rtl::OString(testlib.getStr(),
283cdf0e10cSrcweir // testlib.getLength(),
284cdf0e10cSrcweir // RTL_TEXTENCODING_UTF8).getStr());
285cdf0e10cSrcweir // return 1;
286cdf0e10cSrcweir // }
287cdf0e10cSrcweir
288cdf0e10cSrcweir // osl::Module mathLib;
289cdf0e10cSrcweir // mathLib.load(rtl::OUString::createFromAscii("libm.so"));
290cdf0e10cSrcweir // typedef double (*DF)(double);
291cdf0e10cSrcweir // DF func = (DF)mathLib.getSymbol(rtl::OUString::createFromAscii("cos"));
292cdf0e10cSrcweir // fprintf(stderr,"-------double %f ----------\n",(*func)(2.0));
293cdf0e10cSrcweir
294cdf0e10cSrcweir // fprintf(stderr,"-------testing %s ----------\n",scefile);
295