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