Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XURLTransformer.java
blob3955cb9c5cbfa1767410942146759269aac45275
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.util;
21 import com.sun.star.util.URL;
22 import com.sun.star.util.XURLTransformer;
23 import lib.MultiMethodTest;
25 /**
26 * Testing <code>com.sun.star.util.XURLTransformer</code>
27 * interface methods :
28 * <ul>
29 * <li><code> assemble() </code></li>
30 * <li><code> parseStrict() </code></li>
31 * <li><code> parseSmart() </code></li>
32 * <li><code> getPresentation() </code></li>
33 * </ul> <p>
34 * Test is <b> NOT </b> multithread compliant. <p>
35 * @see com.sun.star.util.XURLTransformer
37 public class _XURLTransformer extends MultiMethodTest {
39 public XURLTransformer oObj = null;
41 URL url;
43 final static String user = "user";
44 final static String invalidUserPrefix = "1";
45 final static String password = "password";
46 final static String server = "server";
47 final static String invalidServerPrefix = "1";
48 final static String port = "8080";
49 final static String path = "/pub/path";
50 final static String name = "file.txt";
51 final static String arguments = "a=b";
52 final static String mark = "mark";
54 final static String expectedCompleteHTTP = "http://"
55 + server + ":" + port + path
56 + "/" + name + "?" + arguments + "#" + mark;
57 final static String expectedCompleteFTP = "ftp://"
58 + user + ":" + password + "@" + server + ":" + port + path
59 + "/" + name;
61 /**
62 * First the complete URL (all URL fields are filled) is
63 * passed and assembled. Then incomplete URL (only
64 * <code>Server</code> field is set) is passed. <p>
65 * Has <b> OK </b> status if in the first case <code>true</code>
66 * retruned and <code>Complete</code> field is set and in the
67 * second case <code>false</code> is returned. <p>
69 public void _assemble(){
70 URL[] url = new URL[1];
71 url[0] = new URL();
73 url[0].Protocol = "http://";
74 url[0].Server = server;
75 url[0].Port = Short.parseShort(port);
76 url[0].Path = path;
77 url[0].Name = name;
78 url[0].Arguments = arguments;
79 url[0].Mark = mark;
80 url[0].Main = "http://" + server + ":" +
81 port + path + "/" + name;
83 boolean res = true;
85 log.print("assemble http-URL: ");
86 boolean complete = oObj.assemble(url);
87 log.println(complete);
88 res &= complete;
90 if (!expectedCompleteHTTP.equals(url[0].Complete)) {
91 log.println("assemble works wrong");
92 log.println("complete field : " + url[0].Complete);
93 log.println("expected : " + expectedCompleteHTTP);
94 res = false;
97 url[0] = new URL();
98 url[0].Protocol = "ftp://";
99 url[0].User = user;
100 url[0].Password = password;
101 url[0].Server = server;
102 url[0].Port = Short.parseShort(port);
103 url[0].Path = path;
104 url[0].Name = name;
105 url[0].Main = "ftp://" + user + ":" + password + "@" + server + ":" +
106 port + path + "/" + name;
108 log.print("assemble ftp-URL: ");
109 complete = oObj.assemble(url);
110 log.println(complete);
111 res &= complete;
113 if (!expectedCompleteFTP.equals(url[0].Complete)) {
114 log.println("assemble works wrong");
115 log.println("complete field : " + url[0].Complete);
116 log.println("expected : " + expectedCompleteFTP);
117 res = false;
120 URL[] incompleteUrl = new URL[1];
121 incompleteUrl[0] = new URL();
122 incompleteUrl[0].Server = server;
124 log.print("assemble incomplete URL: ");
125 complete = oObj.assemble(incompleteUrl);
126 log.println(complete);
127 res &= !complete;
129 // should be incomplete
130 tRes.tested("assemble()", res);
134 * First the complete URL (<code>Complete</code> field is set
135 * to proper URL) is passed and parsed. Then incomplete URL (only
136 * <code>Server</code> field is set) is passed. <p>
137 * Has <b> OK </b> status if in the first case <code>true</code>
138 * retruned and all URL fields are set to proper values and in the
139 * second case <code>false</code> is returned. <p>
141 public void _parseStrict() {
142 URL[] url = new URL[1];
144 url[0] = new URL();
145 url[0].Complete = expectedCompleteHTTP;
147 boolean res = true;
148 log.print("parseStrict(" + expectedCompleteHTTP + "): ");
149 boolean complete = oObj.parseStrict(url);
150 log.println(complete);
151 res &= complete;
153 if (!url[0].Protocol.equals("http://")) {
154 log.println("parseStrict works wrong");
155 log.println("protocol field : " + url[0].Protocol);
156 log.println("expected : http://");
157 res = false;
160 if (!url[0].Server.equals(server)) {
161 log.println("parseStrict works wrong");
162 log.println("server field : " + url[0].Server);
163 log.println("expected : " + server);
164 res = false;
167 if (url[0].Port != Short.parseShort(port)) {
168 log.println("parseStrict works wrong");
169 log.println("port field : " + url[0].Port);
170 log.println("expected : " + port);
171 res = false;
174 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
175 log.println("parseStrict works wrong");
176 log.println("path field : " + url[0].Path);
177 log.println("expected : " + path);
178 res = false;
181 if (!url[0].Name.equals(name)) {
182 log.println("parseStrict works wrong");
183 log.println("name field : " + url[0].Name);
184 log.println("expected : " + name);
185 res = false;
188 if (!url[0].Arguments.equals(arguments)) {
189 log.println("parseStrict works wrong");
190 log.println("arguments field : " + url[0].Arguments);
191 log.println("expected : " + arguments);
192 res = false;
195 if (!url[0].Mark.equals(mark)) {
196 log.println("parseStrict works wrong");
197 log.println("mark field : " + url[0].Mark);
198 log.println("expected : " + mark);
199 res = false;
202 url[0] = new URL();
203 url[0].Complete = expectedCompleteFTP;
205 log.print("parseStrict(" + expectedCompleteFTP + "): ");
206 complete = oObj.parseStrict(url);
207 log.println(complete);
208 res &= complete;
210 if (!url[0].Protocol.equals("ftp://")) {
211 log.println("parseStrict works wrong");
212 log.println("protocol field : " + url[0].Protocol);
213 log.println("expected : ftp://");
214 res = false;
217 if (!url[0].User.equals(user)) {
218 log.println("parseStrict works wrong");
219 log.println("user field : " + url[0].User);
220 log.println("expected : " + user);
221 res = false;
224 if (!url[0].Password.equals(password)) {
225 log.println("parseStrict works wrong");
226 log.println("password field : " + url[0].Password);
227 log.println("expected : " + password);
228 res = false;
231 if (!url[0].Server.equals(server)) {
232 log.println("parseStrict works wrong");
233 log.println("server field : " + url[0].Server);
234 log.println("expected : " + server);
235 res = false;
238 if (url[0].Port != Short.parseShort(port)) {
239 log.println("parseStrict works wrong");
240 log.println("port field : " + url[0].Port);
241 log.println("expected : " + port);
242 res = false;
245 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
246 log.println("parseStrict works wrong");
247 log.println("path field : " + url[0].Path);
248 log.println("expected : " + path);
249 res = false;
252 if (!url[0].Name.equals(name)) {
253 log.println("parseStrict works wrong");
254 log.println("name field : " + url[0].Name);
255 log.println("expected : " + name);
256 res = false;
259 URL[] incompleteUrl = new URL[1];
260 incompleteUrl[0] = new URL();
261 incompleteUrl[0].Complete = server;
263 log.print("parseStrict(" + server + "): ");
264 complete = oObj.parseStrict(incompleteUrl);
265 log.println(complete);
266 // should be incomplete
267 res &= !complete;
269 tRes.tested("parseStrict()", res);
273 * Tries to parse WWW server name. <p>
274 * Has <b> OK </b> status if the method return <code>true</code>
275 * value and <code>Protocol, Server, Port</code> URL fields are
276 * set properly.
278 public void _parseSmart() {
279 URL[] url = new URL[1];
281 String httpURL = invalidServerPrefix + server + ":" + port + path + "/" + name + "?" +
282 arguments + "#" + mark;
284 url[0] = new URL();
285 url[0].Complete = httpURL;
287 boolean res = true;
288 log.print("parseSmart('" + httpURL + "', 'http://'): ");
289 boolean complete = oObj.parseSmart(url, "http://");
290 log.println(complete);
291 res &= complete;
293 if (!url[0].Protocol.equals("http://")) {
294 log.println("parseSmart works wrong");
295 log.println("protocol field : " + url[0].Protocol);
296 log.println("expected : http://");
297 res = false;
300 if (!url[0].Server.equals(invalidServerPrefix+server)) {
301 log.println("parseSmart works wrong");
302 log.println("server field : " + url[0].Server);
303 log.println("expected : " + server);
304 res = false;
307 if (url[0].Port != Short.parseShort(port)) {
308 log.println("parseSmart works wrong");
309 log.println("port field : " + url[0].Port);
310 log.println("expected : " + port);
311 res = false;
314 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
315 log.println("parseSmart works wrong");
316 log.println("path field : " + url[0].Path);
317 log.println("expected : " + path);
318 res = false;
321 if (!url[0].Name.equals(name)) {
322 log.println("parseSmart works wrong");
323 log.println("name field : " + url[0].Name);
324 log.println("expected : " + name);
325 res = false;
328 if (!url[0].Arguments.equals(arguments)) {
329 log.println("parseSmart works wrong");
330 log.println("arguments field : " + url[0].Arguments);
331 log.println("expected : " + arguments);
332 res = false;
335 if (!url[0].Mark.equals(mark)) {
336 log.println("parseSmart works wrong");
337 log.println("mark field : " + url[0].Mark);
338 log.println("expected : " + mark);
339 res = false;
342 String ftpURL = invalidUserPrefix +user + ":" + password + "@" + server + ":" +
343 port + path + "/" + name;
345 url[0] = new URL();
346 url[0].Complete = ftpURL;
347 log.print("parseSmart('" + ftpURL + "', 'ftp://'): ");
348 complete = oObj.parseSmart(url, "ftp://");
349 log.println(complete);
350 res &= complete;
352 if (!url[0].Protocol.equals("ftp://")) {
353 log.println("parseSmart works wrong");
354 log.println("protocol field : " + url[0].Protocol);
355 log.println("expected : ftp://");
356 res = false;
359 if (!url[0].User.equals(invalidUserPrefix+user)) {
360 log.println("parseSmart works wrong");
361 log.println("user field : " + url[0].User);
362 log.println("expected : " + user);
363 res = false;
366 if (!url[0].Password.equals(password)) {
367 log.println("parseSmart works wrong");
368 log.println("password field : " + url[0].Password);
369 log.println("expected : " + password);
370 res = false;
373 if (!url[0].Server.equals(server)) {
374 log.println("parseSmart works wrong");
375 log.println("server field : " + url[0].Server);
376 log.println("expected : " + server);
377 res = false;
380 if (url[0].Port != Short.parseShort(port)) {
381 log.println("parseSmart works wrong");
382 log.println("port field : " + url[0].Port);
383 log.println("expected : " + port);
384 res = false;
387 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
388 log.println("parseSmart works wrong");
389 log.println("path field : " + url[0].Path);
390 log.println("expected : " + path);
391 res = false;
394 if (!url[0].Name.equals(name)) {
395 log.println("parseSmart works wrong");
396 log.println("name field : " + url[0].Name);
397 log.println("expected : " + name);
398 res = false;
401 tRes.tested("parseSmart()", res);
405 * Gets the presentation of a URL. <p>
406 * Has <b> OK </b> status if the method returns the same
407 * URL as was passed in parameter.
409 public void _getPresentation() {
410 URL url = new URL();
412 url.Complete = expectedCompleteHTTP;
414 log.println("getPresentation('" + expectedCompleteHTTP + "', true): ");
415 String presentation = oObj.getPresentation(url, true);
416 boolean res = presentation.equals(expectedCompleteHTTP);
417 log.println("Resulted presentation: " + presentation);
418 log.println("Expected presentation: " + expectedCompleteHTTP);
419 log.println("Result: " + res);
421 url.Complete = expectedCompleteFTP;
422 log.println("getPresentation('" + expectedCompleteFTP + "', false): ");
423 // the password must be masqurade with <****>
424 String asterisk = "";
425 for (int n = 0 ; n < password.length(); n++){
426 asterisk += "*";
428 asterisk = "<" + asterisk.substring(1,asterisk.length());
429 asterisk = asterisk.substring(0,asterisk.length()-1) + ">";
431 presentation = oObj.getPresentation(url, false);
432 String expectedPresentation = "ftp://" + user + ":" + asterisk + "@" +
433 server + ":" + port + path + "/" + name;
434 res &= presentation.equals(expectedPresentation);
435 log.println("Resulted presentation: " + presentation);
436 log.println("Expected presentation: " + expectedPresentation);
437 log.println("Result: " + res);
439 log.println("getPresentation('" + expectedCompleteFTP + "', true): ");
440 presentation = oObj.getPresentation(url, true);
441 expectedPresentation = "ftp://" + user + ":" + password + "@" +
442 server + ":" + port + path + "/" + name;
443 res &= presentation.equals(expectedPresentation);
444 log.println("Resulted presentation: " + presentation);
445 log.println("Expected presentation: " + expectedPresentation);
446 log.println("Result: " + res);
448 String incorrectURL = "*bla-bla*";
449 url.Complete = incorrectURL;
450 log.println("getPresentation('" + incorrectURL + "', false): ");
451 presentation = oObj.getPresentation(url, false);
452 expectedPresentation = "";
453 res &= presentation.equals(expectedPresentation);
454 log.println("Resulted presentation: " + presentation);
455 log.println("Expected presentation: " + expectedPresentation);
456 log.println("Result: " + res);
458 tRes.tested("getPresentation()", res);
461 } // finish class _XURLTransformer