1*a5b190bfSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a5b190bfSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a5b190bfSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a5b190bfSAndrew Rist * distributed with this work for additional information 6*a5b190bfSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a5b190bfSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a5b190bfSAndrew Rist * "License"); you may not use this file except in compliance 9*a5b190bfSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*a5b190bfSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*a5b190bfSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a5b190bfSAndrew Rist * software distributed under the License is distributed on an 15*a5b190bfSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a5b190bfSAndrew Rist * KIND, either express or implied. See the License for the 17*a5b190bfSAndrew Rist * specific language governing permissions and limitations 18*a5b190bfSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*a5b190bfSAndrew Rist *************************************************************/ 21*a5b190bfSAndrew Rist 22*a5b190bfSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.lib.uno.helper; 25cdf0e10cSrcweir public class UnoUrlTest { 26cdf0e10cSrcweir UnoUrlTest()27cdf0e10cSrcweir private UnoUrlTest() { 28cdf0e10cSrcweir } 29cdf0e10cSrcweir 30cdf0e10cSrcweir fail(String msg)31cdf0e10cSrcweir private void fail(String msg) { 32cdf0e10cSrcweir System.err.println(msg); 33cdf0e10cSrcweir System.exit(1); 34cdf0e10cSrcweir } 35cdf0e10cSrcweir log(String msg)36cdf0e10cSrcweir private static void log(String msg) { 37cdf0e10cSrcweir System.out.println(msg); 38cdf0e10cSrcweir } 39cdf0e10cSrcweir assertTrue(boolean b)40cdf0e10cSrcweir private void assertTrue(boolean b) { 41cdf0e10cSrcweir if (!b) 42cdf0e10cSrcweir fail("boolean assertion failed"); 43cdf0e10cSrcweir } 44cdf0e10cSrcweir assertEquals(String expected, String actual)45cdf0e10cSrcweir private void assertEquals(String expected, String actual) { 46cdf0e10cSrcweir if (!expected.equals(actual)) { 47cdf0e10cSrcweir fail("Expected: '"+ expected + "' but was: '"+actual+"'"); 48cdf0e10cSrcweir } 49cdf0e10cSrcweir } 50cdf0e10cSrcweir assertEquals(int expected, int actual)51cdf0e10cSrcweir private void assertEquals(int expected, int actual) { 52cdf0e10cSrcweir if (expected != actual) { 53cdf0e10cSrcweir fail("Expected: "+ expected + " but was: "+actual); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir } 56cdf0e10cSrcweir testStart1()57cdf0e10cSrcweir public void testStart1() { 58cdf0e10cSrcweir try { 59cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:x;y;z"); 60cdf0e10cSrcweir assertTrue((url != null)); 61cdf0e10cSrcweir assertEquals("x", url.getConnection()); 62cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 63cdf0e10cSrcweir fail("Caught exception:" + e.getMessage()); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir testStart2()67cdf0e10cSrcweir public void testStart2() { 68cdf0e10cSrcweir try { 69cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno1:x;y;z"); 70cdf0e10cSrcweir fail("Should throw an exception"); 71cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 72cdf0e10cSrcweir } 73cdf0e10cSrcweir } 74cdf0e10cSrcweir testStart3()75cdf0e10cSrcweir public void testStart3() { 76cdf0e10cSrcweir try { 77cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("un:x;y;z"); 78cdf0e10cSrcweir fail("Should throw an exception"); 79cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 80cdf0e10cSrcweir } 81cdf0e10cSrcweir } 82cdf0e10cSrcweir testStart4()83cdf0e10cSrcweir public void testStart4() { 84cdf0e10cSrcweir try { 85cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("x;y;z"); 86cdf0e10cSrcweir assertTrue((url != null)); 87cdf0e10cSrcweir assertEquals("y", url.getProtocol()); 88cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 89cdf0e10cSrcweir fail("Caught exception:" + e.getMessage()); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir } 92cdf0e10cSrcweir testParam1()93cdf0e10cSrcweir public void testParam1() { 94cdf0e10cSrcweir try { 95cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:"); 96cdf0e10cSrcweir fail("Should throw an exception"); 97cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 98cdf0e10cSrcweir } 99cdf0e10cSrcweir } 100cdf0e10cSrcweir testParam2()101cdf0e10cSrcweir public void testParam2() { 102cdf0e10cSrcweir try { 103cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:a;"); 104cdf0e10cSrcweir fail("Should throw an exception"); 105cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 106cdf0e10cSrcweir } 107cdf0e10cSrcweir } 108cdf0e10cSrcweir testPartName1()109cdf0e10cSrcweir public void testPartName1() { 110cdf0e10cSrcweir try { 111cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:abc!abc;b;c"); 112cdf0e10cSrcweir fail("Should throw an exception"); 113cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir testOID1()117cdf0e10cSrcweir public void testOID1() { 118cdf0e10cSrcweir try { 119cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:x;y;ABC<ABC"); 120cdf0e10cSrcweir fail("Should throw an exception"); 121cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir testOIDandParams1()125cdf0e10cSrcweir public void testOIDandParams1() { 126cdf0e10cSrcweir try { 127cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:x,key9=val9;y;ABC"); 128cdf0e10cSrcweir assertTrue((url != null)); 129cdf0e10cSrcweir assertEquals("ABC", url.getRootOid()); 130cdf0e10cSrcweir assertEquals(1, url.getConnectionParameters().size()); 131cdf0e10cSrcweir assertEquals("val9", (String)url.getConnectionParameters().get("key9")); 132cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 133cdf0e10cSrcweir fail(e.getMessage()); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir testOIDandParams2()137cdf0e10cSrcweir public void testOIDandParams2() { 138cdf0e10cSrcweir try { 139cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:x,key1=val1,k2=v2;y,k3=v3;ABC()!/"); 140cdf0e10cSrcweir assertTrue((url != null)); 141cdf0e10cSrcweir assertEquals("ABC()!/", url.getRootOid()); 142cdf0e10cSrcweir assertEquals(2, url.getConnectionParameters().size()); 143cdf0e10cSrcweir assertEquals(1, url.getProtocolParameters().size()); 144cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 145cdf0e10cSrcweir fail("Caught exception:" + e.getMessage()); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir } 148cdf0e10cSrcweir testParams1()149cdf0e10cSrcweir public void testParams1() { 150cdf0e10cSrcweir try { 151cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:x,abc!abc=val;y;ABC"); 152cdf0e10cSrcweir fail("Should throw an exception"); 153cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 154cdf0e10cSrcweir } 155cdf0e10cSrcweir } 156cdf0e10cSrcweir testParams2()157cdf0e10cSrcweir public void testParams2() { 158cdf0e10cSrcweir try { 159cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:x,abc=val<val;y;ABC"); 160cdf0e10cSrcweir fail("Should throw an exception"); 161cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir testParams3()165cdf0e10cSrcweir public void testParams3() { 166cdf0e10cSrcweir try { 167cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:x,abc=val!()val;y;ABC"); 168cdf0e10cSrcweir assertTrue((url != null)); 169cdf0e10cSrcweir assertEquals(1, url.getConnectionParameters().size()); 170cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 171cdf0e10cSrcweir fail("Caught exception:" + e.getMessage()); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } 174cdf0e10cSrcweir testCommon()175cdf0e10cSrcweir public void testCommon() { 176cdf0e10cSrcweir try { 177cdf0e10cSrcweir UnoUrl url = 178cdf0e10cSrcweir UnoUrl.parseUnoUrl( 179cdf0e10cSrcweir "socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"); 180cdf0e10cSrcweir assertTrue((url != null)); 181cdf0e10cSrcweir assertEquals("StarOffice.ServiceManager", url.getRootOid()); 182cdf0e10cSrcweir assertEquals("socket", url.getConnection()); 183cdf0e10cSrcweir assertEquals("urp", url.getProtocol()); 184cdf0e10cSrcweir assertEquals("2002", (String)url.getConnectionParameters().get("port")); 185cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 186cdf0e10cSrcweir fail("Caught exception:" + e.getMessage()); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir } 189cdf0e10cSrcweir testUTF()190cdf0e10cSrcweir public void testUTF() { 191cdf0e10cSrcweir try { 192cdf0e10cSrcweir UnoUrl url = 193cdf0e10cSrcweir UnoUrl.parseUnoUrl( 194cdf0e10cSrcweir "socket,host=localhost,horst=abc%c3%9c%c3%a4ABC%41%2c%2C,port=2002;urp;StarOffice.ServiceManager"); 195cdf0e10cSrcweir assertEquals("abc��ABCA,,", (String)url.getConnectionParameters().get("horst")); 196cdf0e10cSrcweir assertEquals( 197cdf0e10cSrcweir "host=localhost,horst=abc%c3%9c%c3%a4ABC%41%2c%2C,port=2002", 198cdf0e10cSrcweir url.getConnectionParametersAsString()); 199cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 200cdf0e10cSrcweir fail("Caught exception:" + e.getMessage()); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir } 204cdf0e10cSrcweir testUTF1()205cdf0e10cSrcweir public void testUTF1() { 206cdf0e10cSrcweir try { 207cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl("uno:x,abc=val%4t;y;ABC"); 208cdf0e10cSrcweir fail("Should throw an exception"); 209cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 210cdf0e10cSrcweir } 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir main(String args[])214cdf0e10cSrcweir public static void main(String args[]) { 215cdf0e10cSrcweir UnoUrlTest t = new UnoUrlTest(); 216cdf0e10cSrcweir 217cdf0e10cSrcweir log("Running test case 1"); 218cdf0e10cSrcweir t.testStart1(); 219cdf0e10cSrcweir log("Running test case 2"); 220cdf0e10cSrcweir t.testStart2(); 221cdf0e10cSrcweir log("Running test case 3"); 222cdf0e10cSrcweir t.testStart3(); 223cdf0e10cSrcweir log("Running test case 4"); 224cdf0e10cSrcweir t.testStart4(); 225cdf0e10cSrcweir 226cdf0e10cSrcweir log("Running test case 5"); 227cdf0e10cSrcweir t.testParam1(); 228cdf0e10cSrcweir log("Running test case 6"); 229cdf0e10cSrcweir t.testParam2(); 230cdf0e10cSrcweir 231cdf0e10cSrcweir log("Running test case 7"); 232cdf0e10cSrcweir t.testPartName1(); 233cdf0e10cSrcweir 234cdf0e10cSrcweir log("Running test case 8"); 235cdf0e10cSrcweir t.testOID1(); 236cdf0e10cSrcweir 237cdf0e10cSrcweir log("Running test case 9"); 238cdf0e10cSrcweir t.testOIDandParams1(); 239cdf0e10cSrcweir log("Running test case 10"); 240cdf0e10cSrcweir t.testOIDandParams2(); 241cdf0e10cSrcweir 242cdf0e10cSrcweir log("Running test case 11"); 243cdf0e10cSrcweir t.testParams1(); 244cdf0e10cSrcweir log("Running test case 12"); 245cdf0e10cSrcweir t.testParams2(); 246cdf0e10cSrcweir log("Running test case 13"); 247cdf0e10cSrcweir t.testParams3(); 248cdf0e10cSrcweir 249cdf0e10cSrcweir log("Running test case 14"); 250cdf0e10cSrcweir t.testCommon(); 251cdf0e10cSrcweir 252cdf0e10cSrcweir log("Running test case 15"); 253cdf0e10cSrcweir t.testUTF(); 254cdf0e10cSrcweir log("Running test case 16"); 255cdf0e10cSrcweir t.testUTF1(); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir } 258