merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / text / _BaseIndex.java
blobaa988b0f09b16b1338d736af2cffa5c5ffd46c81
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: _BaseIndex.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 ************************************************************************/
30 package ifc.text;
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.container.XIndexAccess;
34 import com.sun.star.container.XIndexReplace;
35 import com.sun.star.text.XTextColumns;
36 import com.sun.star.uno.UnoRuntime;
38 import lib.MultiPropertyTest;
41 /**
42 * Testing <code>com.sun.star.text.BaseIndex</code>
43 * service properties :
44 * <ul>
45 * <li><code> Title</code></li>
46 * <li><code> IsProtected</code></li>
47 * <li><code> ParaStyleHeading</code></li>
48 * <li><code> ParaStyleLevel1</code></li>
49 * <li><code> ParaStyleLevel2</code></li>
50 * <li><code> ParaStyleLevel3</code></li>
51 * <li><code> ParaStyleLevel4</code></li>
52 * <li><code> ParaStyleLevel5</code></li>
53 * <li><code> ParaStyleLevel6</code></li>
54 * <li><code> ParaStyleLevel7</code></li>
55 * <li><code> ParaStyleLevel8</code></li>
56 * <li><code> ParaStyleLevel9</code></li>
57 * <li><code> ParaStyleLevel10</code></li>
58 * <li><code> ParaStyleSeparator</code></li>
59 * <li><code> TextColumns</code></li>
60 * <li><code> BackGraphicURL</code></li>
61 * <li><code> BackGraphicFilter</code></li>
62 * <li><code> BackGraphicLocation</code></li>
63 * <li><code> BackTransparent</code></li>
64 * <li><code> LevelFormat</code></li>
65 * <li><code> CreateFromChapter</code></li>
66 * </ul> <p>
67 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
68 * @see com.sun.star.text.BaseIndex
70 public class _BaseIndex extends MultiPropertyTest {
71 /**
72 * Redefined method returns object, that contains changed property value.
74 protected PropertyTester CustomTester = new PropertyTester() {
75 protected Object getNewValue(String propName, Object oldValue) {
76 XTextColumns TC = (XTextColumns) UnoRuntime.queryInterface(
77 XTextColumns.class, oldValue);
78 TC.setColumnCount((short) (TC.getColumnCount() + (short) 1));
80 return TC;
84 /**
85 * New value must be defined for this property.
87 public void _TextColumns() {
88 log.println(
89 "Testing property 'TextColumns' with custom property tester");
90 testProperty("TextColumns", CustomTester);
93 /**
94 * The value of this property is a collection of document index
95 * level formats. This property is tested in the following manner :
96 * the property value (a collection) is obtained, the first element
97 * of this collection is replaced with new non-empty array
98 * (<code>PropertyValue[][]</code>) with some properties set.
99 * After that the collection is set back as property value. <p>
101 * Comparing of set and got <code>PropertyValue</code> arrays
102 * is difficult because values can be changed after setting
103 * by service miplementation. <p>
105 * Has <b>OK</b> status if the collection again gotten, has a
106 * new first element (i.e. lengths of the old array and the array
107 * get are different or their contents differ).
109 public void _LevelFormat() {
110 log.println(
111 "Testing property 'LevelFormat' with custom property tester");
112 testProperty("LevelFormat",
113 new PropertyTester() {
114 PropertyValue[][] newVal = null;
115 PropertyValue[][] oldVal = null;
117 protected Object getNewValue(String propName, Object oldValue) {
118 XIndexReplace indProp = (XIndexReplace) UnoRuntime.queryInterface(
119 XIndexReplace.class, oldValue);
121 try {
122 oldVal = (PropertyValue[][]) indProp.getByIndex(0);
124 log.println("Get:");
125 printLevelFormatProperty(oldValue);
127 newVal = new PropertyValue[1][2];
129 for (int i = 0; i < newVal[0].length; i++) {
130 newVal[0][i] = new PropertyValue();
133 newVal[0][1].Name = "TokenType";
134 newVal[0][1].Value = "TokenEntryText";
135 newVal[0][0].Name = "Text";
136 newVal[0][0].Value = "BaseIndex";
138 indProp.replaceByIndex(0, newVal);
139 } catch (com.sun.star.lang.WrappedTargetException e) {
140 log.println("Exception occured while testing LevelFormat");
141 e.printStackTrace(log);
142 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
143 log.println("Exception occured while testing LevelFormat");
144 e.printStackTrace(log);
145 } catch (com.sun.star.lang.IllegalArgumentException e) {
146 log.println("Exception occured while testing LevelFormat");
147 e.printStackTrace(log);
150 return indProp;
153 protected void checkResult(String propName, Object oldValue,
154 Object newValue, Object resValue,
155 Exception exception)
156 throws Exception {
157 PropertyValue[][] res = (PropertyValue[][]) ((XIndexAccess) UnoRuntime.queryInterface(
158 XIndexAccess.class,
159 resValue)).getByIndex(0);
161 log.println("Result:");
162 printLevelFormatProperty(resValue);
164 boolean result = (res.length != oldVal.length) ||
165 !util.ValueComparer.equalValue(res, oldVal);
167 tRes.tested(propName, result);
173 * Outputs full description of 'LevelFormat' property
174 * value into <code>log</code>.
176 private void printLevelFormatProperty(Object value) {
177 XIndexReplace indProp = (XIndexReplace) UnoRuntime.queryInterface(
178 XIndexReplace.class, value);
179 PropertyValue[][] val = null;
181 try {
182 log.println(" \u0421ollection has " + indProp.getCount() +
183 " elements : ");
185 for (int i = 0; i < indProp.getCount(); i++) {
186 val = (PropertyValue[][]) indProp.getByIndex(i);
188 log.println(" " + i + ": has " + val.length + " levels :");
190 for (int j = 0; j < val.length; j++) {
191 log.println(" " + j + " level :");
193 for (int k = 0; k < val[j].length; k++) {
194 log.println(" " + val[j][k].Name + "=" +
195 val[j][k].Value);
199 } catch (com.sun.star.lang.WrappedTargetException e) {
200 log.println("Exception occured while printing LevelFormat");
201 e.printStackTrace(log);
202 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
203 log.println("Exception occured while printing LevelFormat");
204 e.printStackTrace(log);
207 } // finish class _NumberingRules