1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoUrlTest.java,v $
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 com
.sun
.star
.lib
.uno
.helper
;
32 public class UnoUrlTest
{
34 private UnoUrlTest() {
38 private void fail(String msg
) {
39 System
.err
.println(msg
);
43 private static void log(String msg
) {
44 System
.out
.println(msg
);
47 private void assertTrue(boolean b
) {
49 fail("boolean assertion failed");
52 private void assertEquals(String expected
, String actual
) {
53 if (!expected
.equals(actual
)) {
54 fail("Expected: '"+ expected
+ "' but was: '"+actual
+"'");
58 private void assertEquals(int expected
, int actual
) {
59 if (expected
!= actual
) {
60 fail("Expected: "+ expected
+ " but was: "+actual
);
64 public void testStart1() {
66 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x;y;z");
67 assertTrue((url
!= null));
68 assertEquals("x", url
.getConnection());
69 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
70 fail("Caught exception:" + e
.getMessage());
74 public void testStart2() {
76 UnoUrl url
= UnoUrl
.parseUnoUrl("uno1:x;y;z");
77 fail("Should throw an exception");
78 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
82 public void testStart3() {
84 UnoUrl url
= UnoUrl
.parseUnoUrl("un:x;y;z");
85 fail("Should throw an exception");
86 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
90 public void testStart4() {
92 UnoUrl url
= UnoUrl
.parseUnoUrl("x;y;z");
93 assertTrue((url
!= null));
94 assertEquals("y", url
.getProtocol());
95 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
96 fail("Caught exception:" + e
.getMessage());
100 public void testParam1() {
102 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:");
103 fail("Should throw an exception");
104 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
108 public void testParam2() {
110 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:a;");
111 fail("Should throw an exception");
112 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
116 public void testPartName1() {
118 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:abc!abc;b;c");
119 fail("Should throw an exception");
120 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
124 public void testOID1() {
126 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x;y;ABC<ABC");
127 fail("Should throw an exception");
128 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
132 public void testOIDandParams1() {
134 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,key9=val9;y;ABC");
135 assertTrue((url
!= null));
136 assertEquals("ABC", url
.getRootOid());
137 assertEquals(1, url
.getConnectionParameters().size());
138 assertEquals("val9", (String
)url
.getConnectionParameters().get("key9"));
139 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
140 fail(e
.getMessage());
144 public void testOIDandParams2() {
146 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,key1=val1,k2=v2;y,k3=v3;ABC()!/");
147 assertTrue((url
!= null));
148 assertEquals("ABC()!/", url
.getRootOid());
149 assertEquals(2, url
.getConnectionParameters().size());
150 assertEquals(1, url
.getProtocolParameters().size());
151 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
152 fail("Caught exception:" + e
.getMessage());
156 public void testParams1() {
158 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,abc!abc=val;y;ABC");
159 fail("Should throw an exception");
160 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
164 public void testParams2() {
166 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,abc=val<val;y;ABC");
167 fail("Should throw an exception");
168 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
172 public void testParams3() {
174 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,abc=val!()val;y;ABC");
175 assertTrue((url
!= null));
176 assertEquals(1, url
.getConnectionParameters().size());
177 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
178 fail("Caught exception:" + e
.getMessage());
182 public void testCommon() {
186 "socket,host=localhost,port=2002;urp;StarOffice.ServiceManager");
187 assertTrue((url
!= null));
188 assertEquals("StarOffice.ServiceManager", url
.getRootOid());
189 assertEquals("socket", url
.getConnection());
190 assertEquals("urp", url
.getProtocol());
191 assertEquals("2002", (String
)url
.getConnectionParameters().get("port"));
192 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
193 fail("Caught exception:" + e
.getMessage());
197 public void testUTF() {
201 "socket,host=localhost,horst=abc%c3%9c%c3%a4ABC%41%2c%2C,port=2002;urp;StarOffice.ServiceManager");
202 assertEquals("abcÜäABCA,,", (String
)url
.getConnectionParameters().get("horst"));
204 "host=localhost,horst=abc%c3%9c%c3%a4ABC%41%2c%2C,port=2002",
205 url
.getConnectionParametersAsString());
206 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
207 fail("Caught exception:" + e
.getMessage());
212 public void testUTF1() {
214 UnoUrl url
= UnoUrl
.parseUnoUrl("uno:x,abc=val%4t;y;ABC");
215 fail("Should throw an exception");
216 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
221 public static void main(String args
[]) {
222 UnoUrlTest t
= new UnoUrlTest();
224 log("Running test case 1");
226 log("Running test case 2");
228 log("Running test case 3");
230 log("Running test case 4");
233 log("Running test case 5");
235 log("Running test case 6");
238 log("Running test case 7");
241 log("Running test case 8");
244 log("Running test case 9");
245 t
.testOIDandParams1();
246 log("Running test case 10");
247 t
.testOIDandParams2();
249 log("Running test case 11");
251 log("Running test case 12");
253 log("Running test case 13");
256 log("Running test case 14");
259 log("Running test case 15");
261 log("Running test case 16");