1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.util; 25 26 import com.sun.star.util.XStringSubstitution; 27 import lib.MultiMethodTest; 28 29 public class _XStringSubstitution extends MultiMethodTest { 30 31 public XStringSubstitution oObj; 32 _getSubstituteVariableValue()33 public void _getSubstituteVariableValue() { 34 boolean res = true; 35 try { 36 log.println("try to get the valid variable $(user) ..."); 37 String toCheck = "$(user)"; 38 String eString = oObj.getSubstituteVariableValue(toCheck); 39 res = eString.startsWith("file:///"); 40 } catch (com.sun.star.container.NoSuchElementException e) { 41 log.println("$(user) does not exist"); 42 tRes.tested("getSubstituteVariableValue()",false); 43 } 44 try { 45 log.println("try to get a invalid variable..."); 46 String toCheck = "$(ThisVariableShouldNoExist)"; 47 String eString = oObj.getSubstituteVariableValue(toCheck); 48 log.println("$(ThisVariableShouldNoExist) should not exist"); 49 tRes.tested("getSubstituteVariableValue()",false); 50 51 } catch (com.sun.star.container.NoSuchElementException e) { 52 log.println("expected exception was thrown."); 53 res &= true; 54 } 55 56 tRes.tested("getSubstituteVariableValue()",res); 57 } 58 _substituteVariables()59 public void _substituteVariables() { 60 boolean res = true; 61 try { 62 log.println("try to get a valid variable..."); 63 String toCheck = "$(user)"; 64 String eString = oObj.substituteVariables(toCheck, false); 65 log.println(eString); 66 res = eString.startsWith("file:///"); 67 } catch (com.sun.star.container.NoSuchElementException e) { 68 log.println("$(user) does not exist"); 69 tRes.tested("substituteVariables()",false); 70 } 71 try { 72 log.println("try to get a invalid variable..."); 73 String toCheck = "$(ThisVariableShouldNoExist)"; 74 String eString = oObj.substituteVariables(toCheck,true); 75 log.println("$(ThisVariableShouldNoExist) should not exist"); 76 tRes.tested("substituteVariables()",false); 77 78 } catch (com.sun.star.container.NoSuchElementException e) { 79 log.println("expected exception was thrown."); 80 res &= true; 81 } 82 83 tRes.tested("substituteVariables()",res); 84 } 85 _reSubstituteVariables()86 public void _reSubstituteVariables() { 87 boolean res = true; 88 log.println("try to get a valid variable..."); 89 String toCheck = "file:///"; 90 String eString = oObj.reSubstituteVariables(toCheck); 91 log.println(eString); 92 res = eString.startsWith("file:///"); 93 94 tRes.tested("reSubstituteVariables()",res); 95 } 96 97 } 98