Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXReferenceMarks.java
blob1c7ef0c20f15ad443cef3b839db9f0d9a262b9f9
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 @Override
65 protected void initialize( TestParameters tParam, PrintWriter log ) {
66 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
67 try {
68 log.println( "creating a textdocument" );
69 xTextDoc = SOF.createTextDoc( null );
70 } catch ( com.sun.star.uno.Exception e ) {
71 e.printStackTrace( log );
72 throw new StatusException( "Couldn't create document", e );
76 /**
77 * Disposes text document.
79 @Override
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xTextDoc " );
82 util.DesktopTools.closeDoc(xTextDoc);
85 /**
86 * Creating a Testenvironment for the interfaces to be tested.
87 * Creates an instances of the service
88 * <code>com.sun.star.text.ReferenceMark</code>, then sets new names to
89 * created ReferenceMark's using <code>XNamed</code> interface. Then renamed
90 * ReferenceMark's are inserted to a major text of text document. Finally,
91 * ReferenceMarks are gotten from text document using
92 * <code>XReferenceMarksSupplier</code> interface.
94 @Override
95 public synchronized TestEnvironment createTestEnvironment(
96 TestParameters tParam, PrintWriter log ) throws StatusException {
97 XInterface oObj = null;
98 XText oText = null;
99 String Name = "SwXReferenceMark01";
100 String Name2 = "SwXReferenceMark02";
102 log.println( "creating a test environment" );
103 oText = xTextDoc.getText();
105 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
107 // Creation and insertion of ReferenceMark01
108 try {
109 oObj = (XInterface)
110 oDocMSF.createInstance( "com.sun.star.text.ReferenceMark" );
111 } catch ( com.sun.star.uno.Exception e ) {
112 e.printStackTrace( log );
113 throw new StatusException( "Couldn't get ReferenceMark", e);
115 XNamed oObjN = UnoRuntime.queryInterface(XNamed.class, oObj);
116 oObjN.setName(Name);
117 XTextContent oObjTC = UnoRuntime.queryInterface(XTextContent.class, oObj);
118 XTextCursor oCursor = oText.createTextCursor();
119 try {
120 oText.insertTextContent(oCursor, oObjTC, false);
121 } catch ( com.sun.star.lang.IllegalArgumentException e ){
122 e.printStackTrace( log );
123 throw new StatusException(" Couldn't insert ReferenceMark01", e);
126 // Creation and insertion of ReferenceMark02
127 try {
128 oObj = (XInterface)
129 oDocMSF.createInstance( "com.sun.star.text.ReferenceMark" );
130 } catch ( com.sun.star.uno.Exception e ) {
131 e.printStackTrace( log );
132 throw new StatusException( "Couldn't get ReferenceMark", e);
134 XNamed oObjN2 = UnoRuntime.queryInterface(XNamed.class, oObj);
135 oObjN2.setName(Name2);
137 XTextContent oObjTC2 = UnoRuntime.queryInterface(XTextContent.class, oObj);
138 try {
139 oText.insertTextContent(oCursor, oObjTC2, false);
140 } catch ( com.sun.star.lang.IllegalArgumentException e ){
141 e.printStackTrace( log );
142 throw new StatusException(" Couldn't insert ReferenceMark02", e);
145 // getting ReferenceMarks from text document
146 XReferenceMarksSupplier oRefSupp = UnoRuntime.queryInterface(XReferenceMarksSupplier.class, xTextDoc);
147 oObj = oRefSupp.getReferenceMarks();
149 TestEnvironment tEnv = new TestEnvironment( oObj );
150 return tEnv;
151 } // finish method getTestEnvironment
153 } // finish class SwXReferenceMarks