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.XText; 41 import com.sun.star.text.XTextContent; 42 import com.sun.star.text.XTextCursor; 43 import com.sun.star.text.XTextDocument; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 47 /** 48 * Test for object which is represented by service 49 * <code>com.sun.star.text.ReferenceMark</code>. <p> 50 * Object implements the following interfaces : 51 * <ul> 52 * <li> <code>com::sun::star::container::XNamed</code></li> 53 * <li> <code>com::sun::star::lang::XComponent</code></li> 54 * <li> <code>com::sun::star::text::XTextContent</code></li> 55 * </ul> <p> 56 * This object test <b> is NOT </b> designed to be run in several 57 * threads concurently. 58 * @see com.sun.star.container.XNamed 59 * @see com.sun.star.lang.XComponent 60 * @see com.sun.star.text.XTextContent 61 * @see com.sun.star.text.ReferenceMark 62 * @see ifc.container._XNamed 63 * @see ifc.lang._XComponent 64 * @see ifc.text._XTextContent 65 */ 66 public class SwXReferenceMark extends TestCase { 67 XTextDocument xTextDoc; 68 69 /** 70 * Creates text document. 71 */ 72 protected void initialize( TestParameters tParam, PrintWriter log ) { 73 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 74 try { 75 log.println( "creating a textdocument" ); 76 xTextDoc = SOF.createTextDoc( null ); 77 } catch ( com.sun.star.uno.Exception e ) { 78 e.printStackTrace( log ); 79 throw new StatusException( "Couldn't create document", e ); 80 } 81 } 82 83 /** 84 * Disposes text document. 85 */ 86 protected void cleanup( TestParameters tParam, PrintWriter log ) { 87 log.println( " disposing xTextDoc " ); 88 util.DesktopTools.closeDoc(xTextDoc); 89 } 90 91 /** 92 * Creating a Testenvironment for the interfaces to be tested. 93 * Creates an instance of the service 94 * <code>com.sun.star.text.ReferenceMark</code>, then sets new 95 * name of created ReferenceMark using <code>XNamed</code> interface. 96 * Finally, renamed ReferenceMark is inserted to a major text of text 97 * document as a text content. 98 */ 99 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 100 XInterface oObj = null; 101 XText oText = null; 102 String Name = "SwXReferenceMark"; 103 104 log.println( "creating a test environment" ); 105 oText = xTextDoc.getText(); 106 XMultiServiceFactory oDocMSF = (XMultiServiceFactory) 107 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 108 Object instance = null; 109 try { 110 oObj = (XInterface) oDocMSF.createInstance 111 ("com.sun.star.text.ReferenceMark"); 112 instance = (XInterface) oDocMSF.createInstance 113 ("com.sun.star.text.ReferenceMark"); 114 } catch ( com.sun.star.uno.Exception e ) { 115 e.printStackTrace( log ); 116 throw new StatusException( "Couldn't get ReferenceMark", e); 117 } 118 119 XNamed oObjN = (XNamed) UnoRuntime.queryInterface(XNamed.class, oObj); 120 oObjN.setName(Name); 121 XTextContent oObjTC = (XTextContent) 122 UnoRuntime.queryInterface(XTextContent.class, oObj); 123 124 XTextCursor oCursor = oText.createTextCursor(); 125 try { 126 oText.insertTextContent(oCursor, oObjTC, false); 127 } catch ( com.sun.star.lang.IllegalArgumentException e ){ 128 e.printStackTrace( log ); 129 throw new StatusException(" Couldn't insert ReferenceMark", e); 130 } 131 132 TestEnvironment tEnv = new TestEnvironment( oObj ); 133 134 tEnv.addObjRelation("CONTENT", (XTextContent) 135 UnoRuntime.queryInterface(XTextContent.class,instance)); 136 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor()); 137 138 return tEnv; 139 } // finish method getTestEnvironment 140 141 } // finish class SwXReferenceMark 142 143