Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / javaunohelper / test / com / sun / star / lib / uno / helper / UnoUrlTest.java
blobd12c5aee4e21d5e462ea6a7c4fb59cd9b371cff2
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 com.sun.star.lib.uno.helper;
20 public class UnoUrlTest {
22 private UnoUrlTest() {
26 private void fail(String msg) {
27 System.err.println(msg);
28 System.exit(1);
31 private static void log(String msg) {
32 System.out.println(msg);
35 private void assertTrue(boolean b) {
36 if (!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() {
53 try {
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() {
63 try {
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() {
71 try {
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() {
79 try {
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() {
89 try {
90 UnoUrl.parseUnoUrl("uno:");
91 fail("Should throw an exception");
92 } catch (com.sun.star.lang.IllegalArgumentException e) {
96 public void testParam2() {
97 try {
98 UnoUrl.parseUnoUrl("uno:a;");
99 fail("Should throw an exception");
100 } catch (com.sun.star.lang.IllegalArgumentException e) {
104 public void testPartName1() {
105 try {
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() {
113 try {
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() {
121 try {
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() {
133 try {
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() {
145 try {
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() {
153 try {
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() {
161 try {
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() {
171 try {
172 UnoUrl url =
173 UnoUrl.parseUnoUrl(
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() {
186 try {
187 UnoUrl url =
188 UnoUrl.parseUnoUrl(
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"));
191 assertEquals(
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() {
201 try {
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");
213 t.testStart1();
214 log("Running test case 2");
215 t.testStart2();
216 log("Running test case 3");
217 t.testStart3();
218 log("Running test case 4");
219 t.testStart4();
221 log("Running test case 5");
222 t.testParam1();
223 log("Running test case 6");
224 t.testParam2();
226 log("Running test case 7");
227 t.testPartName1();
229 log("Running test case 8");
230 t.testOID1();
232 log("Running test case 9");
233 t.testOIDandParams1();
234 log("Running test case 10");
235 t.testOIDandParams2();
237 log("Running test case 11");
238 t.testParams1();
239 log("Running test case 12");
240 t.testParams2();
241 log("Running test case 13");
242 t.testParams3();
244 log("Running test case 14");
245 t.testCommon();
247 log("Running test case 15");
248 t.testUTF();
249 log("Running test case 16");
250 t.testUTF1();