bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXDocumentIndexMark.java
blob0bc8ce938378565316d2c7ec44c902c0a1177bdb
1 /*
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 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XDocumentIndexMark;
31 import com.sun.star.text.XText;
32 import com.sun.star.text.XTextContent;
33 import com.sun.star.text.XTextCursor;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.text.DocumentIndexMark</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::lang::XComponent</code></li>
44 * <li> <code>com::sun::star::text::BaseIndexMark</code></li>
45 * <li> <code>com::sun::star::text::XTextContent</code></li>
46 * <li> <code>com::sun::star::text::TextContent</code></li>
47 * <li> <code>com::sun::star::text::DocumentIndexMark</code></li>
48 * </ul> <p>
49 * This object test <b> is NOT </b> designed to be run in several
50 * threads concurently.
51 * @see com.sun.star.lang.XComponent
52 * @see com.sun.star.text.BaseIndexMark
53 * @see com.sun.star.text.XTextContent
54 * @see com.sun.star.text.TextContent
55 * @see com.sun.star.text.DocumentIndexMark
56 * @see ifc.lang._XComponent
57 * @see ifc.text._BaseIndexMark
58 * @see ifc.text._XTextContent
59 * @see ifc.text._TextContent
60 * @see ifc.text._DocumentIndexMark
62 public class SwXDocumentIndexMark extends TestCase {
63 XTextDocument xTextDoc;
65 /**
66 * Creates text document.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
70 try {
71 log.println( "creating a textdocument" );
72 xTextDoc = SOF.createTextDoc( null );
73 } catch ( com.sun.star.uno.Exception e ) {
74 e.printStackTrace( log );
75 throw new StatusException( "Couldn't create document", e );
79 /**
80 * Disposes text document.
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing xTextDoc " );
84 util.DesktopTools.closeDoc(xTextDoc);
88 /**
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.text.DocumentIndexMark</code>, attaches text to
92 * created DocumentIndexMark, and inserts DocumentIndexMark to the
93 * text document.
95 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
97 XText oText = xTextDoc.getText();
98 XTextCursor oCursor = oText.createTextCursor();
100 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
102 Object oDIM = null;
103 Object instance = null;
104 try {
105 oDIM = oDocMSF.createInstance
106 ("com.sun.star.text.DocumentIndexMark");
107 instance = oDocMSF.createInstance
108 ("com.sun.star.text.DocumentIndexMark");
109 } catch ( com.sun.star.uno.Exception e ) {
110 log.println("Error:" + e);
113 XDocumentIndexMark xDIM = UnoRuntime.queryInterface(XDocumentIndexMark.class, oDIM);
115 try {
116 oText.insertTextContent(oCursor, xDIM, false);
117 } catch (com.sun.star.lang.IllegalArgumentException e) {
118 e.printStackTrace(log);
119 throw new StatusException
120 ("Couldn't insert the DocumentIndexMark", e);
123 TestEnvironment tEnv = new TestEnvironment(xDIM);
125 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
126 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
128 return tEnv;
130 } // finish method getTestEnvironment
132 } // finish class SwXDocumentIndexMark