bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XReplaceable.java
blobc60382c8ca7f278ebefec86c7dc15b94c397594f
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.util;
21 import com.sun.star.table.XCell;
22 import lib.MultiMethodTest;
24 import com.sun.star.util.XReplaceDescriptor;
25 import com.sun.star.util.XReplaceable;
26 import com.sun.star.util.XSearchDescriptor;
28 /**
29 * Testing <code>com.sun.star.util.XReplaceable</code>
30 * interface methods :
31 * <ul>
32 * <li><code> createReplaceDescriptor()</code></li>
33 * <li><code> replaceAll()</code></li>
34 * </ul> <p>
36 * The requipment for the tested object is that it
37 * <b>must containt</b> string 'xTextDoc'. Only
38 * in that case this interface is tested correctly. <p>
40 * Test is <b> NOT </b> multithread compilant. <p>
41 * @see com.sun.star.util.XReplaceable
43 public class _XReplaceable extends MultiMethodTest {
45 public XReplaceable oObj = null;
46 public XReplaceDescriptor Rdesc = null;
47 private String mSearchString = "xTextDoc";
48 private String mReplaceString = "** xTextDoc";
49 private boolean mDispose = false;
51 /**
52 * Creates an entry to search for, if the current object does not provide
53 * one. In this case, the environment is disposed after the test, since
54 * the inserted object may influence following tests.
57 protected void before() {
58 Object o = tEnv.getObjRelation("SEARCHSTRING");
59 if (o != null) {
60 mSearchString = (String)o;
62 // use object relation for XSearchable
63 o = tEnv.getObjRelation("XSearchable.MAKEENTRYINCELL");
64 if (o != null) {
65 XCell[] cells = new XCell[0];
66 if (o instanceof XCell) {
67 cells = new XCell[]{(XCell)o};
69 else if (o instanceof XCell[]) {
70 cells = (XCell[])o;
72 else {
73 log.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '"
74 + o.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead.");
76 for (int i=0; i<cells.length; i++) {
77 cells[i].setFormula(mSearchString);
79 mDispose = true;
83 /**
84 * Creates the descriptor for replacing string 'xTextDoc'
85 * with string '** xTextDoc'. <p>
86 * Has <b> OK </b> status if the returned descriptor is not
87 * <code>null</code>. <p>
89 public void _createReplaceDescriptor() {
91 log.println("testing createReplaceDescriptor() ... ");
93 Rdesc = oObj.createReplaceDescriptor();
94 Rdesc.setSearchString(mSearchString);
95 Rdesc.setReplaceString(mReplaceString);
96 tRes.tested("createReplaceDescriptor()", Rdesc != null);
101 * Replaces the text using descriptor created before. Then
102 * search is performed in the target text. <p>
104 * Has <b> OK </b> status if the string '**' is found in
105 * the text. <p>
107 * The following method tests are to be completed successfully before :
108 * <ul>
109 * <li> <code> createReplaceDescriptor() </code> : replace
110 * descriptor is created. </li>
111 * </ul>
113 public void _replaceAll() {
114 requiredMethod("createReplaceDescriptor()");
115 oObj.replaceAll(Rdesc);
116 XSearchDescriptor SDesc = oObj.createSearchDescriptor();
117 SDesc.setSearchString("**");
118 boolean res = (oObj.findFirst(SDesc) != null);
119 // redo replacement
120 Rdesc.setSearchString(mReplaceString);
121 Rdesc.setReplaceString(mSearchString);
122 oObj.replaceAll(Rdesc);
123 res &= (oObj.findFirst(SDesc) == null);
125 tRes.tested("replaceAll()",res);
129 * In case the interface itself made the entry to search for, the environment
130 * must be disposed
132 protected void after() {
133 if(mDispose) {
134 disposeEnvironment();