1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXBookmarks.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XNameAccess
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.XBookmarksSupplier
;
44 import com
.sun
.star
.text
.XTextContent
;
45 import com
.sun
.star
.text
.XTextDocument
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.text.Bookmarks</code>. <p>
52 * Object implements the following interfaces :
54 * <li> <code>com::sun::star::container::XNameAccess</code></li>
55 * <li> <code>com::sun::star::container::XElementAccess</code></li>
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.XElementAccess
61 * @see ifc.container._XNameAccess
62 * @see ifc.container._XElementAccess
64 public class SwXBookmarks
extends TestCase
{
65 XTextDocument xTextDoc
;
69 * Creates text document.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
74 log
.println( "creating a textdocument" );
75 xTextDoc
= SOF
.createTextDoc( null );
76 } catch ( com
.sun
.star
.uno
.Exception e
) {
77 e
.printStackTrace( log
);
78 throw new StatusException( "Couldn't create document", e
);
83 * Disposes text document.
85 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
86 log
.println( " disposing xTextDoc " );
87 util
.DesktopTools
.closeDoc(xTextDoc
);
91 * Creating a Testenvironment for the interfaces to be tested. Method
92 * creates two bookmarks and inserts them to the text document. Then bookmarks
93 * are gotten from text document using <code>XBookmarksSupplier</code>
96 public synchronized TestEnvironment
createTestEnvironment(
97 TestParameters Param
, PrintWriter log
) throws StatusException
{
98 XInterface oObj
= null;
100 log
.println( "creating a test environment" );
102 oObj
= SOF
.createBookmark( xTextDoc
);
103 SOF
.insertTextContent( xTextDoc
, (XTextContent
) oObj
);
104 oObj
= SOF
.createBookmark( xTextDoc
);
105 SOF
.insertTextContent( xTextDoc
, (XTextContent
) oObj
);
106 } catch( com
.sun
.star
.uno
.Exception e
) {
107 e
.printStackTrace( log
);
108 throw new StatusException( "Couldn't create Bookmark", e
);
111 XBookmarksSupplier oBSupp
= (XBookmarksSupplier
)
112 UnoRuntime
.queryInterface(XBookmarksSupplier
.class, xTextDoc
);
113 XNameAccess oBookNA
= oBSupp
.getBookmarks();
115 log
.println( "creating a new environment for Bookmarks object" );
117 TestEnvironment tEnv
= new TestEnvironment( oObj
);
119 } // finish method getTestEnvironment
121 } // finish class SwXBookmarks