Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XReplaceable.java
blob9f2a801cfcbfe757fde9984d5341a9f6ff64cd28
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc.util;
30 import com.sun.star.table.XCell;
31 import lib.MultiMethodTest;
33 import com.sun.star.util.XReplaceDescriptor;
34 import com.sun.star.util.XReplaceable;
35 import com.sun.star.util.XSearchDescriptor;
37 /**
38 * Testing <code>com.sun.star.util.XReplaceable</code>
39 * interface methods :
40 * <ul>
41 * <li><code> createReplaceDescriptor()</code></li>
42 * <li><code> replaceAll()</code></li>
43 * </ul> <p>
45 * The requipment for the tested object is that it
46 * <b>must containt</b> string 'xTextDoc'. Only
47 * in that case this interface is tested correctly. <p>
49 * Test is <b> NOT </b> multithread compilant. <p>
50 * @see com.sun.star.util.XReplaceable
52 public class _XReplaceable extends MultiMethodTest {
54 public XReplaceable oObj = null;
55 public XReplaceDescriptor Rdesc = null;
56 private String mSearchString = "xTextDoc";
57 private String mReplaceString = "** xTextDoc";
58 private boolean mDispose = false;
60 /**
61 * Creates an entry to search for, if the current object does not provide
62 * one. In this case, the environment is disposed after the test, since
63 * the inserted object may influence following tests.
66 protected void before() {
67 Object o = tEnv.getObjRelation("SEARCHSTRING");
68 if (o != null) {
69 mSearchString = (String)o;
71 // use object relation for XSearchable
72 o = tEnv.getObjRelation("XSearchable.MAKEENTRYINCELL");
73 if (o != null) {
74 XCell[] cells = new XCell[0];
75 if (o instanceof XCell) {
76 cells = new XCell[]{(XCell)o};
78 else if (o instanceof XCell[]) {
79 cells = (XCell[])o;
81 else {
82 log.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '"
83 + o.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead.");
85 for (int i=0; i<cells.length; i++) {
86 cells[i].setFormula(mSearchString);
88 mDispose = true;
92 /**
93 * Creates the descriptor for replacing string 'xTextDoc'
94 * with string '** xTextDoc'. <p>
95 * Has <b> OK </b> status if the returned descriptor is not
96 * <code>null</code>. <p>
98 public void _createReplaceDescriptor() {
100 log.println("testing createReplaceDescriptor() ... ");
102 Rdesc = oObj.createReplaceDescriptor();
103 Rdesc.setSearchString(mSearchString);
104 Rdesc.setReplaceString(mReplaceString);
105 tRes.tested("createReplaceDescriptor()", Rdesc != null);
110 * Replaces the text using descriptor created before. Then
111 * search is performed in the target text. <p>
113 * Has <b> OK </b> status if the string '**' is found in
114 * the text. <p>
116 * The following method tests are to be completed successfully before :
117 * <ul>
118 * <li> <code> createReplaceDescriptor() </code> : replace
119 * descriptor is created. </li>
120 * </ul>
122 public void _replaceAll() {
123 requiredMethod("createReplaceDescriptor()");
124 oObj.replaceAll(Rdesc);
125 XSearchDescriptor SDesc = oObj.createSearchDescriptor();
126 SDesc.setSearchString("**");
127 boolean res = (oObj.findFirst(SDesc) != null);
128 // redo replacement
129 Rdesc.setSearchString(mReplaceString);
130 Rdesc.setReplaceString(mSearchString);
131 oObj.replaceAll(Rdesc);
132 res &= (oObj.findFirst(SDesc) == null);
134 tRes.tested("replaceAll()",res);
138 * In case the interface itself made the entry to search for, the environment
139 * must be disposed
141 protected void after() {
142 if(mDispose) {
143 disposeEnvironment();