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 28 package mod._sw; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.container.XEnumeration; 40 import com.sun.star.container.XEnumerationAccess; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.text.ControlCharacter; 43 import com.sun.star.text.XText; 44 import com.sun.star.text.XTextCursor; 45 import com.sun.star.text.XTextDocument; 46 import com.sun.star.uno.AnyConverter; 47 import com.sun.star.uno.Type; 48 import com.sun.star.uno.UnoRuntime; 49 import com.sun.star.uno.XInterface; 50 import com.sun.star.util.XCloseable; 51 52 /** 53 * Test for object which is represented by service 54 * <code>com.sun.star.text.Paragraph</code>. <p> 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>com::sun::star::text::XTextContent</code></li> 58 * <li> <code>com::sun::star::text::TextContent</code></li> 59 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li> 60 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 61 * <li> <code>com::sun::star::container::XElementAccess</code></li> 62 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 63 * <li> <code>com::sun::star::beans::XPropertyState</code></li> 64 * <li> <code>com::sun::star::style::CharacterProperties</code></li> 65 * <li> <code>com::sun::star::style::ParagraphProperties</code></li> 66 * <li> <code>com::sun::star::lang::XComponent</code></li> 67 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li> 68 * </ul> <p> 69 * This object test <b> is NOT </b> designed to be run in several 70 * threads concurently. 71 * @see com.sun.star.text.XTextContent 72 * @see com.sun.star.text.TextContent 73 * @see com.sun.star.style.CharacterPropertiesComplex 74 * @see com.sun.star.beans.XPropertySet 75 * @see com.sun.star.container.XElementAccess 76 * @see com.sun.star.container.XEnumerationAccess 77 * @see com.sun.star.beans.XPropertyState 78 * @see com.sun.star.style.CharacterProperties 79 * @see com.sun.star.style.ParagraphProperties 80 * @see com.sun.star.lang.XComponent 81 * @see com.sun.star.style.CharacterPropertiesAsian 82 * @see com.sun.star.text.Paragraph 83 * @see ifc.text._XTextContent 84 * @see ifc.text._TextContent 85 * @see ifc.style._CharacterPropertiesComplex 86 * @see ifc.beans._XPropertySet 87 * @see ifc.container._XElementAccess 88 * @see ifc.container._XEnumerationAccess 89 * @see ifc.beans._XPropertyState 90 * @see ifc.style._CharacterProperties 91 * @see ifc.style._ParagraphProperties 92 * @see ifc.lang._XComponent 93 * @see ifc.style._CharacterPropertiesAsian 94 */ 95 public class SwXParagraph extends TestCase { 96 XTextDocument xTextDoc; 97 98 /** 99 * Creates text document. 100 */ 101 protected void initialize( TestParameters tParam, PrintWriter log ) { 102 103 } 104 105 protected void cleanup(TestParameters tParam, PrintWriter log) { 106 log.println(" disposing xTextDoc "); 107 108 try { 109 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 110 XCloseable.class, xTextDoc); 111 closer.close(true); 112 } catch (com.sun.star.util.CloseVetoException e) { 113 log.println("couldn't close document"); 114 } catch (com.sun.star.lang.DisposedException e) { 115 log.println("couldn't close document"); 116 } 117 } 118 119 120 /** 121 * Creating a Testenvironment for the interfaces to be tested. To obtain 122 * test component, at first several paragraphs are inserted to a major text 123 * of text document. Then enumeration of text paragraphs is created, and 124 * some paragraph is gotten using <code>XEnumeration</code> interface.<p> 125 * Object relations created : 126 * <ul> 127 * <li> <code>'PARA'</code> for 128 * {@link ifc.style._CharacterProperties} : paragraph </li> 129 * <li> <code>'PORTION'</code> for 130 * {@link ifc.style._CharacterProperties} : some text portion of 131 * paragraph. To obtain text portion, enumeration of paragraph text portions is 132 * created, and some text portion is gotten using <code>XEnumeration</code> 133 * interface. </li> 134 * <li> <code>'NRULES'</code> for 135 * {@link ifc.style._ParagraphProperties} : value of property 136 * 'NumberingRules' of paragraph. Method changes property 137 * 'NumberingStyleName' of previously obtained paragraph, and gets value of 138 * a property 'NumberingRules'. </li> 139 * </ul> 140 */ 141 protected synchronized TestEnvironment createTestEnvironment 142 (TestParameters tParam, PrintWriter log) { 143 144 if (xTextDoc != null) { 145 log.println(" disposing xTextDoc "); 146 147 try { 148 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 149 XCloseable.class, xTextDoc); 150 closer.close(true); 151 } catch (com.sun.star.util.CloseVetoException e) { 152 log.println("couldn't close document"); 153 } catch (com.sun.star.lang.DisposedException e) { 154 log.println("couldn't close document"); 155 } 156 } 157 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() ); 158 try { 159 log.println( "creating a textdocument" ); 160 xTextDoc = SOF.createTextDoc( null ); 161 } catch ( com.sun.star.uno.Exception e ) { 162 e.printStackTrace( log ); 163 throw new StatusException( "Couldn't create document", e ); 164 } 165 166 XInterface oObj = null; 167 XPropertySet paraP = null; 168 XPropertySet portP = null; 169 Object nRules = null; 170 XInterface port = null; 171 XInterface para = null; 172 173 log.println( "creating a test environment" ); 174 175 176 XText oText = xTextDoc.getText(); 177 XTextCursor oCursor = oText.createTextCursor(); 178 179 log.println( "inserting some lines" ); 180 try { 181 for (int i=0; i<5; i++){ 182 oText.insertString( oCursor,"Paragraph Number: " + i, false); 183 oText.insertString( oCursor, 184 " The quick brown fox jumps over the lazy Dog: SwXParagraph", 185 false); 186 oText.insertControlCharacter( 187 oCursor, ControlCharacter.PARAGRAPH_BREAK, false ); 188 oText.insertString( oCursor, 189 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph", 190 false); 191 oText.insertControlCharacter(oCursor, 192 ControlCharacter.PARAGRAPH_BREAK, false ); 193 oText.insertControlCharacter( 194 oCursor, ControlCharacter.LINE_BREAK, false ); 195 } 196 } catch ( com.sun.star.lang.IllegalArgumentException e ){ 197 e.printStackTrace(log); 198 throw new StatusException( "Couldn't insert lines", e ); 199 } 200 201 // Enumeration 202 XEnumerationAccess oEnumA = (XEnumerationAccess) 203 UnoRuntime.queryInterface(XEnumerationAccess.class, oText ); 204 XEnumeration oEnum = oEnumA.createEnumeration(); 205 206 try { 207 para = (XInterface) AnyConverter.toObject( 208 new Type(XInterface.class),oEnum.nextElement()); 209 XEnumerationAccess oEnumB = (XEnumerationAccess) 210 UnoRuntime.queryInterface( XEnumerationAccess.class, para ); 211 XEnumeration oEnum2 = oEnumB.createEnumeration(); 212 port = (XInterface) AnyConverter.toObject( 213 new Type(XInterface.class),oEnum2.nextElement()); 214 } catch ( com.sun.star.lang.WrappedTargetException e ) { 215 e.printStackTrace(log); 216 log.println("Error: exception occured..."); 217 } catch ( com.sun.star.container.NoSuchElementException e ) { 218 e.printStackTrace(log); 219 log.println("Error: exception occured..."); 220 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 221 e.printStackTrace(log); 222 log.println("Error: exception occured..."); 223 } 224 225 try { 226 portP = (XPropertySet) 227 UnoRuntime.queryInterface(XPropertySet.class, port); 228 paraP = (XPropertySet) 229 UnoRuntime.queryInterface(XPropertySet.class, para); 230 paraP.setPropertyValue("NumberingStyleName","Numbering 4"); 231 nRules = paraP.getPropertyValue("NumberingRules"); 232 } catch ( com.sun.star.lang.WrappedTargetException e ) { 233 log.println("Error, exception occured..."); 234 e.printStackTrace(log); 235 throw new StatusException( "Couldn't get Paragraph", e ); 236 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 237 log.println("Error, exception occured..."); 238 e.printStackTrace(log); 239 throw new StatusException( "Couldn't get Paragraph", e ); 240 } catch ( com.sun.star.beans.UnknownPropertyException e ) { 241 log.println("Error, exception occured..."); 242 e.printStackTrace(log); 243 throw new StatusException( "Couldn't get Paragraph", e ); 244 } catch ( com.sun.star.beans.PropertyVetoException e ) { 245 log.println("Error, exception occured..."); 246 e.printStackTrace(log); 247 throw new StatusException( "Couldn't get Paragraph", e ); 248 } 249 250 251 try { 252 oObj = (XInterface) AnyConverter.toObject( 253 new Type(XInterface.class),oEnum.nextElement()); 254 } catch ( Exception e) { 255 log.println("Error, exception occured..."); 256 e.printStackTrace(log); 257 throw new StatusException( "Couldn't get Paragraph", e ); 258 } 259 260 261 log.println( "creating a new environment for Paragraph object" ); 262 TestEnvironment tEnv = new TestEnvironment( oObj ); 263 264 log.println("adding ObjectRelation 'PARA' for CharacterProperties"); 265 tEnv.addObjRelation("PARA", paraP); 266 267 log.println("adding ObjectRelation 'PORTION' for CharacterProperties"); 268 tEnv.addObjRelation("PORTION", portP); 269 270 log.println("adding ObjectRelation 'NRULES' for ParagraphProperties"); 271 tEnv.addObjRelation("NRULES", nRules); 272 273 tEnv.addObjRelation("NoAttach","SwXParagraph"); 274 275 return tEnv; 276 } // finish method getTestEnvironment 277 278 } // finish class SwXParagraph 279 280