1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.util; 29 30 import com.sun.star.util.XStringSubstitution; 31 import lib.MultiMethodTest; 32 33 public class _XStringSubstitution extends MultiMethodTest { 34 35 public XStringSubstitution oObj; 36 37 public void _getSubstituteVariableValue() { 38 boolean res = true; 39 try { 40 log.println("try to get the valid variable $(user) ..."); 41 String toCheck = "$(user)"; 42 String eString = oObj.getSubstituteVariableValue(toCheck); 43 res = eString.startsWith("file:///"); 44 } catch (com.sun.star.container.NoSuchElementException e) { 45 log.println("$(user) does not exist"); 46 tRes.tested("getSubstituteVariableValue()",false); 47 } 48 try { 49 log.println("try to get a invalid variable..."); 50 String toCheck = "$(ThisVariableShouldNoExist)"; 51 String eString = oObj.getSubstituteVariableValue(toCheck); 52 log.println("$(ThisVariableShouldNoExist) should not exist"); 53 tRes.tested("getSubstituteVariableValue()",false); 54 55 } catch (com.sun.star.container.NoSuchElementException e) { 56 log.println("expected exception was thrown."); 57 res &= true; 58 } 59 60 tRes.tested("getSubstituteVariableValue()",res); 61 } 62 63 public void _substituteVariables() { 64 boolean res = true; 65 try { 66 log.println("try to get a valid variable..."); 67 String toCheck = "$(user)"; 68 String eString = oObj.substituteVariables(toCheck, false); 69 log.println(eString); 70 res = eString.startsWith("file:///"); 71 } catch (com.sun.star.container.NoSuchElementException e) { 72 log.println("$(user) does not exist"); 73 tRes.tested("substituteVariables()",false); 74 } 75 try { 76 log.println("try to get a invalid variable..."); 77 String toCheck = "$(ThisVariableShouldNoExist)"; 78 String eString = oObj.substituteVariables(toCheck,true); 79 log.println("$(ThisVariableShouldNoExist) should not exist"); 80 tRes.tested("substituteVariables()",false); 81 82 } catch (com.sun.star.container.NoSuchElementException e) { 83 log.println("expected exception was thrown."); 84 res &= true; 85 } 86 87 tRes.tested("substituteVariables()",res); 88 } 89 90 public void _reSubstituteVariables() { 91 boolean res = true; 92 log.println("try to get a valid variable..."); 93 String toCheck = "file:///"; 94 String eString = oObj.reSubstituteVariables(toCheck); 95 log.println(eString); 96 res = eString.startsWith("file:///"); 97 98 tRes.tested("reSubstituteVariables()",res); 99 } 100 101 } 102