/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ package com.sun.star.lib.uno.helper; public class UnoUrlTest { private UnoUrlTest() { } private void fail(String msg) { System.err.println(msg); System.exit(1); } private static void log(String msg) { System.out.println(msg); } private void assertTrue(boolean b) { if (!b) fail("boolean assertion failed"); } private void assertEquals(String expected, String actual) { if (!expected.equals(actual)) { fail("Expected: '"+ expected + "' but was: '"+actual+"'"); } } private void assertEquals(int expected, int actual) { if (expected != actual) { fail("Expected: "+ expected + " but was: "+actual); } } public void testStart1() { try { UnoUrl url = UnoUrl.parseUnoUrl("uno:x;y;z"); assertTrue((url != null)); assertEquals("x", url.getConnection()); } catch (com.sun.star.lang.IllegalArgumentException e) { fail("Caught exception:" + e.getMessage()); } } public void testStart2() { try { UnoUrl url = UnoUrl.parseUnoUrl("uno1:x;y;z"); fail("Should throw an exception"); } catch (com.sun.star.lang.IllegalArgumentException e) { } } public void testStart3() { try { UnoUrl url = UnoUrl.parseUnoUrl("un:x;y;z"); fail("Should throw an exception"); } catch (com.sun.star.lang.IllegalArgumentException e) { } } public void testStart4() { try { UnoUrl url = UnoUrl.parseUnoUrl("x;y;z"); assertTrue((url != null)); assertEquals("y", url.getProtocol()); } catch (com.sun.star.lang.IllegalArgumentException e) { fail("Caught exception:" + e.getMessage()); } } public void testParam1() { try { UnoUrl url = UnoUrl.parseUnoUrl("uno:"); fail("Should throw an exception"); } catch (com.sun.star.lang.IllegalArgumentException e) { } } public void testParam2() { try { UnoUrl url = UnoUrl.parseUnoUrl("uno:a;"); fail("Should throw an exception"); } catch (com.sun.star.lang.IllegalArgumentException e) { } } public void testPartName1() { try { UnoUrl url = UnoUrl.parseUnoUrl("uno:abc!abc;b;c"); fail("Should throw an exception"); } catch (com.sun.star.lang.IllegalArgumentException e) { } } public void testOID1() { try { UnoUrl url = UnoUrl.parseUnoUrl("uno:x;y;ABC