Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXReferenceMark.java
blob1fc6a5a3b915b42d4694a7ee2e0a2023472850ad
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 @Override
64 protected void initialize( TestParameters tParam, PrintWriter log ) {
65 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
79 protected void cleanup( TestParameters tParam, PrintWriter log ) {
80 log.println( " disposing xTextDoc " );
81 util.DesktopTools.closeDoc(xTextDoc);
84 /**
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Creates an instance of the service
87 * <code>com.sun.star.text.ReferenceMark</code>, then sets new
88 * name of created ReferenceMark using <code>XNamed</code> interface.
89 * Finally, renamed ReferenceMark is inserted to a major text of text
90 * document as a text content.
92 @Override
93 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
94 XInterface oObj = null;
95 XText oText = null;
96 String Name = "SwXReferenceMark";
98 log.println( "creating a test environment" );
99 oText = xTextDoc.getText();
100 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
101 Object instance = null;
102 try {
103 oObj = (XInterface) oDocMSF.createInstance
104 ("com.sun.star.text.ReferenceMark");
105 instance = oDocMSF.createInstance
106 ("com.sun.star.text.ReferenceMark");
107 } catch ( com.sun.star.uno.Exception e ) {
108 e.printStackTrace( log );
109 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);
116 XTextCursor oCursor = oText.createTextCursor();
117 try {
118 oText.insertTextContent(oCursor, oObjTC, false);
119 } catch ( com.sun.star.lang.IllegalArgumentException e ){
120 e.printStackTrace( log );
121 throw new StatusException(" Couldn't insert ReferenceMark", e);
124 TestEnvironment tEnv = new TestEnvironment( oObj );
126 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
127 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
129 return tEnv;
130 } // finish method getTestEnvironment
132 } // finish class SwXReferenceMark