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: SwXDocumentIndex.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
.XText
;
43 import com
.sun
.star
.text
.XTextContent
;
44 import com
.sun
.star
.text
.XTextCursor
;
45 import com
.sun
.star
.text
.XTextDocument
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.text.DocumentIndex</code>. <p>
52 * Object implements the following interfaces :
54 * <li> <code>com::sun::star::lang::XComponent</code></li>
55 * <li> <code>com::sun::star::text::XDocumentIndex</code></li>
56 * <li> <code>com::sun::star::text::BaseIndex</code></li>
57 * <li> <code>com::sun::star::text::XTextContent</code></li>
58 * <li> <code>com::sun::star::text::DocumentIndex</code></li>
60 * This object test <b> is NOT </b> designed to be run in several
61 * threads concurently.
62 * @see com.sun.star.lang.XComponent
63 * @see com.sun.star.text.XDocumentIndex
64 * @see com.sun.star.text.BaseIndex
65 * @see com.sun.star.text.XTextContent
66 * @see com.sun.star.text.DocumentIndex
67 * @see ifc.lang._XComponent
68 * @see ifc.text._XDocumentIndex
69 * @see ifc.text._BaseIndex
70 * @see ifc.text._XTextContent
71 * @see ifc.text._DocumentIndex
73 public class SwXDocumentIndex
extends TestCase
{
74 XTextDocument xTextDoc
;
77 * Creates text document.
79 protected void initialize( TestParameters tParam
, PrintWriter log
) {
80 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
82 log
.println( "creating a textdocument" );
83 xTextDoc
= SOF
.createTextDoc( null );
84 } catch ( com
.sun
.star
.uno
.Exception e
) {
85 e
.printStackTrace( log
);
86 throw new StatusException( "Couldn't create document", e
);
91 * Disposes text document.
93 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
94 log
.println( " disposing xTextDoc " );
95 util
.DesktopTools
.closeDoc(xTextDoc
);
99 * Creating a Testenvironment for the interfaces to be tested.
100 * Creates an instance of the service
101 * <code>com.sun.star.text.DocumentIndex</code>, then created document index
102 * is inserted to the text of the document as content.
105 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
106 XTextContent xTC
= null;
107 Object instance
= null;
109 SOfficeFactory SOF
= SOfficeFactory
.getFactory((XMultiServiceFactory
)tParam
.getMSF());
110 log
.println( "creating a test environment" );
112 xTC
= SOF
.createIndex(xTextDoc
, "com.sun.star.text.DocumentIndex");
113 instance
= SOF
.createIndex(xTextDoc
, "com.sun.star.text.DocumentIndex");
115 catch ( com
.sun
.star
.uno
.Exception e
) {
116 e
.printStackTrace(log
);
117 throw new StatusException("Couldn't create the Index", e
);
120 XText oText
= xTextDoc
.getText();
121 XTextCursor oCursor
= oText
.createTextCursor();
123 log
.println("inserting the Index into text document");
125 oText
.insertTextContent(oCursor
, xTC
, false);
126 } catch (com
.sun
.star
.uno
.Exception e
) {
127 e
.printStackTrace(log
);
128 throw new StatusException("Couldn't insert the Index", e
);
131 TestEnvironment tEnv
= new TestEnvironment(xTC
);
133 tEnv
.addObjRelation("CONTENT", (XTextContent
)
134 UnoRuntime
.queryInterface(XTextContent
.class,instance
));
136 // relation for XDocumentIndex
137 tEnv
.addObjRelation("TextDoc", xTextDoc
);
140 } // finish method getTestEnvironment
142 } // finish class SwXDocumentIndex