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 .
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
;
29 * Testing <code>com.sun.star.util.XReplaceable</code>
32 * <li><code> createReplaceDescriptor()</code></li>
33 * <li><code> replaceAll()</code></li>
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 compliant. <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 static final String mReplaceString
= "** xTextDoc";
49 private boolean mDispose
= false;
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.
58 protected void before() {
59 Object o
= tEnv
.getObjRelation("SEARCHSTRING");
61 mSearchString
= (String
)o
;
63 // use object relation for XSearchable
64 o
= tEnv
.getObjRelation("XSearchable.MAKEENTRYINCELL");
66 XCell
[] cells
= new XCell
[0];
67 if (o
instanceof XCell
) {
68 cells
= new XCell
[]{(XCell
)o
};
70 else if (o
instanceof XCell
[]) {
74 log
.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '"
75 + o
.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead.");
77 for (int i
=0; i
<cells
.length
; i
++) {
78 cells
[i
].setFormula(mSearchString
);
85 * Creates the descriptor for replacing string 'xTextDoc'
86 * with string '** xTextDoc'. <p>
87 * Has <b> OK </b> status if the returned descriptor is not
88 * <code>null</code>. <p>
90 public void _createReplaceDescriptor() {
92 log
.println("testing createReplaceDescriptor() ... ");
94 Rdesc
= oObj
.createReplaceDescriptor();
95 Rdesc
.setSearchString(mSearchString
);
96 Rdesc
.setReplaceString(mReplaceString
);
97 tRes
.tested("createReplaceDescriptor()", Rdesc
!= null);
102 * Replaces the text using descriptor created before. Then
103 * search is performed in the target text. <p>
105 * Has <b> OK </b> status if the string '**' is found in
108 * The following method tests are to be completed successfully before :
110 * <li> <code> createReplaceDescriptor() </code> : replace
111 * descriptor is created. </li>
114 public void _replaceAll() {
115 requiredMethod("createReplaceDescriptor()");
116 oObj
.replaceAll(Rdesc
);
117 XSearchDescriptor SDesc
= oObj
.createSearchDescriptor();
118 SDesc
.setSearchString("**");
119 boolean res
= (oObj
.findFirst(SDesc
) != null);
121 Rdesc
.setSearchString(mReplaceString
);
122 Rdesc
.setReplaceString(mSearchString
);
123 oObj
.replaceAll(Rdesc
);
124 res
&= (oObj
.findFirst(SDesc
) == null);
126 tRes
.tested("replaceAll()",res
);
130 * In case the interface itself made the entry to search for, the environment
134 protected void after() {
136 disposeEnvironment();