Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / util / _XReplaceable.java
blob97d4173bf33e480263e58cb1da34b055b8338b05
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XReplaceable.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.util;
33 import com.sun.star.table.XCell;
34 import lib.MultiMethodTest;
36 import com.sun.star.util.XReplaceDescriptor;
37 import com.sun.star.util.XReplaceable;
38 import com.sun.star.util.XSearchDescriptor;
40 /**
41 * Testing <code>com.sun.star.util.XReplaceable</code>
42 * interface methods :
43 * <ul>
44 * <li><code> createReplaceDescriptor()</code></li>
45 * <li><code> replaceAll()</code></li>
46 * </ul> <p>
48 * The requipment for the tested object is that it
49 * <b>must containt</b> string 'xTextDoc'. Only
50 * in that case this interface is tested correctly. <p>
52 * Test is <b> NOT </b> multithread compilant. <p>
53 * @see com.sun.star.util.XReplaceable
55 public class _XReplaceable extends MultiMethodTest {
57 public XReplaceable oObj = null;
58 public XReplaceDescriptor Rdesc = null;
59 private String mSearchString = "xTextDoc";
60 private String mReplaceString = "** xTextDoc";
61 private boolean mDispose = false;
63 /**
64 * Creates an entry to search for, if the current object does not provide
65 * one. In this case, the environment is disposed after the test, since
66 * the inserted object may influence following tests.
69 protected void before() {
70 Object o = tEnv.getObjRelation("SEARCHSTRING");
71 if (o != null) {
72 mSearchString = (String)o;
74 // use object relation for XSearchable
75 o = tEnv.getObjRelation("XSearchable.MAKEENTRYINCELL");
76 if (o != null) {
77 XCell[] cells = new XCell[0];
78 if (o instanceof XCell) {
79 cells = new XCell[]{(XCell)o};
81 else if (o instanceof XCell[]) {
82 cells = (XCell[])o;
84 else {
85 log.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '"
86 + o.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead.");
88 for (int i=0; i<cells.length; i++) {
89 cells[i].setFormula(mSearchString);
91 mDispose = true;
95 /**
96 * Creates the descriptor for replacing string 'xTextDoc'
97 * with string '** xTextDoc'. <p>
98 * Has <b> OK </b> status if the returned descriptor is not
99 * <code>null</code>. <p>
101 public void _createReplaceDescriptor() {
103 log.println("testing createReplaceDescriptor() ... ");
105 Rdesc = oObj.createReplaceDescriptor();
106 Rdesc.setSearchString(mSearchString);
107 Rdesc.setReplaceString(mReplaceString);
108 tRes.tested("createReplaceDescriptor()", Rdesc != null);
113 * Replaces the text using descriptor created before. Then
114 * search is performed in the target text. <p>
116 * Has <b> OK </b> status if the string '**' is found in
117 * the text. <p>
119 * The following method tests are to be completed successfully before :
120 * <ul>
121 * <li> <code> createReplaceDescriptor() </code> : replace
122 * descriptor is created. </li>
123 * </ul>
125 public void _replaceAll() {
126 requiredMethod("createReplaceDescriptor()");
127 oObj.replaceAll(Rdesc);
128 XSearchDescriptor SDesc = oObj.createSearchDescriptor();
129 SDesc.setSearchString("**");
130 boolean res = (oObj.findFirst(SDesc) != null);
131 // redo replacement
132 Rdesc.setSearchString(mReplaceString);
133 Rdesc.setReplaceString(mSearchString);
134 oObj.replaceAll(Rdesc);
135 res &= (oObj.findFirst(SDesc) == null);
137 tRes.tested("replaceAll()",res);
141 * In case the interface itself made the entry to search for, the environment
142 * must be disposed
144 protected void after() {
145 if(mDispose) {
146 disposeEnvironment();