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 34 import com.sun.star.lang.XMultiServiceFactory; 35 import com.sun.star.text.XFootnote; 36 import com.sun.star.text.XFootnotesSupplier; 37 import com.sun.star.text.XText; 38 import com.sun.star.text.XTextCursor; 39 import com.sun.star.text.XTextDocument; 40 import com.sun.star.uno.UnoRuntime; 41 import com.sun.star.uno.XInterface; 42 43 44 /** 45 * Test for the object, which is represented as set of footnote properties 46 * (instance of <code>com.sun.star.text.FootnoteSettings</code> service). 47 * Object implements the following interfaces : 48 * <ul> 49 * <li> <code>com::sun::star::text::FootnoteSettings</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.FootnoteSettings 54 * @see ifc.text._FootnoteSettings 55 */ 56 public class SwXFootnoteProperties extends TestCase { 57 XTextDocument xTextDoc; 58 59 /** 60 * Creates text document. 61 */ initialize( TestParameters tParam, PrintWriter log )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 */ cleanup( TestParameters tParam, PrintWriter log )76 protected void cleanup( TestParameters tParam, PrintWriter log ) { 77 log.println( " disposing xTextDoc " ); 78 util.DesktopTools.closeDoc(xTextDoc); 79 } 80 81 /** 82 * Creating a Testenvironment for the interfaces to be tested. 83 * Creates an instance of the service 84 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote 85 * to the text document, and finally gets footnote settings from text 86 * document through <code>XFootnotesSupplier</code> interface.<br> 87 */ createTestEnvironment( TestParameters Param, PrintWriter log )88 public synchronized TestEnvironment createTestEnvironment( 89 TestParameters Param, PrintWriter log ) throws StatusException { 90 XFootnotesSupplier oInterface = null; 91 XInterface oObj = null; 92 XFootnote oFootnote; 93 94 log.println( "Creating a test environment" ); 95 // get a soffice factory object 96 XMultiServiceFactory msf = (XMultiServiceFactory) 97 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 98 log.println("creating a footnote"); 99 100 try { 101 oFootnote = (XFootnote) UnoRuntime.queryInterface(XFootnote.class, 102 msf.createInstance("com.sun.star.text.Footnote")); 103 } catch (com.sun.star.uno.Exception e) { 104 e.printStackTrace(log); 105 throw new StatusException("Couldn't create footnote", e); 106 } 107 108 XText oText = xTextDoc.getText(); 109 XTextCursor oCursor = oText.createTextCursor(); 110 111 log.println("inserting the footnote into text document"); 112 try { 113 oText.insertTextContent(oCursor, oFootnote, false); 114 } catch (com.sun.star.lang.IllegalArgumentException e) { 115 e.printStackTrace(log); 116 throw new StatusException("Couldn't insert the footnote", e); 117 } 118 119 oInterface = (XFootnotesSupplier) 120 UnoRuntime.queryInterface(XFootnotesSupplier.class, xTextDoc); 121 oObj = oInterface.getFootnoteSettings(); 122 123 TestEnvironment tEnv = new TestEnvironment(oObj); 124 return tEnv; 125 } 126 127 } 128 129