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.XTextContent; 40 import com.sun.star.text.XTextDocument; 41 import com.sun.star.uno.UnoRuntime; 42 import com.sun.star.uno.XInterface; 43 44 /** 45 * Test for object which is represented by service 46 * <code>com.sun.star.text.Bookmark</code>. <p> 47 * Object implements the following interfaces : 48 * <ul> 49 * <li> <code>com::sun::star::container::XNamed</code></li> 50 * <li> <code>com::sun::star::lang::XComponent</code></li> 51 * <li> <code>com::sun::star::text::XTextContent</code></li> 52 * <li> <code>com::sun::star::text::TextContent</code></li> 53 * </ul> <p> 54 * This object test <b> is NOT </b> designed to be run in several 55 * threads concurently. 56 * @see com.sun.star.container.XNamed 57 * @see com.sun.star.lang.XComponent 58 * @see com.sun.star.text.XTextContent 59 * @see com.sun.star.text.TextContent 60 * @see ifc.container._XNamed 61 * @see ifc.lang._XComponent 62 * @see ifc.text._XTextContent 63 * @see ifc.text._TextContent 64 */ 65 public class SwXBookmark extends TestCase { 66 XTextDocument xTextDoc; 67 SOfficeFactory SOF; 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. After creating 93 * a bookmark, it is inserted to the text document. 94 */ 95 protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 96 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 97 XInterface oObj = null; 98 Object instance = null; 99 log.println( "creating a test environment" ); 100 try { 101 oObj = SOF.createBookmark( xTextDoc ); 102 SOF.insertTextContent( xTextDoc, (XTextContent) oObj ); 103 instance = SOF.createInstance(xTextDoc,"com.sun.star.text.Bookmark"); 104 } catch ( com.sun.star.uno.Exception e ) { 105 e.printStackTrace( log ); 106 throw new StatusException( "Couldn't create Bookmark", e ); 107 } 108 log.println( "creating a new environment for bodytext object" ); 109 TestEnvironment tEnv = new TestEnvironment( oObj ); 110 111 util.dbg.printInterfaces((XInterface) instance); 112 113 tEnv.addObjRelation("CONTENT", (XTextContent) 114 UnoRuntime.queryInterface(XTextContent.class,instance)); 115 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor()); 116 return tEnv; 117 } // finish method getTestEnvironment 118 119 120 } // finish class SwXBookmark 121 122