bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXReferenceMark.java
blobc345785dae87b81d87be209626d6864882e7d837
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.container.XNamed;
30 import com.sun.star.lang.XMultiServiceFactory;
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;
36 import com.sun.star.uno.XInterface;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.text.ReferenceMark</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::container::XNamed</code></li>
44 * <li> <code>com::sun::star::lang::XComponent</code></li>
45 * <li> <code>com::sun::star::text::XTextContent</code></li>
46 * </ul> <p>
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurently.
49 * @see com.sun.star.container.XNamed
50 * @see com.sun.star.lang.XComponent
51 * @see com.sun.star.text.XTextContent
52 * @see com.sun.star.text.ReferenceMark
53 * @see ifc.container._XNamed
54 * @see ifc.lang._XComponent
55 * @see ifc.text._XTextContent
57 public class SwXReferenceMark extends TestCase {
58 XTextDocument xTextDoc;
60 /**
61 * Creates text document.
63 protected void initialize( TestParameters tParam, PrintWriter log ) {
64 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
65 try {
66 log.println( "creating a textdocument" );
67 xTextDoc = SOF.createTextDoc( null );
68 } catch ( com.sun.star.uno.Exception e ) {
69 e.printStackTrace( log );
70 throw new StatusException( "Couldn't create document", e );
74 /**
75 * Disposes text document.
77 protected void cleanup( TestParameters tParam, PrintWriter log ) {
78 log.println( " disposing xTextDoc " );
79 util.DesktopTools.closeDoc(xTextDoc);
82 /**
83 * Creating a Testenvironment for the interfaces to be tested.
84 * Creates an instance of the service
85 * <code>com.sun.star.text.ReferenceMark</code>, then sets new
86 * name of created ReferenceMark using <code>XNamed</code> interface.
87 * Finally, renamed ReferenceMark is inserted to a major text of text
88 * document as a text content.
90 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
91 XInterface oObj = null;
92 XText oText = null;
93 String Name = "SwXReferenceMark";
95 log.println( "creating a test environment" );
96 oText = xTextDoc.getText();
97 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
98 Object instance = null;
99 try {
100 oObj = (XInterface) oDocMSF.createInstance
101 ("com.sun.star.text.ReferenceMark");
102 instance = oDocMSF.createInstance
103 ("com.sun.star.text.ReferenceMark");
104 } catch ( com.sun.star.uno.Exception e ) {
105 e.printStackTrace( log );
106 throw new StatusException( "Couldn't get ReferenceMark", e);
109 XNamed oObjN = UnoRuntime.queryInterface(XNamed.class, oObj);
110 oObjN.setName(Name);
111 XTextContent oObjTC = UnoRuntime.queryInterface(XTextContent.class, oObj);
113 XTextCursor oCursor = oText.createTextCursor();
114 try {
115 oText.insertTextContent(oCursor, oObjTC, false);
116 } catch ( com.sun.star.lang.IllegalArgumentException e ){
117 e.printStackTrace( log );
118 throw new StatusException(" Couldn't insert ReferenceMark", e);
121 TestEnvironment tEnv = new TestEnvironment( oObj );
123 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
124 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
126 return tEnv;
127 } // finish method getTestEnvironment
129 } // finish class SwXReferenceMark