1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package ifc.text; 28 29 import com.sun.star.beans.PropertyValue; 30 import com.sun.star.container.XIndexAccess; 31 import com.sun.star.container.XIndexReplace; 32 import com.sun.star.text.XTextColumns; 33 import com.sun.star.uno.UnoRuntime; 34 35 import lib.MultiPropertyTest; 36 37 38 /** 39 * Testing <code>com.sun.star.text.BaseIndex</code> 40 * service properties : 41 * <ul> 42 * <li><code> Title</code></li> 43 * <li><code> IsProtected</code></li> 44 * <li><code> ParaStyleHeading</code></li> 45 * <li><code> ParaStyleLevel1</code></li> 46 * <li><code> ParaStyleLevel2</code></li> 47 * <li><code> ParaStyleLevel3</code></li> 48 * <li><code> ParaStyleLevel4</code></li> 49 * <li><code> ParaStyleLevel5</code></li> 50 * <li><code> ParaStyleLevel6</code></li> 51 * <li><code> ParaStyleLevel7</code></li> 52 * <li><code> ParaStyleLevel8</code></li> 53 * <li><code> ParaStyleLevel9</code></li> 54 * <li><code> ParaStyleLevel10</code></li> 55 * <li><code> ParaStyleSeparator</code></li> 56 * <li><code> TextColumns</code></li> 57 * <li><code> BackGraphicURL</code></li> 58 * <li><code> BackGraphicFilter</code></li> 59 * <li><code> BackGraphicLocation</code></li> 60 * <li><code> BackTransparent</code></li> 61 * <li><code> LevelFormat</code></li> 62 * <li><code> CreateFromChapter</code></li> 63 * </ul> <p> 64 * Properties testing is automated by <code>lib.MultiPropertyTest</code>. 65 * @see com.sun.star.text.BaseIndex 66 */ 67 public class _BaseIndex extends MultiPropertyTest { 68 /** 69 * Redefined method returns object, that contains changed property value. 70 */ 71 protected PropertyTester CustomTester = new PropertyTester() { 72 protected Object getNewValue(String propName, Object oldValue) { 73 XTextColumns TC = (XTextColumns) UnoRuntime.queryInterface( 74 XTextColumns.class, oldValue); 75 TC.setColumnCount((short) (TC.getColumnCount() + (short) 1)); 76 77 return TC; 78 } 79 }; 80 81 /** 82 * New value must be defined for this property. 83 */ 84 public void _TextColumns() { 85 log.println( 86 "Testing property 'TextColumns' with custom property tester"); 87 testProperty("TextColumns", CustomTester); 88 } 89 90 /** 91 * The value of this property is a collection of document index 92 * level formats. This property is tested in the following manner : 93 * the property value (a collection) is obtained, the first element 94 * of this collection is replaced with new non-empty array 95 * (<code>PropertyValue[][]</code>) with some properties set. 96 * After that the collection is set back as property value. <p> 97 * 98 * Comparing of set and got <code>PropertyValue</code> arrays 99 * is difficult because values can be changed after setting 100 * by service miplementation. <p> 101 * 102 * Has <b>OK</b> status if the collection again gotten, has a 103 * new first element (i.e. lengths of the old array and the array 104 * get are different or their contents differ). 105 */ 106 public void _LevelFormat() { 107 log.println( 108 "Testing property 'LevelFormat' with custom property tester"); 109 testProperty("LevelFormat", 110 new PropertyTester() { 111 PropertyValue[][] newVal = null; 112 PropertyValue[][] oldVal = null; 113 114 protected Object getNewValue(String propName, Object oldValue) { 115 XIndexReplace indProp = (XIndexReplace) UnoRuntime.queryInterface( 116 XIndexReplace.class, oldValue); 117 118 try { 119 oldVal = (PropertyValue[][]) indProp.getByIndex(0); 120 121 log.println("Get:"); 122 printLevelFormatProperty(oldValue); 123 124 newVal = new PropertyValue[1][2]; 125 126 for (int i = 0; i < newVal[0].length; i++) { 127 newVal[0][i] = new PropertyValue(); 128 } 129 130 newVal[0][1].Name = "TokenType"; 131 newVal[0][1].Value = "TokenEntryText"; 132 newVal[0][0].Name = "Text"; 133 newVal[0][0].Value = "BaseIndex"; 134 135 indProp.replaceByIndex(0, newVal); 136 } catch (com.sun.star.lang.WrappedTargetException e) { 137 log.println("Exception occured while testing LevelFormat"); 138 e.printStackTrace(log); 139 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 140 log.println("Exception occured while testing LevelFormat"); 141 e.printStackTrace(log); 142 } catch (com.sun.star.lang.IllegalArgumentException e) { 143 log.println("Exception occured while testing LevelFormat"); 144 e.printStackTrace(log); 145 } 146 147 return indProp; 148 } 149 150 protected void checkResult(String propName, Object oldValue, 151 Object newValue, Object resValue, 152 Exception exception) 153 throws Exception { 154 PropertyValue[][] res = (PropertyValue[][]) ((XIndexAccess) UnoRuntime.queryInterface( 155 XIndexAccess.class, 156 resValue)).getByIndex(0); 157 158 log.println("Result:"); 159 printLevelFormatProperty(resValue); 160 161 boolean result = (res.length != oldVal.length) || 162 !util.ValueComparer.equalValue(res, oldVal); 163 164 tRes.tested(propName, result); 165 } 166 }); 167 } 168 169 /** 170 * Outputs full description of 'LevelFormat' property 171 * value into <code>log</code>. 172 */ 173 private void printLevelFormatProperty(Object value) { 174 XIndexReplace indProp = (XIndexReplace) UnoRuntime.queryInterface( 175 XIndexReplace.class, value); 176 PropertyValue[][] val = null; 177 178 try { 179 log.println(" \u0421ollection has " + indProp.getCount() + 180 " elements : "); 181 182 for (int i = 0; i < indProp.getCount(); i++) { 183 val = (PropertyValue[][]) indProp.getByIndex(i); 184 185 log.println(" " + i + ": has " + val.length + " levels :"); 186 187 for (int j = 0; j < val.length; j++) { 188 log.println(" " + j + " level :"); 189 190 for (int k = 0; k < val[j].length; k++) { 191 log.println(" " + val[j][k].Name + "=" + 192 val[j][k].Value); 193 } 194 } 195 } 196 } catch (com.sun.star.lang.WrappedTargetException e) { 197 log.println("Exception occured while printing LevelFormat"); 198 e.printStackTrace(log); 199 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 200 log.println("Exception occured while printing LevelFormat"); 201 e.printStackTrace(log); 202 } 203 } 204 } // finish class _NumberingRules 205