Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXReferenceMark.java
blob8b257ba13342f468fa1b803fa509f335c132a650
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.XText;
31 import com.sun.star.text.XTextContent;
32 import com.sun.star.text.XTextCursor;
33 import com.sun.star.text.XTextDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.text.ReferenceMark</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li> <code>com::sun::star::container::XNamed</code></li>
43 * <li> <code>com::sun::star::lang::XComponent</code></li>
44 * <li> <code>com::sun::star::text::XTextContent</code></li>
45 * </ul> <p>
46 * This object test <b> is NOT </b> designed to be run in several
47 * threads concurrently.
48 * @see com.sun.star.container.XNamed
49 * @see com.sun.star.lang.XComponent
50 * @see com.sun.star.text.XTextContent
51 * @see com.sun.star.text.ReferenceMark
52 * @see ifc.container._XNamed
53 * @see ifc.lang._XComponent
54 * @see ifc.text._XTextContent
56 public class SwXReferenceMark extends TestCase {
57 XTextDocument xTextDoc;
59 /**
60 * Creates text document.
62 @Override
63 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
64 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
65 log.println( "creating a textdocument" );
66 xTextDoc = SOF.createTextDoc( null );
69 /**
70 * Disposes text document.
72 @Override
73 protected void cleanup( TestParameters tParam, PrintWriter log ) {
74 log.println( " disposing xTextDoc " );
75 util.DesktopTools.closeDoc(xTextDoc);
78 /**
79 * Creating a TestEnvironment for the interfaces to be tested.
80 * Creates an instance of the service
81 * <code>com.sun.star.text.ReferenceMark</code>, then sets new
82 * name of created ReferenceMark using <code>XNamed</code> interface.
83 * Finally, renamed ReferenceMark is inserted to a major text of text
84 * document as a text content.
86 @Override
87 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception{
88 XInterface oObj = null;
89 XText oText = null;
90 String Name = "SwXReferenceMark";
92 log.println( "creating a test environment" );
93 oText = xTextDoc.getText();
94 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
95 Object instance = null;
96 oObj = (XInterface) oDocMSF.createInstance
97 ("com.sun.star.text.ReferenceMark");
98 instance = oDocMSF.createInstance
99 ("com.sun.star.text.ReferenceMark");
101 XNamed oObjN = UnoRuntime.queryInterface(XNamed.class, oObj);
102 oObjN.setName(Name);
103 XTextContent oObjTC = UnoRuntime.queryInterface(XTextContent.class, oObj);
105 XTextCursor oCursor = oText.createTextCursor();
106 oText.insertTextContent(oCursor, oObjTC, false);
108 TestEnvironment tEnv = new TestEnvironment( oObj );
110 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
111 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
113 return tEnv;
114 } // finish method getTestEnvironment
116 } // finish class SwXReferenceMark