/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package ifc.text;
import lib.MultiMethodTest;
import lib.Status;
import lib.StatusException;
import util.ValueComparer;
import com.sun.star.text.XAutoTextGroup;
import com.sun.star.text.XTextRange;
/**
* Testing com.sun.star.text.XAutoTextGroup
* interface methods :
*
getTitles()
renameByName()
insertNewByName()
removeByName()
* This test needs the following object relations : *
'TextRange'
(of type XTextRange
):
* the range for which an entry is added. * Test is multithread compilant.
* @see com.sun.star.text.XAutoTextGroup */ public class _XAutoTextGroup extends MultiMethodTest { public XAutoTextGroup oObj = null; /** * Unique number among different interface threads. */ protected static int uniq = 0 ; /** * Unique string for AutoTextEntry names among different * threads. */ protected String str = null ; /** * Prefix for unique string. * @see #str */ protected static final String pref = "XAutoTextGroup" ; protected XTextRange oRange = null; /** * Constructs a unique string for current interface thread * for naming purposes. All old entries which names are * started with prefix used for entry names, are deleted * from the group (they can remain after previous unsuccessfull * test runs). The relation is obtained. * * @throws StatusException if the relation is not found. */ public void before() { str = pref + uniq++ ; String[] names = oObj.getElementNames() ; for (int i = 0; i < names.length; i++) { log.println(" " + names[i]); if (names[i].toUpperCase().indexOf(pref.toUpperCase()) > 0) { try { log.println(" ... removing ..."); oObj.removeByName(names[i]) ; } catch (com.sun.star.container.NoSuchElementException e) { log.println("Element '" + names[i] + "' not found."); } } } oRange = (XTextRange) tEnv.getObjRelation("TextRange"); if (oRange == null) { throw new StatusException(Status.failed("No relation found")) ; } } /** * Test calls the method.
* Has OK status if the method returns not
* null
value.
*/
public void _getTitles() {
String[] titles = oObj.getTitles();
tRes.tested("getTitles()",titles != null);
}
/**
* Firsts inserts a new AutoTextEntry
using a range
* from relation, entry titles are checked before and after
* insertion, second tries to add an entry with the same name.
*
* Has OK status if in the first case titles are changed,
* and in the second case ElementExistException
is
* thrown.
*/
public void _insertNewByName() {
boolean result = false;
try {
String[] before = oObj.getTitles();
oObj.insertNewByName(str, "For " + str,oRange);
String[] after = oObj.getTitles();
result = !util.ValueComparer.equalValue(before, after);
}
catch (com.sun.star.container.ElementExistException ex) {
log.println("Exception occured while testing insertNewByName");
ex.printStackTrace(log);
result = false;
}
try {
oObj.insertNewByName(str, "For " + str, oRange);
log.println(
"com::sun::star::container::ElementExistsException wasn't thrown");
oObj.removeByName(str);
result &= false;
} catch (com.sun.star.container.ElementExistException ex) {
result &= true;
} catch (com.sun.star.container.NoSuchElementException ex) {
log.println("Wrong exception was thrown :");
ex.printStackTrace(log);
result &= false;
}
tRes.tested("insertNewByName()",result);
}
/**
* Removes AutoTextEntry
added before and checks
* titles of the group before and after removing.
* Has OK status if titles are not equal before and after * removing and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
insertNewByName()
: the entry is
* inserted here. ElementExistException
* must be thrown. IllegalArgumentException
must be thrown.