tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XURLTransformer.java
blob9ce968cdf1ba2290650a335aac276d06d83ea7d4
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 static final String user = "user";
42 static final String invalidUserPrefix = "1";
43 static final String password = "password";
44 static final String server = "server";
45 static final String invalidServerPrefix = "1";
46 static final String port = "8080";
47 static final String path = "/pub/path";
48 static final String name = "file.txt";
49 static final String arguments = "a=b";
50 static final String mark = "mark";
52 static final String expectedCompleteHTTP = "http://"
53 + server + ":" + port + path
54 + "/" + name + "?" + arguments + "#" + mark;
55 static final String expectedCompleteFTP = "ftp://"
56 + user + ":" + password + "@" + server + ":" + port + path
57 + "/" + name;
59 /**
60 * First the complete URL (all URL fields are filled) is
61 * passed and assembled. Then incomplete URL (only
62 * <code>Server</code> field is set) is passed. <p>
63 * Has <b> OK </b> status if in the first case <code>true</code>
64 * returned and <code>Complete</code> field is set and in the
65 * second case <code>false</code> is returned. <p>
67 public void _assemble(){
68 URL[] url = new URL[1];
69 url[0] = new URL();
71 url[0].Protocol = "http://";
72 url[0].Server = server;
73 url[0].Port = Short.parseShort(port);
74 url[0].Path = path;
75 url[0].Name = name;
76 url[0].Arguments = arguments;
77 url[0].Mark = mark;
78 url[0].Main = "http://" + server + ":" +
79 port + path + "/" + name;
81 boolean res = true;
83 log.print("assemble http-URL: ");
84 boolean complete = oObj.assemble(url);
85 log.println(complete);
86 res &= complete;
88 if (!expectedCompleteHTTP.equals(url[0].Complete)) {
89 log.println("assemble works wrong");
90 log.println("complete field : " + url[0].Complete);
91 log.println("expected : " + expectedCompleteHTTP);
92 res = false;
95 url[0] = new URL();
96 url[0].Protocol = "ftp://";
97 url[0].User = user;
98 url[0].Password = password;
99 url[0].Server = server;
100 url[0].Port = Short.parseShort(port);
101 url[0].Path = path;
102 url[0].Name = name;
103 url[0].Main = "ftp://" + user + ":" + password + "@" + server + ":" +
104 port + path + "/" + name;
106 log.print("assemble ftp-URL: ");
107 complete = oObj.assemble(url);
108 log.println(complete);
109 res &= complete;
111 if (!expectedCompleteFTP.equals(url[0].Complete)) {
112 log.println("assemble works wrong");
113 log.println("complete field : " + url[0].Complete);
114 log.println("expected : " + expectedCompleteFTP);
115 res = false;
118 URL[] incompleteUrl = new URL[1];
119 incompleteUrl[0] = new URL();
120 incompleteUrl[0].Server = server;
122 log.print("assemble incomplete URL: ");
123 complete = oObj.assemble(incompleteUrl);
124 log.println(complete);
125 res &= !complete;
127 // should be incomplete
128 tRes.tested("assemble()", res);
132 * First the complete URL (<code>Complete</code> field is set
133 * to proper URL) is passed and parsed. Then incomplete URL (only
134 * <code>Server</code> field is set) is passed. <p>
135 * Has <b> OK </b> status if in the first case <code>true</code>
136 * returned and all URL fields are set to proper values and in the
137 * second case <code>false</code> is returned. <p>
139 public void _parseStrict() {
140 URL[] url = new URL[1];
142 url[0] = new URL();
143 url[0].Complete = expectedCompleteHTTP;
145 boolean res = true;
146 log.print("parseStrict(" + expectedCompleteHTTP + "): ");
147 boolean complete = oObj.parseStrict(url);
148 log.println(complete);
149 res &= complete;
151 if (!url[0].Protocol.equals("http://")) {
152 log.println("parseStrict works wrong");
153 log.println("protocol field : " + url[0].Protocol);
154 log.println("expected : http://");
155 res = false;
158 if (!url[0].Server.equals(server)) {
159 log.println("parseStrict works wrong");
160 log.println("server field : " + url[0].Server);
161 log.println("expected : " + server);
162 res = false;
165 if (url[0].Port != Short.parseShort(port)) {
166 log.println("parseStrict works wrong");
167 log.println("port field : " + url[0].Port);
168 log.println("expected : " + port);
169 res = false;
172 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
173 log.println("parseStrict works wrong");
174 log.println("path field : " + url[0].Path);
175 log.println("expected : " + path);
176 res = false;
179 if (!url[0].Name.equals(name)) {
180 log.println("parseStrict works wrong");
181 log.println("name field : " + url[0].Name);
182 log.println("expected : " + name);
183 res = false;
186 if (!url[0].Arguments.equals(arguments)) {
187 log.println("parseStrict works wrong");
188 log.println("arguments field : " + url[0].Arguments);
189 log.println("expected : " + arguments);
190 res = false;
193 if (!url[0].Mark.equals(mark)) {
194 log.println("parseStrict works wrong");
195 log.println("mark field : " + url[0].Mark);
196 log.println("expected : " + mark);
197 res = false;
200 url[0] = new URL();
201 url[0].Complete = expectedCompleteFTP;
203 log.print("parseStrict(" + expectedCompleteFTP + "): ");
204 complete = oObj.parseStrict(url);
205 log.println(complete);
206 res &= complete;
208 if (!url[0].Protocol.equals("ftp://")) {
209 log.println("parseStrict works wrong");
210 log.println("protocol field : " + url[0].Protocol);
211 log.println("expected : ftp://");
212 res = false;
215 if (!url[0].User.equals(user)) {
216 log.println("parseStrict works wrong");
217 log.println("user field : " + url[0].User);
218 log.println("expected : " + user);
219 res = false;
222 if (!url[0].Password.equals(password)) {
223 log.println("parseStrict works wrong");
224 log.println("password field : " + url[0].Password);
225 log.println("expected : " + password);
226 res = false;
229 if (!url[0].Server.equals(server)) {
230 log.println("parseStrict works wrong");
231 log.println("server field : " + url[0].Server);
232 log.println("expected : " + server);
233 res = false;
236 if (url[0].Port != Short.parseShort(port)) {
237 log.println("parseStrict works wrong");
238 log.println("port field : " + url[0].Port);
239 log.println("expected : " + port);
240 res = false;
243 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
244 log.println("parseStrict works wrong");
245 log.println("path field : " + url[0].Path);
246 log.println("expected : " + path);
247 res = false;
250 if (!url[0].Name.equals(name)) {
251 log.println("parseStrict works wrong");
252 log.println("name field : " + url[0].Name);
253 log.println("expected : " + name);
254 res = false;
257 URL[] incompleteUrl = new URL[1];
258 incompleteUrl[0] = new URL();
259 incompleteUrl[0].Complete = server;
261 log.print("parseStrict(" + server + "): ");
262 complete = oObj.parseStrict(incompleteUrl);
263 log.println(complete);
264 // should be incomplete
265 res &= !complete;
267 tRes.tested("parseStrict()", res);
271 * Tries to parse WWW server name. <p>
272 * Has <b> OK </b> status if the method return <code>true</code>
273 * value and <code>Protocol, Server, Port</code> URL fields are
274 * set properly.
276 public void _parseSmart() {
277 URL[] url = new URL[1];
279 String httpURL = invalidServerPrefix + server + ":" + port + path + "/" + name + "?" +
280 arguments + "#" + mark;
282 url[0] = new URL();
283 url[0].Complete = httpURL;
285 boolean res = true;
286 log.print("parseSmart('" + httpURL + "', 'http://'): ");
287 boolean complete = oObj.parseSmart(url, "http://");
288 log.println(complete);
289 res &= complete;
291 if (!url[0].Protocol.equals("http://")) {
292 log.println("parseSmart works wrong");
293 log.println("protocol field : " + url[0].Protocol);
294 log.println("expected : http://");
295 res = false;
298 if (!url[0].Server.equals(invalidServerPrefix+server)) {
299 log.println("parseSmart works wrong");
300 log.println("server field : " + url[0].Server);
301 log.println("expected : " + server);
302 res = false;
305 if (url[0].Port != Short.parseShort(port)) {
306 log.println("parseSmart works wrong");
307 log.println("port field : " + url[0].Port);
308 log.println("expected : " + port);
309 res = false;
312 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
313 log.println("parseSmart works wrong");
314 log.println("path field : " + url[0].Path);
315 log.println("expected : " + path);
316 res = false;
319 if (!url[0].Name.equals(name)) {
320 log.println("parseSmart works wrong");
321 log.println("name field : " + url[0].Name);
322 log.println("expected : " + name);
323 res = false;
326 if (!url[0].Arguments.equals(arguments)) {
327 log.println("parseSmart works wrong");
328 log.println("arguments field : " + url[0].Arguments);
329 log.println("expected : " + arguments);
330 res = false;
333 if (!url[0].Mark.equals(mark)) {
334 log.println("parseSmart works wrong");
335 log.println("mark field : " + url[0].Mark);
336 log.println("expected : " + mark);
337 res = false;
340 String ftpURL = invalidUserPrefix +user + ":" + password + "@" + server + ":" +
341 port + path + "/" + name;
343 url[0] = new URL();
344 url[0].Complete = ftpURL;
345 log.print("parseSmart('" + ftpURL + "', 'ftp://'): ");
346 complete = oObj.parseSmart(url, "ftp://");
347 log.println(complete);
348 res &= complete;
350 if (!url[0].Protocol.equals("ftp://")) {
351 log.println("parseSmart works wrong");
352 log.println("protocol field : " + url[0].Protocol);
353 log.println("expected : ftp://");
354 res = false;
357 if (!url[0].User.equals(invalidUserPrefix+user)) {
358 log.println("parseSmart works wrong");
359 log.println("user field : " + url[0].User);
360 log.println("expected : " + user);
361 res = false;
364 if (!url[0].Password.equals(password)) {
365 log.println("parseSmart works wrong");
366 log.println("password field : " + url[0].Password);
367 log.println("expected : " + password);
368 res = false;
371 if (!url[0].Server.equals(server)) {
372 log.println("parseSmart works wrong");
373 log.println("server field : " + url[0].Server);
374 log.println("expected : " + server);
375 res = false;
378 if (url[0].Port != Short.parseShort(port)) {
379 log.println("parseSmart works wrong");
380 log.println("port field : " + url[0].Port);
381 log.println("expected : " + port);
382 res = false;
385 if ((!url[0].Path.equals(path)) && (!url[0].Path.equals(path + "/"))) {
386 log.println("parseSmart works wrong");
387 log.println("path field : " + url[0].Path);
388 log.println("expected : " + path);
389 res = false;
392 if (!url[0].Name.equals(name)) {
393 log.println("parseSmart works wrong");
394 log.println("name field : " + url[0].Name);
395 log.println("expected : " + name);
396 res = false;
399 tRes.tested("parseSmart()", res);
403 * Gets the presentation of a URL. <p>
404 * Has <b> OK </b> status if the method returns the same
405 * URL as was passed in parameter.
407 public void _getPresentation() {
408 URL url = new URL();
410 url.Complete = expectedCompleteHTTP;
412 log.println("getPresentation('" + expectedCompleteHTTP + "', true): ");
413 String presentation = oObj.getPresentation(url, true);
414 boolean res = presentation.equals(expectedCompleteHTTP);
415 log.println("Resulted presentation: " + presentation);
416 log.println("Expected presentation: " + expectedCompleteHTTP);
417 log.println("Result: " + res);
419 url.Complete = expectedCompleteFTP;
420 log.println("getPresentation('" + expectedCompleteFTP + "', false): ");
421 // the password must be masquerade with <****>
422 StringBuilder sb = new StringBuilder();
423 for (int n = 0 ; n < password.length(); n++){
424 sb.append("*");
426 String asterisk = sb.toString();
427 asterisk = "<" + asterisk.substring(1,asterisk.length());
428 asterisk = asterisk.substring(0,asterisk.length()-1) + ">";
430 presentation = oObj.getPresentation(url, false);
431 String expectedPresentation = "ftp://" + user + ":" + asterisk + "@" +
432 server + ":" + port + path + "/" + name;
433 res &= presentation.equals(expectedPresentation);
434 log.println("Resulted presentation: " + presentation);
435 log.println("Expected presentation: " + expectedPresentation);
436 log.println("Result: " + res);
438 log.println("getPresentation('" + expectedCompleteFTP + "', true): ");
439 presentation = oObj.getPresentation(url, true);
440 expectedPresentation = "ftp://" + user + ":" + password + "@" +
441 server + ":" + port + path + "/" + name;
442 res &= presentation.equals(expectedPresentation);
443 log.println("Resulted presentation: " + presentation);
444 log.println("Expected presentation: " + expectedPresentation);
445 log.println("Result: " + res);
447 String incorrectURL = "*bla-bla*";
448 url.Complete = incorrectURL;
449 log.println("getPresentation('" + incorrectURL + "', false): ");
450 presentation = oObj.getPresentation(url, false);
451 expectedPresentation = "";
452 res &= presentation.equals(expectedPresentation);
453 log.println("Resulted presentation: " + presentation);
454 log.println("Expected presentation: " + expectedPresentation);
455 log.println("Result: " + res);
457 tRes.tested("getPresentation()", res);
460 } // finish class _XURLTransformer