bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFootnote.java
blobc650a67d6d35bc1bafd1e4d663a84f5c930a214e
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.FrameDsc;
28 import util.InstCreator;
29 import util.SOfficeFactory;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XFootnote;
33 import com.sun.star.text.XText;
34 import com.sun.star.text.XTextContent;
35 import com.sun.star.text.XTextCursor;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.text.Footnote</code>. <p>
42 * Object implements the following interfaces :
43 * <ul>
44 * <li> <code>com::sun::star::text::XFootnote</code></li>
45 * <li> <code>com::sun::star::lang::XComponent</code></li>
46 * <li> <code>com::sun::star::text::XSimpleText</code></li>
47 * <li> <code>com::sun::star::text::Footnote</code></li>
48 * <li> <code>com::sun::star::text::XTextContent</code></li>
49 * <li> <code>com::sun::star::text::XTextRange</code></li>
50 * <li> <code>com::sun::star::text::XText</code></li>
51 * </ul> <p>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurently.
54 * @see com.sun.star.text.XFootnote
55 * @see com.sun.star.lang.XComponent
56 * @see com.sun.star.text.XSimpleText
57 * @see com.sun.star.text.Footnote
58 * @see com.sun.star.text.XTextContent
59 * @see com.sun.star.text.XTextRange
60 * @see com.sun.star.text.XText
61 * @see ifc.text._XFootnote
62 * @see ifc.lang._XComponent
63 * @see ifc.text._XSimpleText
64 * @see ifc.text._Footnote
65 * @see ifc.text._XTextContent
66 * @see ifc.text._XTextRange
67 * @see ifc.text._XText
69 public class SwXFootnote extends TestCase {
70 XTextDocument xTextDoc;
72 /**
73 * Creates text document.
75 protected void initialize( TestParameters tParam, PrintWriter log ) {
76 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
77 try {
78 log.println( "creating a textdocument" );
79 xTextDoc = SOF.createTextDoc( null );
80 } catch ( com.sun.star.uno.Exception e ) {
81 e.printStackTrace( log );
82 throw new StatusException( "Couldn't create document", e );
86 /**
87 * Disposes text document.
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println( " disposing xTextDoc " );
91 util.DesktopTools.closeDoc(xTextDoc);
94 /**
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates an instance of the service
97 * <code>com.sun.star.text.Footnote</code>. Then inserts created footnote
98 * to a text of document as content.
99 * Object relations created :
100 * <ul>
101 * <li><code>'XTEXTINFO'</code> for
102 * {@link ifc.text._XText} </li>
103 * </ul>
105 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
106 XFootnote oFootnote;
108 log.println( "Creating a test environment" );
109 // get a soffice factory object
110 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
111 log.println("creating a footnote");
112 Object instance = null;
113 try {
114 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
115 msf.createInstance("com.sun.star.text.Footnote"));
116 instance = msf.createInstance("com.sun.star.text.Footnote");
117 } catch (com.sun.star.uno.Exception e) {
118 e.printStackTrace(log);
119 throw new StatusException("Couldn't create footnote", e);
122 XText oText = xTextDoc.getText();
123 XTextCursor oCursor = oText.createTextCursor();
125 log.println("inserting the footnote into text document");
126 try {
127 oText.insertTextContent(oCursor, oFootnote, false);
128 } catch (com.sun.star.lang.IllegalArgumentException e) {
129 e.printStackTrace(log);
130 throw new StatusException("Couldn't insert the footnote", e);
133 TestEnvironment tEnv = new TestEnvironment(oFootnote);
135 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
136 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
138 log.println( "adding InstDescriptor object" );
139 FrameDsc tDsc = new FrameDsc( 3000, 6000 );
140 log.println( "adding InstCreator object" );
141 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
143 return tEnv;
146 } // finish class SwXFootnote