bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXReferenceMarks.java
blob273ca44ceb3b16944c1fae2df64b0942f775cffb
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.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;
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.text.ReferenceMarks</code>. <p>
42 * Object implements the following interfaces :
43 * <ul>
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>
47 * </ul> <p>
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;
61 /**
62 * Creates text document.
64 protected void initialize( TestParameters tParam, PrintWriter log ) {
65 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
66 try {
67 log.println( "creating a textdocument" );
68 xTextDoc = SOF.createTextDoc( null );
69 } catch ( com.sun.star.uno.Exception e ) {
70 e.printStackTrace( log );
71 throw new StatusException( "Couldn't create document", e );
75 /**
76 * Disposes text document.
78 protected void cleanup( TestParameters tParam, PrintWriter log ) {
79 log.println( " disposing xTextDoc " );
80 util.DesktopTools.closeDoc(xTextDoc);
83 /**
84 * Creating a Testenvironment for the interfaces to be tested.
85 * Creates an instances of the service
86 * <code>com.sun.star.text.ReferenceMark</code>, then sets new names to
87 * created ReferenceMark's using <code>XNamed</code> interface. Then renamed
88 * ReferenceMark's are inserted to a major text of text document. Finally,
89 * ReferenceMarks are gotten from text document using
90 * <code>XReferenceMarksSupplier</code> interface.
92 public synchronized TestEnvironment createTestEnvironment(
93 TestParameters tParam, PrintWriter log ) throws StatusException {
94 XInterface oObj = null;
95 XText oText = null;
96 String Name = "SwXReferenceMark01";
97 String Name2 = "SwXReferenceMark02";
99 log.println( "creating a test environment" );
100 oText = xTextDoc.getText();
102 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
104 // Creation and insertion of ReferenceMark01
105 try {
106 oObj = (XInterface)
107 oDocMSF.createInstance( "com.sun.star.text.ReferenceMark" );
108 } catch ( com.sun.star.uno.Exception e ) {
109 e.printStackTrace( log );
110 throw new StatusException( "Couldn't get ReferenceMark", e);
112 XNamed oObjN = UnoRuntime.queryInterface(XNamed.class, oObj);
113 oObjN.setName(Name);
114 XTextContent oObjTC = UnoRuntime.queryInterface(XTextContent.class, oObj);
115 XTextCursor oCursor = oText.createTextCursor();
116 try {
117 oText.insertTextContent(oCursor, oObjTC, false);
118 } catch ( com.sun.star.lang.IllegalArgumentException e ){
119 e.printStackTrace( log );
120 throw new StatusException(" Couldn't insert ReferenceMark01", e);
123 // Creation and insertion of ReferenceMark02
124 try {
125 oObj = (XInterface)
126 oDocMSF.createInstance( "com.sun.star.text.ReferenceMark" );
127 } catch ( com.sun.star.uno.Exception e ) {
128 e.printStackTrace( log );
129 throw new StatusException( "Couldn't get ReferenceMark", e);
131 XNamed oObjN2 = UnoRuntime.queryInterface(XNamed.class, oObj);
132 oObjN2.setName(Name2);
134 XTextContent oObjTC2 = UnoRuntime.queryInterface(XTextContent.class, oObj);
135 try {
136 oText.insertTextContent(oCursor, oObjTC2, false);
137 } catch ( com.sun.star.lang.IllegalArgumentException e ){
138 e.printStackTrace( log );
139 throw new StatusException(" Couldn't insert ReferenceMark02", e);
142 // getting ReferenceMarks from text document
143 XReferenceMarksSupplier oRefSupp = UnoRuntime.queryInterface(XReferenceMarksSupplier.class, xTextDoc);
144 oObj = oRefSupp.getReferenceMarks();
146 TestEnvironment tEnv = new TestEnvironment( oObj );
147 return tEnv;
148 } // finish method getTestEnvironment
150 } // finish class SwXReferenceMarks