Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXReferenceMarks.java
blob40b99adeccc171bf46b26a209041b9e2a8dc216e
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.container.XNamed;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XReferenceMarksSupplier;
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.ReferenceMarks</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::container::XNameAccess</code></li>
44 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
45 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * </ul> <p>
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurrently.
49 * @see com.sun.star.container.XNameAccess
50 * @see com.sun.star.container.XIndexAccess
51 * @see com.sun.star.container.XElementAccess
52 * @see com.sun.star.text.ReferenceMarks
53 * @see ifc.container._XNameAccess
54 * @see ifc.container._XIndexAccess
55 * @see ifc.container._XElementAccess
57 public class SwXReferenceMarks extends TestCase {
58 XTextDocument xTextDoc;
60 /**
61 * Creates text document.
63 @Override
64 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
65 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
66 log.println( "creating a textdocument" );
67 xTextDoc = SOF.createTextDoc( null );
70 /**
71 * Disposes text document.
73 @Override
74 protected void cleanup( TestParameters tParam, PrintWriter log ) {
75 log.println( " disposing xTextDoc " );
76 util.DesktopTools.closeDoc(xTextDoc);
79 /**
80 * Creating a TestEnvironment for the interfaces to be tested.
81 * Creates an instances of the service
82 * <code>com.sun.star.text.ReferenceMark</code>, then sets new names to
83 * created ReferenceMark's using <code>XNamed</code> interface. Then renamed
84 * ReferenceMark's are inserted to a major text of text document. Finally,
85 * ReferenceMarks are gotten from text document using
86 * <code>XReferenceMarksSupplier</code> interface.
88 @Override
89 public TestEnvironment createTestEnvironment(
90 TestParameters tParam, PrintWriter log ) throws Exception {
91 XInterface oObj = null;
92 XText oText = null;
93 String Name = "SwXReferenceMark01";
94 String Name2 = "SwXReferenceMark02";
96 log.println( "creating a test environment" );
97 oText = xTextDoc.getText();
99 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
101 // Creation and insertion of ReferenceMark01
102 oObj = (XInterface)
103 oDocMSF.createInstance( "com.sun.star.text.ReferenceMark" );
104 XNamed oObjN = UnoRuntime.queryInterface(XNamed.class, oObj);
105 oObjN.setName(Name);
106 XTextContent oObjTC = UnoRuntime.queryInterface(XTextContent.class, oObj);
107 XTextCursor oCursor = oText.createTextCursor();
108 oText.insertTextContent(oCursor, oObjTC, false);
110 // Creation and insertion of ReferenceMark02
111 oObj = (XInterface)
112 oDocMSF.createInstance( "com.sun.star.text.ReferenceMark" );
113 XNamed oObjN2 = UnoRuntime.queryInterface(XNamed.class, oObj);
114 oObjN2.setName(Name2);
116 XTextContent oObjTC2 = UnoRuntime.queryInterface(XTextContent.class, oObj);
117 oText.insertTextContent(oCursor, oObjTC2, false);
119 // getting ReferenceMarks from text document
120 XReferenceMarksSupplier oRefSupp = UnoRuntime.queryInterface(XReferenceMarksSupplier.class, xTextDoc);
121 oObj = oRefSupp.getReferenceMarks();
123 TestEnvironment tEnv = new TestEnvironment( oObj );
124 return tEnv;
125 } // finish method getTestEnvironment
127 } // finish class SwXReferenceMarks