1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.util; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.table.XCell; 27cdf0e10cSrcweir import lib.MultiMethodTest; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.util.XReplaceDescriptor; 30cdf0e10cSrcweir import com.sun.star.util.XReplaceable; 31cdf0e10cSrcweir import com.sun.star.util.XSearchDescriptor; 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** 34cdf0e10cSrcweir * Testing <code>com.sun.star.util.XReplaceable</code> 35cdf0e10cSrcweir * interface methods : 36cdf0e10cSrcweir * <ul> 37cdf0e10cSrcweir * <li><code> createReplaceDescriptor()</code></li> 38cdf0e10cSrcweir * <li><code> replaceAll()</code></li> 39cdf0e10cSrcweir * </ul> <p> 40cdf0e10cSrcweir * 41cdf0e10cSrcweir * The requipment for the tested object is that it 42cdf0e10cSrcweir * <b>must containt</b> string 'xTextDoc'. Only 43cdf0e10cSrcweir * in that case this interface is tested correctly. <p> 44cdf0e10cSrcweir * 45cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 46cdf0e10cSrcweir * @see com.sun.star.util.XReplaceable 47cdf0e10cSrcweir */ 48cdf0e10cSrcweir public class _XReplaceable extends MultiMethodTest { 49cdf0e10cSrcweir 50cdf0e10cSrcweir public XReplaceable oObj = null; 51cdf0e10cSrcweir public XReplaceDescriptor Rdesc = null; 52cdf0e10cSrcweir private String mSearchString = "xTextDoc"; 53cdf0e10cSrcweir private String mReplaceString = "** xTextDoc"; 54cdf0e10cSrcweir private boolean mDispose = false; 55cdf0e10cSrcweir 56cdf0e10cSrcweir /** 57cdf0e10cSrcweir * Creates an entry to search for, if the current object does not provide 58cdf0e10cSrcweir * one. In this case, the environment is disposed after the test, since 59cdf0e10cSrcweir * the inserted object may influence following tests. 60cdf0e10cSrcweir * 61cdf0e10cSrcweir */ before()62cdf0e10cSrcweir protected void before() { 63cdf0e10cSrcweir Object o = tEnv.getObjRelation("SEARCHSTRING"); 64cdf0e10cSrcweir if (o != null) { 65cdf0e10cSrcweir mSearchString = (String)o; 66cdf0e10cSrcweir } 67cdf0e10cSrcweir // use object relation for XSearchable 68cdf0e10cSrcweir o = tEnv.getObjRelation("XSearchable.MAKEENTRYINCELL"); 69cdf0e10cSrcweir if (o != null) { 70cdf0e10cSrcweir XCell[] cells = new XCell[0]; 71cdf0e10cSrcweir if (o instanceof XCell) { 72cdf0e10cSrcweir cells = new XCell[]{(XCell)o}; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir else if (o instanceof XCell[]) { 75cdf0e10cSrcweir cells = (XCell[])o; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir else { 78cdf0e10cSrcweir log.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '" 79cdf0e10cSrcweir + o.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead."); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir for (int i=0; i<cells.length; i++) { 82cdf0e10cSrcweir cells[i].setFormula(mSearchString); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir mDispose = true; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir /** 89cdf0e10cSrcweir * Creates the descriptor for replacing string 'xTextDoc' 90cdf0e10cSrcweir * with string '** xTextDoc'. <p> 91cdf0e10cSrcweir * Has <b> OK </b> status if the returned descriptor is not 92cdf0e10cSrcweir * <code>null</code>. <p> 93cdf0e10cSrcweir */ _createReplaceDescriptor()94cdf0e10cSrcweir public void _createReplaceDescriptor() { 95cdf0e10cSrcweir 96cdf0e10cSrcweir log.println("testing createReplaceDescriptor() ... "); 97cdf0e10cSrcweir 98cdf0e10cSrcweir Rdesc = oObj.createReplaceDescriptor(); 99cdf0e10cSrcweir Rdesc.setSearchString(mSearchString); 100cdf0e10cSrcweir Rdesc.setReplaceString(mReplaceString); 101cdf0e10cSrcweir tRes.tested("createReplaceDescriptor()", Rdesc != null); 102cdf0e10cSrcweir 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir /** 106cdf0e10cSrcweir * Replaces the text using descriptor created before. Then 107cdf0e10cSrcweir * search is performed in the target text. <p> 108cdf0e10cSrcweir * 109cdf0e10cSrcweir * Has <b> OK </b> status if the string '**' is found in 110cdf0e10cSrcweir * the text. <p> 111cdf0e10cSrcweir * 112cdf0e10cSrcweir * The following method tests are to be completed successfully before : 113cdf0e10cSrcweir * <ul> 114cdf0e10cSrcweir * <li> <code> createReplaceDescriptor() </code> : replace 115cdf0e10cSrcweir * descriptor is created. </li> 116cdf0e10cSrcweir * </ul> 117cdf0e10cSrcweir */ _replaceAll()118cdf0e10cSrcweir public void _replaceAll() { 119cdf0e10cSrcweir requiredMethod("createReplaceDescriptor()"); 120cdf0e10cSrcweir oObj.replaceAll(Rdesc); 121cdf0e10cSrcweir XSearchDescriptor SDesc = oObj.createSearchDescriptor(); 122cdf0e10cSrcweir SDesc.setSearchString("**"); 123cdf0e10cSrcweir boolean res = (oObj.findFirst(SDesc) != null); 124cdf0e10cSrcweir // redo replacement 125cdf0e10cSrcweir Rdesc.setSearchString(mReplaceString); 126cdf0e10cSrcweir Rdesc.setReplaceString(mSearchString); 127cdf0e10cSrcweir oObj.replaceAll(Rdesc); 128cdf0e10cSrcweir res &= (oObj.findFirst(SDesc) == null); 129cdf0e10cSrcweir 130cdf0e10cSrcweir tRes.tested("replaceAll()",res); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir /** 134cdf0e10cSrcweir * In case the interface itself made the entry to search for, the environment 135cdf0e10cSrcweir * must be disposed 136cdf0e10cSrcweir */ after()137cdf0e10cSrcweir protected void after() { 138cdf0e10cSrcweir if(mDispose) { 139cdf0e10cSrcweir disposeEnvironment(); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144