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: SwXBookmark.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
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.text
.XTextContent
;
43 import com
.sun
.star
.text
.XTextDocument
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
48 * Test for object which is represented by service
49 * <code>com.sun.star.text.Bookmark</code>. <p>
50 * Object implements the following interfaces :
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 * <li> <code>com::sun::star::text::TextContent</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.XNamed
60 * @see com.sun.star.lang.XComponent
61 * @see com.sun.star.text.XTextContent
62 * @see com.sun.star.text.TextContent
63 * @see ifc.container._XNamed
64 * @see ifc.lang._XComponent
65 * @see ifc.text._XTextContent
66 * @see ifc.text._TextContent
68 public class SwXBookmark
extends TestCase
{
69 XTextDocument xTextDoc
;
73 * Creates text document.
75 protected void initialize( TestParameters tParam
, PrintWriter log
) {
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
78 log
.println( "creating a textdocument" );
79 xTextDoc
= SOF
.createTextDoc( null );
80 } catch ( com
.sun
.star
.uno
.Exception e
) {
81 e
.printStackTrace( log
);
82 throw new StatusException( "Couldn't create document", e
);
87 * Disposes text document.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xTextDoc " );
91 util
.DesktopTools
.closeDoc(xTextDoc
);
95 * Creating a Testenvironment for the interfaces to be tested. After creating
96 * a bookmark, it is inserted to the text document.
98 protected synchronized TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
99 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
100 XInterface oObj
= null;
101 Object instance
= null;
102 log
.println( "creating a test environment" );
104 oObj
= SOF
.createBookmark( xTextDoc
);
105 SOF
.insertTextContent( xTextDoc
, (XTextContent
) oObj
);
106 instance
= SOF
.createInstance(xTextDoc
,"com.sun.star.text.Bookmark");
107 } catch ( com
.sun
.star
.uno
.Exception e
) {
108 e
.printStackTrace( log
);
109 throw new StatusException( "Couldn't create Bookmark", e
);
111 log
.println( "creating a new environment for bodytext object" );
112 TestEnvironment tEnv
= new TestEnvironment( oObj
);
114 util
.dbg
.printInterfaces((XInterface
) instance
);
116 tEnv
.addObjRelation("CONTENT", (XTextContent
)
117 UnoRuntime
.queryInterface(XTextContent
.class,instance
));
118 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
120 } // finish method getTestEnvironment
123 } // finish class SwXBookmark