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.container.XNamed; 39 import com.sun.star.lang.XMultiServiceFactory; 40 import com.sun.star.text.XReferenceMarksSupplier; 41 import com.sun.star.text.XText; 42 import com.sun.star.text.XTextContent; 43 import com.sun.star.text.XTextCursor; 44 import com.sun.star.text.XTextDocument; 45 import com.sun.star.uno.UnoRuntime; 46 import com.sun.star.uno.XInterface; 47 48 /** 49 * Test for object which is represented by service 50 * <code>com.sun.star.text.ReferenceMarks</code>. <p> 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::container::XNameAccess</code></li> 54 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 55 * <li> <code>com::sun::star::container::XElementAccess</code></li> 56 * </ul> <p> 57 * This object test <b> is NOT </b> designed to be run in several 58 * threads concurently. 59 * @see com.sun.star.container.XNameAccess 60 * @see com.sun.star.container.XIndexAccess 61 * @see com.sun.star.container.XElementAccess 62 * @see com.sun.star.text.ReferenceMarks 63 * @see ifc.container._XNameAccess 64 * @see ifc.container._XIndexAccess 65 * @see ifc.container._XElementAccess 66 */ 67 public class SwXReferenceMarks extends TestCase { 68 XTextDocument xTextDoc; 69 70 /** 71 * Creates text document. 72 */ 73 protected void initialize( TestParameters tParam, PrintWriter log ) { 74 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 75 try { 76 log.println( "creating a textdocument" ); 77 xTextDoc = SOF.createTextDoc( null ); 78 } catch ( com.sun.star.uno.Exception e ) { 79 e.printStackTrace( log ); 80 throw new StatusException( "Couldn't create document", e ); 81 } 82 } 83 84 /** 85 * Disposes text document. 86 */ 87 protected void cleanup( TestParameters tParam, PrintWriter log ) { 88 log.println( " disposing xTextDoc " ); 89 util.DesktopTools.closeDoc(xTextDoc); 90 } 91 92 /** 93 * Creating a Testenvironment for the interfaces to be tested. 94 * Creates an instances of the service 95 * <code>com.sun.star.text.ReferenceMark</code>, then sets new names to 96 * created ReferenceMark's using <code>XNamed</code> interface. Then renamed 97 * ReferenceMark's are inserted to a major text of text document. Finally, 98 * ReferenceMarks are gotten from text document using 99 * <code>XReferenceMarksSupplier</code> interface. 100 */ 101 public synchronized TestEnvironment createTestEnvironment( 102 TestParameters tParam, PrintWriter log ) throws StatusException { 103 XInterface oObj = null; 104 XText oText = null; 105 String Name = "SwXReferenceMark01"; 106 String Name2 = "SwXReferenceMark02"; 107 108 log.println( "creating a test environment" ); 109 oText = xTextDoc.getText(); 110 111 XMultiServiceFactory oDocMSF = (XMultiServiceFactory) 112 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 113 114 // Creation and insertion of ReferenceMark01 115 try { 116 oObj = (XInterface) 117 oDocMSF.createInstance( "com.sun.star.text.ReferenceMark" ); 118 } catch ( com.sun.star.uno.Exception e ) { 119 e.printStackTrace( log ); 120 throw new StatusException( "Couldn't get ReferenceMark", e); 121 } 122 XNamed oObjN = (XNamed) UnoRuntime.queryInterface(XNamed.class, oObj); 123 oObjN.setName(Name); 124 XTextContent oObjTC = (XTextContent) 125 UnoRuntime.queryInterface(XTextContent.class, oObj); 126 XTextCursor oCursor = oText.createTextCursor(); 127 try { 128 oText.insertTextContent(oCursor, oObjTC, false); 129 } catch ( com.sun.star.lang.IllegalArgumentException e ){ 130 e.printStackTrace( log ); 131 throw new StatusException(" Couldn't insert ReferenceMark01", e); 132 } 133 134 // Creation and insertion of ReferenceMark02 135 try { 136 oObj = (XInterface) 137 oDocMSF.createInstance( "com.sun.star.text.ReferenceMark" ); 138 } catch ( com.sun.star.uno.Exception e ) { 139 e.printStackTrace( log ); 140 throw new StatusException( "Couldn't get ReferenceMark", e); 141 } 142 XNamed oObjN2 = (XNamed) UnoRuntime.queryInterface(XNamed.class, oObj); 143 oObjN2.setName(Name2); 144 145 XTextContent oObjTC2 = (XTextContent) 146 UnoRuntime.queryInterface(XTextContent.class, oObj); 147 try { 148 oText.insertTextContent(oCursor, oObjTC2, false); 149 } catch ( com.sun.star.lang.IllegalArgumentException e ){ 150 e.printStackTrace( log ); 151 throw new StatusException(" Couldn't insert ReferenceMark02", e); 152 } 153 154 // getting ReferenceMarks from text document 155 XReferenceMarksSupplier oRefSupp = (XReferenceMarksSupplier) 156 UnoRuntime.queryInterface(XReferenceMarksSupplier.class, xTextDoc); 157 oObj = oRefSupp.getReferenceMarks(); 158 159 TestEnvironment tEnv = new TestEnvironment( oObj ); 160 return tEnv; 161 } // finish method getTestEnvironment 162 163 } // finish class SwXReferenceMarks 164 165