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