merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / util / _XURLTransformer.java
blob77207d8d134630ecf45aaf252c2481294a197347
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XURLTransformer.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.util;
33 import com.sun.star.util.URL;
34 import com.sun.star.util.XURLTransformer;
35 import lib.MultiMethodTest;
37 /**
38 * Testing <code>com.sun.star.util.XURLTransformer</code>
39 * interface methods :
40 * <ul>
41 * <li><code> assemble() </code></li>
42 * <li><code> parseStrict() </code></li>
43 * <li><code> parseSmart() </code></li>
44 * <li><code> getPresentation() </code></li>
45 * </ul> <p>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.util.XURLTransformer
49 public class _XURLTransformer extends MultiMethodTest {
51 public XURLTransformer oObj = null;
53 URL url;
55 final static String user = "user";
56 final static String invalidUserPrefix = "1";
57 final static String password = "password";
58 final static String server = "server";
59 final static String invalidServerPrefix = "1";
60 final static String port = "8080";
61 final static String path = "/pub/path";
62 final static String name = "file.txt";
63 final static String arguments = "a=b";
64 final static String mark = "mark";
66 final static String expectedCompleteHTTP = "http://"
67 + server + ":" + port + path
68 + "/" + name + "?" + arguments + "#" + mark;
69 final static String expectedCompleteFTP = "ftp://"
70 + user + ":" + password + "@" + server + ":" + port + path
71 + "/" + name;
73 /**
74 * First the complete URL (all URL fields are filled) is
75 * passed and assembled. Then incomplete URL (only
76 * <code>Server</code> field is set) is passed. <p>
77 * Has <b> OK </b> status if in the first case <code>true</code>
78 * retruned and <code>Complete</code> field is set and in the
79 * second case <code>false</code> is returned. <p>
81 public void _assemble(){
82 URL[] url = new URL[1];
83 url[0] = new URL();
85 url[0].Protocol = "http://";
86 url[0].Server = server;
87 url[0].Port = new Integer(port).shortValue();
88 url[0].Path = path;
89 url[0].Name = name;
90 url[0].Arguments = arguments;
91 url[0].Mark = mark;
92 url[0].Main = "http://" + server + ":" +
93 port + path + "/" + name;
95 boolean res = true;
97 log.print("assemble http-URL: ");
98 boolean complete = oObj.assemble(url);
99 log.println(complete);
100 res &= complete;
102 if (!expectedCompleteHTTP.equals(url[0].Complete)) {
103 log.println("assemble works wrong");
104 log.println("complete field : " + url[0].Complete);
105 log.println("expected : " + expectedCompleteHTTP);
106 res = false;
109 url[0] = new URL();
110 url[0].Protocol = "ftp://";
111 url[0].User = user;
112 url[0].Password = password;
113 url[0].Server = server;
114 url[0].Port = new Integer(port).shortValue();
115 url[0].Path = path;
116 url[0].Name = name;
117 url[0].Main = "ftp://" + user + ":" + password + "@" + server + ":" +
118 port + path + "/" + name;
120 log.print("assemble ftp-URL: ");
121 complete = oObj.assemble(url);
122 log.println(complete);
123 res &= complete;
125 if (!expectedCompleteFTP.equals(url[0].Complete)) {
126 log.println("assemble works wrong");
127 log.println("complete field : " + url[0].Complete);
128 log.println("expected : " + expectedCompleteFTP);
129 res = false;
132 URL[] incompleteUrl = new URL[1];
133 incompleteUrl[0] = new URL();
134 incompleteUrl[0].Server = server;
136 log.print("assemble incomplete URL: ");
137 complete = oObj.assemble(incompleteUrl);
138 log.println(complete);
139 res &= !complete;
141 // should be incomplete
142 tRes.tested("assemble()", res);
146 * First the complete URL (<code>Complete</code> field is set
147 * to proper URL) is passed and parsed. Then incomplete URL (only
148 * <code>Server</code> field is set) is passed. <p>
149 * Has <b> OK </b> status if in the first case <code>true</code>
150 * retruned and all URL fields are set to proper values and in the
151 * second case <code>false</code> is returned. <p>
153 public void _parseStrict() {
154 URL[] url = new URL[1];
156 url[0] = new URL();
157 url[0].Complete = expectedCompleteHTTP;
159 boolean res = true;
160 log.print("parseStrict(" + expectedCompleteHTTP + "): ");
161 boolean complete = oObj.parseStrict(url);
162 log.println(complete);
163 res &= complete;
165 if (!url[0].Protocol.equals("http://")) {
166 log.println("parseStrict works wrong");
167 log.println("protocol field : " + url[0].Protocol);
168 log.println("expected : http://");
169 res = false;
172 if (!url[0].Server.equals(server)) {
173 log.println("parseStrict works wrong");
174 log.println("server field : " + url[0].Server);
175 log.println("expected : " + server);
176 res = false;
179 if (url[0].Port != new Integer(port).shortValue()) {
180 log.println("parseStrict works wrong");
181 log.println("port field : " + url[0].Port);
182 log.println("expected : " + port);
183 res = false;
186 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
187 log.println("parseStrict works wrong");
188 log.println("path field : " + url[0].Path);
189 log.println("expected : " + path);
190 res = false;
193 if (!url[0].Name.equals(name)) {
194 log.println("parseStrict works wrong");
195 log.println("name field : " + url[0].Name);
196 log.println("expected : " + name);
197 res = false;
200 if (!url[0].Arguments.equals(arguments)) {
201 log.println("parseStrict works wrong");
202 log.println("arguments field : " + url[0].Arguments);
203 log.println("expected : " + arguments);
204 res = false;
207 if (!url[0].Mark.equals(mark)) {
208 log.println("parseStrict works wrong");
209 log.println("mark field : " + url[0].Mark);
210 log.println("expected : " + mark);
211 res = false;
214 url[0] = new URL();
215 url[0].Complete = expectedCompleteFTP;
217 log.print("parseStrict(" + expectedCompleteFTP + "): ");
218 complete = oObj.parseStrict(url);
219 log.println(complete);
220 res &= complete;
222 if (!url[0].Protocol.equals("ftp://")) {
223 log.println("parseStrict works wrong");
224 log.println("protocol field : " + url[0].Protocol);
225 log.println("expected : ftp://");
226 res = false;
229 if (!url[0].User.equals(user)) {
230 log.println("parseStrict works wrong");
231 log.println("user field : " + url[0].User);
232 log.println("expected : " + user);
233 res = false;
236 if (!url[0].Password.equals(password)) {
237 log.println("parseStrict works wrong");
238 log.println("password field : " + url[0].Password);
239 log.println("expected : " + password);
240 res = false;
243 if (!url[0].Server.equals(server)) {
244 log.println("parseStrict works wrong");
245 log.println("server field : " + url[0].Server);
246 log.println("expected : " + server);
247 res = false;
250 if (url[0].Port != new Integer(port).shortValue()) {
251 log.println("parseStrict works wrong");
252 log.println("port field : " + url[0].Port);
253 log.println("expected : " + port);
254 res = false;
257 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
258 log.println("parseStrict works wrong");
259 log.println("path field : " + url[0].Path);
260 log.println("expected : " + path);
261 res = false;
264 if (!url[0].Name.equals(name)) {
265 log.println("parseStrict works wrong");
266 log.println("name field : " + url[0].Name);
267 log.println("expected : " + name);
268 res = false;
271 URL[] incompleteUrl = new URL[1];
272 incompleteUrl[0] = new URL();
273 incompleteUrl[0].Complete = server;
275 log.print("parseStrict(" + server + "): ");
276 complete = oObj.parseStrict(incompleteUrl);
277 log.println(complete);
278 // should be incomplete
279 res &= !complete;
281 tRes.tested("parseStrict()", res);
285 * Tries to parse WWW server name. <p>
286 * Has <b> OK </b> status if the method return <code>true</code>
287 * value and <code>Protocol, Server, Port</code> URL fields are
288 * set properly.
290 public void _parseSmart() {
291 URL[] url = new URL[1];
293 String httpURL = invalidServerPrefix + server + ":" + port + path + "/" + name + "?" +
294 arguments + "#" + mark;
296 url[0] = new URL();
297 url[0].Complete = httpURL;
299 boolean res = true;
300 log.print("parseSmart('" + httpURL + "', 'http://'): ");
301 boolean complete = oObj.parseSmart(url, "http://");
302 log.println(complete);
303 res &= complete;
305 if (!url[0].Protocol.equals("http://")) {
306 log.println("parseSmart works wrong");
307 log.println("protocol field : " + url[0].Protocol);
308 log.println("expected : http://");
309 res = false;
312 if (!url[0].Server.equals(invalidServerPrefix+server)) {
313 log.println("parseSmart works wrong");
314 log.println("server field : " + url[0].Server);
315 log.println("expected : " + server);
316 res = false;
319 if (url[0].Port != new Integer(port).shortValue()) {
320 log.println("parseSmart works wrong");
321 log.println("port field : " + url[0].Port);
322 log.println("expected : " + port);
323 res = false;
326 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
327 log.println("parseSmart works wrong");
328 log.println("path field : " + url[0].Path);
329 log.println("expected : " + path);
330 res = false;
333 if (!url[0].Name.equals(name)) {
334 log.println("parseSmart works wrong");
335 log.println("name field : " + url[0].Name);
336 log.println("expected : " + name);
337 res = false;
340 if (!url[0].Arguments.equals(arguments)) {
341 log.println("parseSmart works wrong");
342 log.println("arguments field : " + url[0].Arguments);
343 log.println("expected : " + arguments);
344 res = false;
347 if (!url[0].Mark.equals(mark)) {
348 log.println("parseSmart works wrong");
349 log.println("mark field : " + url[0].Mark);
350 log.println("expected : " + mark);
351 res = false;
354 String ftpURL = invalidUserPrefix +user + ":" + password + "@" + server + ":" +
355 port + path + "/" + name;
357 url[0] = new URL();
358 url[0].Complete = ftpURL;
359 log.print("parseSmart('" + ftpURL + "', 'ftp://'): ");
360 complete = oObj.parseSmart(url, "ftp://");
361 log.println(complete);
362 res &= complete;
364 if (!url[0].Protocol.equals("ftp://")) {
365 log.println("parseSmart works wrong");
366 log.println("protocol field : " + url[0].Protocol);
367 log.println("expected : ftp://");
368 res = false;
371 if (!url[0].User.equals(invalidUserPrefix+user)) {
372 log.println("parseSmart works wrong");
373 log.println("user field : " + url[0].User);
374 log.println("expected : " + user);
375 res = false;
378 if (!url[0].Password.equals(password)) {
379 log.println("parseSmart works wrong");
380 log.println("password field : " + url[0].Password);
381 log.println("expected : " + password);
382 res = false;
385 if (!url[0].Server.equals(server)) {
386 log.println("parseSmart works wrong");
387 log.println("server field : " + url[0].Server);
388 log.println("expected : " + server);
389 res = false;
392 if (url[0].Port != new Integer(port).shortValue()) {
393 log.println("parseSmart works wrong");
394 log.println("port field : " + url[0].Port);
395 log.println("expected : " + port);
396 res = false;
399 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
400 log.println("parseSmart works wrong");
401 log.println("path field : " + url[0].Path);
402 log.println("expected : " + path);
403 res = false;
406 if (!url[0].Name.equals(name)) {
407 log.println("parseSmart works wrong");
408 log.println("name field : " + url[0].Name);
409 log.println("expected : " + name);
410 res = false;
413 tRes.tested("parseSmart()", res);
417 * Gets the presentation of a URL. <p>
418 * Has <b> OK </b> status if the method returns the same
419 * URL as was passed in parameter.
421 public void _getPresentation() {
422 URL url = new URL();
424 url.Complete = expectedCompleteHTTP;
426 log.println("getPresentation('" + expectedCompleteHTTP + "', true): ");
427 String presentation = oObj.getPresentation(url, true);
428 boolean res = presentation.equals(expectedCompleteHTTP);
429 log.println("Resulted presentation: " + presentation);
430 log.println("Expected presentation: " + expectedCompleteHTTP);
431 log.println("Result: " + res);
433 url.Complete = expectedCompleteFTP;
434 log.println("getPresentation('" + expectedCompleteFTP + "', false): ");
435 // the password must be masqurade with <****>
436 String asterix = "";
437 for (int n = 0 ; n < password.length(); n++){
438 asterix += "*";
440 asterix = "<" + asterix.substring(1,asterix.length());
441 asterix = asterix.substring(0,asterix.length()-1) + ">";
443 presentation = oObj.getPresentation(url, false);
444 String expectedPresentation = "ftp://" + user + ":" + asterix + "@" +
445 server + ":" + port + path + "/" + name;
446 res &= presentation.equals(expectedPresentation);
447 log.println("Resulted presentation: " + presentation);
448 log.println("Expected presentation: " + expectedPresentation);
449 log.println("Result: " + res);
451 log.println("getPresentation('" + expectedCompleteFTP + "', true): ");
452 presentation = oObj.getPresentation(url, true);
453 expectedPresentation = "ftp://" + user + ":" + password + "@" +
454 server + ":" + port + path + "/" + name;
455 res &= presentation.equals(expectedPresentation);
456 log.println("Resulted presentation: " + presentation);
457 log.println("Expected presentation: " + expectedPresentation);
458 log.println("Result: " + res);
460 String incorrectURL = "*bla-bla*";
461 url.Complete = incorrectURL;
462 log.println("getPresentation('" + incorrectURL + "', false): ");
463 presentation = oObj.getPresentation(url, false);
464 expectedPresentation = "";
465 res &= presentation.equals(expectedPresentation);
466 log.println("Resulted presentation: " + presentation);
467 log.println("Expected presentation: " + expectedPresentation);
468 log.println("Result: " + res);
470 tRes.tested("getPresentation()", res);
473 } // finish class _XURLTransformer