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: SwXReferenceMarks.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
.XNamed
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.XReferenceMarksSupplier
;
44 import com
.sun
.star
.text
.XText
;
45 import com
.sun
.star
.text
.XTextContent
;
46 import com
.sun
.star
.text
.XTextCursor
;
47 import com
.sun
.star
.text
.XTextDocument
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
52 * Test for object which is represented by service
53 * <code>com.sun.star.text.ReferenceMarks</code>. <p>
54 * Object implements the following interfaces :
56 * <li> <code>com::sun::star::container::XNameAccess</code></li>
57 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
58 * <li> <code>com::sun::star::container::XElementAccess</code></li>
60 * This object test <b> is NOT </b> designed to be run in several
61 * threads concurently.
62 * @see com.sun.star.container.XNameAccess
63 * @see com.sun.star.container.XIndexAccess
64 * @see com.sun.star.container.XElementAccess
65 * @see com.sun.star.text.ReferenceMarks
66 * @see ifc.container._XNameAccess
67 * @see ifc.container._XIndexAccess
68 * @see ifc.container._XElementAccess
70 public class SwXReferenceMarks
extends TestCase
{
71 XTextDocument xTextDoc
;
74 * Creates text document.
76 protected void initialize( TestParameters tParam
, PrintWriter log
) {
77 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
79 log
.println( "creating a textdocument" );
80 xTextDoc
= SOF
.createTextDoc( null );
81 } catch ( com
.sun
.star
.uno
.Exception e
) {
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
88 * Disposes text document.
90 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
91 log
.println( " disposing xTextDoc " );
92 util
.DesktopTools
.closeDoc(xTextDoc
);
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instances of the service
98 * <code>com.sun.star.text.ReferenceMark</code>, then sets new names to
99 * created ReferenceMark's using <code>XNamed</code> interface. Then renamed
100 * ReferenceMark's are inserted to a major text of text document. Finally,
101 * ReferenceMarks are gotten from text document using
102 * <code>XReferenceMarksSupplier</code> interface.
104 public synchronized TestEnvironment
createTestEnvironment(
105 TestParameters tParam
, PrintWriter log
) throws StatusException
{
106 XInterface oObj
= null;
108 String Name
= "SwXReferenceMark01";
109 String Name2
= "SwXReferenceMark02";
111 log
.println( "creating a test environment" );
112 oText
= xTextDoc
.getText();
114 XMultiServiceFactory oDocMSF
= (XMultiServiceFactory
)
115 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
117 // Creation and insertion of ReferenceMark01
120 oDocMSF
.createInstance( "com.sun.star.text.ReferenceMark" );
121 } catch ( com
.sun
.star
.uno
.Exception e
) {
122 e
.printStackTrace( log
);
123 throw new StatusException( "Couldn't get ReferenceMark", e
);
125 XNamed oObjN
= (XNamed
) UnoRuntime
.queryInterface(XNamed
.class, oObj
);
127 XTextContent oObjTC
= (XTextContent
)
128 UnoRuntime
.queryInterface(XTextContent
.class, oObj
);
129 XTextCursor oCursor
= oText
.createTextCursor();
131 oText
.insertTextContent(oCursor
, oObjTC
, false);
132 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
133 e
.printStackTrace( log
);
134 throw new StatusException(" Couldn't insert ReferenceMark01", e
);
137 // Creation and insertion of ReferenceMark02
140 oDocMSF
.createInstance( "com.sun.star.text.ReferenceMark" );
141 } catch ( com
.sun
.star
.uno
.Exception e
) {
142 e
.printStackTrace( log
);
143 throw new StatusException( "Couldn't get ReferenceMark", e
);
145 XNamed oObjN2
= (XNamed
) UnoRuntime
.queryInterface(XNamed
.class, oObj
);
146 oObjN2
.setName(Name2
);
148 XTextContent oObjTC2
= (XTextContent
)
149 UnoRuntime
.queryInterface(XTextContent
.class, oObj
);
151 oText
.insertTextContent(oCursor
, oObjTC2
, false);
152 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
153 e
.printStackTrace( log
);
154 throw new StatusException(" Couldn't insert ReferenceMark02", e
);
157 // getting ReferenceMarks from text document
158 XReferenceMarksSupplier oRefSupp
= (XReferenceMarksSupplier
)
159 UnoRuntime
.queryInterface(XReferenceMarksSupplier
.class, xTextDoc
);
160 oObj
= oRefSupp
.getReferenceMarks();
162 TestEnvironment tEnv
= new TestEnvironment( oObj
);
164 } // finish method getTestEnvironment
166 } // finish class SwXReferenceMarks