2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XNamed
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.text
.XReferenceMarksSupplier
;
32 import com
.sun
.star
.text
.XText
;
33 import com
.sun
.star
.text
.XTextContent
;
34 import com
.sun
.star
.text
.XTextCursor
;
35 import com
.sun
.star
.text
.XTextDocument
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
40 * Test for object which is represented by service
41 * <code>com.sun.star.text.ReferenceMarks</code>. <p>
42 * Object implements the following interfaces :
44 * <li> <code>com::sun::star::container::XNameAccess</code></li>
45 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
46 * <li> <code>com::sun::star::container::XElementAccess</code></li>
48 * This object test <b> is NOT </b> designed to be run in several
49 * threads concurently.
50 * @see com.sun.star.container.XNameAccess
51 * @see com.sun.star.container.XIndexAccess
52 * @see com.sun.star.container.XElementAccess
53 * @see com.sun.star.text.ReferenceMarks
54 * @see ifc.container._XNameAccess
55 * @see ifc.container._XIndexAccess
56 * @see ifc.container._XElementAccess
58 public class SwXReferenceMarks
extends TestCase
{
59 XTextDocument xTextDoc
;
62 * Creates text document.
65 protected void initialize( TestParameters tParam
, PrintWriter log
) {
66 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
68 log
.println( "creating a textdocument" );
69 xTextDoc
= SOF
.createTextDoc( null );
70 } catch ( com
.sun
.star
.uno
.Exception e
) {
71 e
.printStackTrace( log
);
72 throw new StatusException( "Couldn't create document", e
);
77 * Disposes text document.
80 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
81 log
.println( " disposing xTextDoc " );
82 util
.DesktopTools
.closeDoc(xTextDoc
);
86 * Creating a Testenvironment for the interfaces to be tested.
87 * Creates an instances of the service
88 * <code>com.sun.star.text.ReferenceMark</code>, then sets new names to
89 * created ReferenceMark's using <code>XNamed</code> interface. Then renamed
90 * ReferenceMark's are inserted to a major text of text document. Finally,
91 * ReferenceMarks are gotten from text document using
92 * <code>XReferenceMarksSupplier</code> interface.
95 public synchronized TestEnvironment
createTestEnvironment(
96 TestParameters tParam
, PrintWriter log
) throws StatusException
{
97 XInterface oObj
= null;
99 String Name
= "SwXReferenceMark01";
100 String Name2
= "SwXReferenceMark02";
102 log
.println( "creating a test environment" );
103 oText
= xTextDoc
.getText();
105 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
107 // Creation and insertion of ReferenceMark01
110 oDocMSF
.createInstance( "com.sun.star.text.ReferenceMark" );
111 } catch ( com
.sun
.star
.uno
.Exception e
) {
112 e
.printStackTrace( log
);
113 throw new StatusException( "Couldn't get ReferenceMark", e
);
115 XNamed oObjN
= UnoRuntime
.queryInterface(XNamed
.class, oObj
);
117 XTextContent oObjTC
= UnoRuntime
.queryInterface(XTextContent
.class, oObj
);
118 XTextCursor oCursor
= oText
.createTextCursor();
120 oText
.insertTextContent(oCursor
, oObjTC
, false);
121 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
122 e
.printStackTrace( log
);
123 throw new StatusException(" Couldn't insert ReferenceMark01", e
);
126 // Creation and insertion of ReferenceMark02
129 oDocMSF
.createInstance( "com.sun.star.text.ReferenceMark" );
130 } catch ( com
.sun
.star
.uno
.Exception e
) {
131 e
.printStackTrace( log
);
132 throw new StatusException( "Couldn't get ReferenceMark", e
);
134 XNamed oObjN2
= UnoRuntime
.queryInterface(XNamed
.class, oObj
);
135 oObjN2
.setName(Name2
);
137 XTextContent oObjTC2
= UnoRuntime
.queryInterface(XTextContent
.class, oObj
);
139 oText
.insertTextContent(oCursor
, oObjTC2
, false);
140 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
141 e
.printStackTrace( log
);
142 throw new StatusException(" Couldn't insert ReferenceMark02", e
);
145 // getting ReferenceMarks from text document
146 XReferenceMarksSupplier oRefSupp
= UnoRuntime
.queryInterface(XReferenceMarksSupplier
.class, xTextDoc
);
147 oObj
= oRefSupp
.getReferenceMarks();
149 TestEnvironment tEnv
= new TestEnvironment( oObj
);
151 } // finish method getTestEnvironment
153 } // finish class SwXReferenceMarks