1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sw; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 import util.dbg; 34 35 import com.sun.star.beans.XPropertySet; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.text.ControlCharacter; 38 import com.sun.star.text.XLineNumberingProperties; 39 import com.sun.star.text.XText; 40 import com.sun.star.text.XTextCursor; 41 import com.sun.star.text.XTextDocument; 42 import com.sun.star.uno.UnoRuntime; 43 44 /** 45 * Test for object which is represented by service 46 * <code>com.sun.star.text.LineNumberingProperties</code>. <p> 47 * Object implements the following interfaces : 48 * <ul> 49 * <li> <code>com::sun::star::text::LineNumberingProperties</code></li> 50 * </ul> <p> 51 * This object test <b> is NOT </b> designed to be run in several 52 * threads concurently. 53 * @see com.sun.star.text.LineNumberingProperties 54 * @see ifc.text._LineNumberingProperties 55 */ 56 public class SwXLineNumberingProperties extends TestCase { 57 XTextDocument xTextDoc; 58 59 /** 60 * Creates text document. 61 */ 62 protected void initialize( TestParameters tParam, PrintWriter log ) { 63 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 64 try { 65 log.println( "creating a textdocument" ); 66 xTextDoc = SOF.createTextDoc( null ); 67 } catch ( com.sun.star.uno.Exception e ) { 68 e.printStackTrace( log ); 69 throw new StatusException( "Couldn't create document", e ); 70 } 71 } 72 73 /** 74 * Disposes text document. 75 */ 76 protected void cleanup( TestParameters tParam, PrintWriter log ) { 77 log.println( " disposing xTextDoc " ); 78 util.DesktopTools.closeDoc(xTextDoc); 79 } 80 81 82 /** 83 * Creating a Testenvironment for the interfaces to be tested. After inserting 84 * string and control character to the text document, line numbering 85 * properties are gotten using <code>XLineNumberingProperties</code> interface. 86 */ 87 public TestEnvironment createTestEnvironment( 88 TestParameters tParam, PrintWriter log ) throws StatusException { 89 90 // insert some Text 91 XText oText = xTextDoc.getText(); 92 XTextCursor oCursor = oText.createTextCursor(); 93 try { 94 for (int i=0; i<5; i++) { 95 oText.insertString(oCursor, "The quick brown fox jumps "+ 96 "over the lazy Dog", false); 97 oText.insertControlCharacter(oCursor, 98 ControlCharacter.PARAGRAPH_BREAK, false ); 99 } 100 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 101 e.printStackTrace(log); 102 log.println("Exception occured: " + e); 103 } 104 105 XLineNumberingProperties oLNP = (XLineNumberingProperties) 106 UnoRuntime.queryInterface(XLineNumberingProperties.class,xTextDoc); 107 XPropertySet lineNumProps = oLNP.getLineNumberingProperties(); 108 dbg.printPropertiesNames(lineNumProps); 109 TestEnvironment tEnv = new TestEnvironment(lineNumProps); 110 return tEnv; 111 112 } // finish method getTestEnvironment 113 114 } // finish class SwXLineNumberingProperties 115 116