bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXDocumentIndexMark.java
blob03c52cc111aa55d035effa927f614945307f73b1
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 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
70 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
71 try {
72 log.println( "creating a textdocument" );
73 xTextDoc = SOF.createTextDoc( null );
74 } catch ( com.sun.star.uno.Exception e ) {
75 e.printStackTrace( log );
76 throw new StatusException( "Couldn't create document", e );
80 /**
81 * Disposes text document.
83 @Override
84 protected void cleanup( TestParameters tParam, PrintWriter log ) {
85 log.println( " disposing xTextDoc " );
86 util.DesktopTools.closeDoc(xTextDoc);
90 /**
91 * Creating a Testenvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.text.DocumentIndexMark</code>, attaches text to
94 * created DocumentIndexMark, and inserts DocumentIndexMark to the
95 * text document.
97 @Override
98 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
100 XText oText = xTextDoc.getText();
101 XTextCursor oCursor = oText.createTextCursor();
103 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
105 Object oDIM = null;
106 Object instance = null;
107 try {
108 oDIM = oDocMSF.createInstance
109 ("com.sun.star.text.DocumentIndexMark");
110 instance = oDocMSF.createInstance
111 ("com.sun.star.text.DocumentIndexMark");
112 } catch ( com.sun.star.uno.Exception e ) {
113 log.println("Error:" + e);
116 XDocumentIndexMark xDIM = UnoRuntime.queryInterface(XDocumentIndexMark.class, oDIM);
118 try {
119 oText.insertTextContent(oCursor, xDIM, false);
120 } catch (com.sun.star.lang.IllegalArgumentException e) {
121 e.printStackTrace(log);
122 throw new StatusException
123 ("Couldn't insert the DocumentIndexMark", e);
126 TestEnvironment tEnv = new TestEnvironment(xDIM);
128 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
129 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
131 return tEnv;
133 } // finish method getTestEnvironment
135 } // finish class SwXDocumentIndexMark