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.XIndexAccess; 40 import com.sun.star.container.XNameAccess; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.style.XStyle; 43 import com.sun.star.style.XStyleFamiliesSupplier; 44 import com.sun.star.text.ControlCharacter; 45 import com.sun.star.text.XText; 46 import com.sun.star.text.XTextColumns; 47 import com.sun.star.text.XTextCursor; 48 import com.sun.star.text.XTextDocument; 49 import com.sun.star.uno.AnyConverter; 50 import com.sun.star.uno.Type; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.uno.XInterface; 53 54 /** 55 * Test for object which is represented by service 56 * <code>com.sun.star.text.TextColumns</code>. <p> 57 * Object implements the following interfaces : 58 * <ul> 59 * <li> <code>com::sun::star::text::XTextColumns</code></li> 60 * <li> <code>com::sun::star::text::TextColumns</code></li> 61 * </ul> <p> 62 * This object test <b> is NOT </b> designed to be run in several 63 * threads concurently. 64 * @see com.sun.star.text.XTextColumns 65 * @see com.sun.star.text.TextColumns 66 * @see ifc.text._XTextColumns 67 * @see ifc.text._TextColumns 68 */ 69 public class SwXTextColumns extends TestCase { 70 XTextDocument xTextDoc; 71 72 /** 73 * Creates text document. 74 */ 75 protected void initialize( TestParameters tParam, PrintWriter log ) { 76 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 77 try { 78 log.println( "creating a textdocument" ); 79 xTextDoc = SOF.createTextDoc( null ); 80 } catch ( com.sun.star.uno.Exception e ) { 81 e.printStackTrace( log ); 82 throw new StatusException( "Couldn't create document", e ); 83 } 84 } 85 86 /** 87 * Disposes text document. 88 */ 89 protected void cleanup( TestParameters tParam, PrintWriter log ) { 90 log.println( " disposing xTextDoc " ); 91 util.DesktopTools.closeDoc(xTextDoc); 92 } 93 94 /** 95 * Creating a Testenvironment for the interfaces to be tested. After style 96 * families are gotten from text document using 97 * <code>XStyleFamiliesSupplier</code> interface, style family indexed '2' 98 * is obtained using <code>XIndexAccess</code> interface. Then style 99 * named 'Standard' is gotten from previously obtained style family using 100 * <code>XNameAccess</code> interface, and 'TextColumns' property value 101 * of this style is returned as a test component. Finally, several 102 * paragraphs within the text are inserted to a text document. 103 */ 104 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 105 XInterface oObj = null; 106 TestEnvironment tEnv = null; 107 XStyle oStyle = null; 108 109 log.println( "creating a test environment" ); 110 log.println("getting PageStyle"); 111 XStyleFamiliesSupplier oSFS = (XStyleFamiliesSupplier) 112 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc); 113 XNameAccess oSF = oSFS.getStyleFamilies(); 114 XIndexAccess oSFIA = (XIndexAccess) 115 UnoRuntime.queryInterface(XIndexAccess.class, oSF); 116 117 try { 118 XNameAccess oSFNA = (XNameAccess) AnyConverter.toObject( 119 new Type(XNameAccess.class),oSFIA.getByIndex(2)); 120 oStyle = (XStyle) AnyConverter.toObject( 121 new Type(XStyle.class),oSFNA.getByName("Standard")); 122 } catch ( com.sun.star.lang.WrappedTargetException e ) { 123 log.println("Error, exception occured while getting style."); 124 e.printStackTrace(log); 125 } catch ( com.sun.star.lang.IndexOutOfBoundsException e ) { 126 log.println("Error, exception occured while getting style."); 127 e.printStackTrace(log); 128 } catch ( com.sun.star.container.NoSuchElementException e ) { 129 log.println("Error, exception occured while getting style."); 130 e.printStackTrace(log); 131 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 132 log.println("Error, exception occured while getting style."); 133 e.printStackTrace(log); 134 } 135 136 try { 137 log.println("Getting property ('TextColumns') value of style " 138 + oStyle.getName()); 139 XPropertySet xProps = (XPropertySet) 140 UnoRuntime.queryInterface(XPropertySet.class,oStyle); 141 oObj = (XTextColumns) AnyConverter.toObject( 142 new Type(XTextColumns.class),xProps.getPropertyValue("TextColumns")); 143 } catch ( com.sun.star.lang.WrappedTargetException e ) { 144 log.println("Exception occured while getting style property"); 145 e.printStackTrace(log); 146 } catch ( com.sun.star.beans.UnknownPropertyException e ) { 147 log.println("Exception occured while getting style property"); 148 e.printStackTrace(log); 149 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 150 log.println("Exception occured while getting style property"); 151 e.printStackTrace(log); 152 } 153 154 XText oText = xTextDoc.getText(); 155 XTextCursor oCursor = oText.createTextCursor(); 156 157 log.println( "inserting some text to text document..." ); 158 try { 159 for (int i =0; i < 5; i++){ 160 oText.insertString( oCursor,"Paragraph Number: " + i, false); 161 oText.insertString( oCursor, 162 "The quick brown fox jumps over the lazy Dog: SwXParagraph", 163 false); 164 oText.insertControlCharacter( oCursor, 165 ControlCharacter.PARAGRAPH_BREAK, false ); 166 oText.insertString( oCursor, 167 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph", 168 false); 169 oText.insertControlCharacter( oCursor, 170 ControlCharacter.PARAGRAPH_BREAK, false ); 171 oText.insertControlCharacter( oCursor, 172 ControlCharacter.LINE_BREAK, false ); 173 } 174 } catch ( com.sun.star.lang.IllegalArgumentException e ){ 175 log.println("Exception occured while inserting Text"); 176 e.printStackTrace(log); 177 } 178 179 log.println("creating a new environment for object"); 180 tEnv = new TestEnvironment(oObj); 181 return tEnv; 182 } // finish method getTestEnvironment 183 184 } // finish class SwXTextColumns 185