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