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