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.XNameAccess; 39 import com.sun.star.lang.XMultiServiceFactory; 40 import com.sun.star.text.XBookmarksSupplier; 41 import com.sun.star.text.XTextContent; 42 import com.sun.star.text.XTextDocument; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 /** 47 * Test for object which is represented by service 48 * <code>com.sun.star.text.Bookmarks</code>. <p> 49 * Object implements the following interfaces : 50 * <ul> 51 * <li> <code>com::sun::star::container::XNameAccess</code></li> 52 * <li> <code>com::sun::star::container::XElementAccess</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.XNameAccess 57 * @see com.sun.star.container.XElementAccess 58 * @see ifc.container._XNameAccess 59 * @see ifc.container._XElementAccess 60 */ 61 public class SwXBookmarks extends TestCase { 62 XTextDocument xTextDoc; 63 SOfficeFactory SOF; 64 65 /** 66 * Creates text document. 67 */ 68 protected void initialize( TestParameters tParam, PrintWriter log ) { 69 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 70 try { 71 log.println( "creating a textdocument" ); 72 xTextDoc = SOF.createTextDoc( null ); 73 } catch ( com.sun.star.uno.Exception e ) { 74 e.printStackTrace( log ); 75 throw new StatusException( "Couldn't create document", e ); 76 } 77 } 78 79 /** 80 * Disposes text document. 81 */ 82 protected void cleanup( TestParameters tParam, PrintWriter log ) { 83 log.println( " disposing xTextDoc " ); 84 util.DesktopTools.closeDoc(xTextDoc); 85 } 86 87 /** 88 * Creating a Testenvironment for the interfaces to be tested. Method 89 * creates two bookmarks and inserts them to the text document. Then bookmarks 90 * are gotten from text document using <code>XBookmarksSupplier</code> 91 * interface. 92 */ 93 public synchronized TestEnvironment createTestEnvironment( 94 TestParameters Param, PrintWriter log ) throws StatusException { 95 XInterface oObj = null; 96 97 log.println( "creating a test environment" ); 98 try { 99 oObj = SOF.createBookmark( xTextDoc ); 100 SOF.insertTextContent( xTextDoc, (XTextContent) oObj ); 101 oObj = SOF.createBookmark( xTextDoc ); 102 SOF.insertTextContent( xTextDoc, (XTextContent) oObj ); 103 } catch( com.sun.star.uno.Exception e ) { 104 e.printStackTrace( log ); 105 throw new StatusException( "Couldn't create Bookmark", e ); 106 } 107 108 XBookmarksSupplier oBSupp = (XBookmarksSupplier) 109 UnoRuntime.queryInterface(XBookmarksSupplier.class, xTextDoc); 110 XNameAccess oBookNA = oBSupp.getBookmarks(); 111 oObj = oBookNA; 112 log.println( "creating a new environment for Bookmarks object" ); 113 114 TestEnvironment tEnv = new TestEnvironment( oObj ); 115 return tEnv; 116 } // finish method getTestEnvironment 117 118 } // finish class SwXBookmarks 119 120