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: SwXReferenceMark.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
.XText
;
44 import com
.sun
.star
.text
.XTextContent
;
45 import com
.sun
.star
.text
.XTextCursor
;
46 import com
.sun
.star
.text
.XTextDocument
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XInterface
;
51 * Test for object which is represented by service
52 * <code>com.sun.star.text.ReferenceMark</code>. <p>
53 * Object implements the following interfaces :
55 * <li> <code>com::sun::star::container::XNamed</code></li>
56 * <li> <code>com::sun::star::lang::XComponent</code></li>
57 * <li> <code>com::sun::star::text::XTextContent</code></li>
59 * This object test <b> is NOT </b> designed to be run in several
60 * threads concurently.
61 * @see com.sun.star.container.XNamed
62 * @see com.sun.star.lang.XComponent
63 * @see com.sun.star.text.XTextContent
64 * @see com.sun.star.text.ReferenceMark
65 * @see ifc.container._XNamed
66 * @see ifc.lang._XComponent
67 * @see ifc.text._XTextContent
69 public class SwXReferenceMark
extends TestCase
{
70 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.
96 * Creates an instance of the service
97 * <code>com.sun.star.text.ReferenceMark</code>, then sets new
98 * name of created ReferenceMark using <code>XNamed</code> interface.
99 * Finally, renamed ReferenceMark is inserted to a major text of text
100 * document as a text content.
102 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
103 XInterface oObj
= null;
105 String Name
= "SwXReferenceMark";
107 log
.println( "creating a test environment" );
108 oText
= xTextDoc
.getText();
109 XMultiServiceFactory oDocMSF
= (XMultiServiceFactory
)
110 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
111 Object instance
= null;
113 oObj
= (XInterface
) oDocMSF
.createInstance
114 ("com.sun.star.text.ReferenceMark");
115 instance
= (XInterface
) oDocMSF
.createInstance
116 ("com.sun.star.text.ReferenceMark");
117 } catch ( com
.sun
.star
.uno
.Exception e
) {
118 e
.printStackTrace( log
);
119 throw new StatusException( "Couldn't get ReferenceMark", e
);
122 XNamed oObjN
= (XNamed
) UnoRuntime
.queryInterface(XNamed
.class, oObj
);
124 XTextContent oObjTC
= (XTextContent
)
125 UnoRuntime
.queryInterface(XTextContent
.class, oObj
);
127 XTextCursor oCursor
= oText
.createTextCursor();
129 oText
.insertTextContent(oCursor
, oObjTC
, false);
130 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
131 e
.printStackTrace( log
);
132 throw new StatusException(" Couldn't insert ReferenceMark", e
);
135 TestEnvironment tEnv
= new TestEnvironment( oObj
);
137 tEnv
.addObjRelation("CONTENT", (XTextContent
)
138 UnoRuntime
.queryInterface(XTextContent
.class,instance
));
139 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
142 } // finish method getTestEnvironment
144 } // finish class SwXReferenceMark