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 com
.sun
.star
.lib
.uno
.helper
;
20 public class UnoUrlTest
{
22 private UnoUrlTest() {
26 private void fail(String msg
) {
27 System
.err
.println(msg
);
31 private static void log(String msg
) {
32 System
.out
.println(msg
);
35 private void assertTrue(boolean b
) {
37 fail("boolean assertion failed");
40 private void assertEquals(String expected
, String actual
) {
41 if (!expected
.equals(actual
)) {
42 fail("Expected: '"+ expected
+ "' but was: '"+actual
+"'");
46 private void assertEquals(int expected
, int actual
) {
47 if (expected
!= actual
) {
48 fail("Expected: "+ expected
+ " but was: "+actual
);
52 public void testStart1() {
54 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x;y;z");
55 assertTrue((url
!= null));
56 assertEquals("x", url
.getConnection());
57 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
58 fail("Caught exception:" + e
.getMessage());
62 public void testStart2() {
64 UnoUrl
.parseUnoUrl("uno1:x;y;z");
65 fail("Should throw an exception");
66 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
70 public void testStart3() {
72 UnoUrl
.parseUnoUrl("un:x;y;z");
73 fail("Should throw an exception");
74 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
78 public void testStart4() {
80 UnoUrl url
= UnoUrl
.parseUnoUrl("x;y;z");
81 assertTrue((url
!= null));
82 assertEquals("y", url
.getProtocol());
83 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
84 fail("Caught exception:" + e
.getMessage());
88 public void testParam1() {
90 UnoUrl
.parseUnoUrl("uno:");
91 fail("Should throw an exception");
92 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
96 public void testParam2() {
98 UnoUrl
.parseUnoUrl("uno:a;");
99 fail("Should throw an exception");
100 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
104 public void testPartName1() {
106 UnoUrl
.parseUnoUrl("uno:abc!abc;b;c");
107 fail("Should throw an exception");
108 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
112 public void testOID1() {
114 UnoUrl
.parseUnoUrl("uno:x;y;ABC<ABC");
115 fail("Should throw an exception");
116 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
120 public void testOIDandParams1() {
122 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,key9=val9;y;ABC");
123 assertTrue((url
!= null));
124 assertEquals("ABC", url
.getRootOid());
125 assertEquals(1, url
.getConnectionParameters().size());
126 assertEquals("val9", url
.getConnectionParameters().get("key9"));
127 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
128 fail(e
.getMessage());
132 public void testOIDandParams2() {
134 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,key1=val1,k2=v2;y,k3=v3;ABC()!/");
135 assertTrue((url
!= null));
136 assertEquals("ABC()!/", url
.getRootOid());
137 assertEquals(2, url
.getConnectionParameters().size());
138 assertEquals(1, url
.getProtocolParameters().size());
139 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
140 fail("Caught exception:" + e
.getMessage());
144 public void testParams1() {
146 UnoUrl
.parseUnoUrl("uno:x,abc!abc=val;y;ABC");
147 fail("Should throw an exception");
148 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
152 public void testParams2() {
154 UnoUrl
.parseUnoUrl("uno:x,abc=val<val;y;ABC");
155 fail("Should throw an exception");
156 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
160 public void testParams3() {
162 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,abc=val!()val;y;ABC");
163 assertTrue((url
!= null));
164 assertEquals(1, url
.getConnectionParameters().size());
165 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
166 fail("Caught exception:" + e
.getMessage());
170 public void testCommon() {
174 "socket,host=localhost,port=2002;urp;StarOffice.ServiceManager");
175 assertTrue((url
!= null));
176 assertEquals("StarOffice.ServiceManager", url
.getRootOid());
177 assertEquals("socket", url
.getConnection());
178 assertEquals("urp", url
.getProtocol());
179 assertEquals("2002", url
.getConnectionParameters().get("port"));
180 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
181 fail("Caught exception:" + e
.getMessage());
185 public void testUTF() {
189 "socket,host=localhost,horst=abc%c3%9c%c3%a4ABC%41%2c%2C,port=2002;urp;StarOffice.ServiceManager");
190 assertEquals("abcÜäABCA,,", url
.getConnectionParameters().get("horst"));
192 "host=localhost,horst=abc%c3%9c%c3%a4ABC%41%2c%2C,port=2002",
193 url
.getConnectionParametersAsString());
194 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
195 fail("Caught exception:" + e
.getMessage());
200 public void testUTF1() {
202 UnoUrl
.parseUnoUrl("uno:x,abc=val%4t;y;ABC");
203 fail("Should throw an exception");
204 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
209 public static void main(String args
[]) {
210 UnoUrlTest t
= new UnoUrlTest();
212 log("Running test case 1");
214 log("Running test case 2");
216 log("Running test case 3");
218 log("Running test case 4");
221 log("Running test case 5");
223 log("Running test case 6");
226 log("Running test case 7");
229 log("Running test case 8");
232 log("Running test case 9");
233 t
.testOIDandParams1();
234 log("Running test case 10");
235 t
.testOIDandParams2();
237 log("Running test case 11");
239 log("Running test case 12");
241 log("Running test case 13");
244 log("Running test case 14");
247 log("Running test case 15");
249 log("Running test case 16");