bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFootnoteText.java
blob6c1edcb810a7b27d5bfdeb844182cd01674b7c86
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.InstCreator;
28 import util.ParagraphDsc;
29 import util.SOfficeFactory;
30 import util.TextSectionDsc;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.XFootnote;
34 import com.sun.star.text.XSimpleText;
35 import com.sun.star.text.XText;
36 import com.sun.star.text.XTextCursor;
37 import com.sun.star.text.XTextDocument;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 /**
42 * Object implements the following interfaces :
43 * <ul>
44 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
45 * <li> <code>com::sun::star::text::XSimpleText</code></li>
46 * <li> <code>com::sun::star::text::XTextRange</code></li>
47 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
48 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
49 * <li> <code>com::sun::star::container::XElementAccess</code></li>
50 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
51 * <li> <code>com::sun::star::text::XText</code></li>
52 * </ul> <p>
53 * This object test <b> is NOT </b> designed to be run in several
54 * threads concurently.
55 * @see com.sun.star.text.XTextRangeMover
56 * @see com.sun.star.text.XSimpleText
57 * @see com.sun.star.text.XTextRange
58 * @see com.sun.star.text.XRelativeTextContentInsert
59 * @see com.sun.star.text.XTextRangeCompare
60 * @see com.sun.star.container.XElementAccess
61 * @see com.sun.star.container.XEnumerationAccess
62 * @see com.sun.star.text.XText
63 * @see ifc.text._XTextRangeMover
64 * @see ifc.text._XSimpleText
65 * @see ifc.text._XTextRange
66 * @see ifc.text._XRelativeTextContentInsert
67 * @see ifc.text._XTextRangeCompare
68 * @see ifc.container._XElementAccess
69 * @see ifc.container._XEnumerationAccess
70 * @see ifc.text._XText
72 public class SwXFootnoteText extends TestCase {
73 XTextDocument xTextDoc;
74 SOfficeFactory SOF;
76 /**
77 * Creates text document.
79 protected void initialize( TestParameters tParam, PrintWriter log ) {
80 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
81 try {
82 log.println( "creating a textdocument" );
83 xTextDoc = SOF.createTextDoc( null );
84 } catch ( com.sun.star.uno.Exception e ) {
85 e.printStackTrace( log );
86 throw new StatusException( "Couldn't create document", e );
90 /**
91 * Disposes text document.
93 protected void cleanup( TestParameters tParam, PrintWriter log ) {
94 log.println( " disposing xTextDoc " );
95 util.DesktopTools.closeDoc(xTextDoc);
98 /**
99 * Creating a Testenvironment for the interfaces to be tested.
100 * Creates an instance of the service
101 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote
102 * to the text, and finally sets a string to the footnote. Then the text
103 * gotten from the footnote is returned as tested component.<br>
104 * Object relations created :
105 * <ul>
106 * <li> <code>'TEXT'</code> for
107 * {@link ifc.text._XTextRangeCompare} : footnote text</li>
108 * <li> <code>'XTEXTINFO'</code> for
109 * {@link ifc.text._XRelativeTextContentInsert},
110 * {@link ifc.text._XText} : text section creator</li>
111 * <li> <code>'PARA'</code> for
112 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
113 * </ul>
115 public synchronized TestEnvironment createTestEnvironment(
116 TestParameters tParam, PrintWriter log ) throws StatusException {
117 XInterface oObj = null;
118 XFootnote oFootnote;
120 log.println( "creating a test environment" );
121 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
122 log.println("creating a footnote");
124 try {
125 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
126 msf.createInstance("com.sun.star.text.Footnote"));
127 } catch (com.sun.star.uno.Exception e) {
128 e.printStackTrace(log);
129 throw new StatusException("Couldn't create footnote", e);
132 XText oText = xTextDoc.getText();
133 XTextCursor oCursor = oText.createTextCursor();
135 log.println("inserting the footnote into text document");
136 try {
137 oText.insertTextContent(oCursor, oFootnote, false);
138 } catch (com.sun.star.lang.IllegalArgumentException e) {
139 e.printStackTrace(log);
140 throw new StatusException("Couldn't insert the footnote", e);
143 XSimpleText oFootText = UnoRuntime.queryInterface(XSimpleText.class, oFootnote);
144 oFootText.setString("SwXFootnoteText");
146 oObj = oFootText.getText();
148 TestEnvironment tEnv = new TestEnvironment(oObj);
150 log.println( "adding TextDocument as mod relation to environment" );
151 tEnv.addObjRelation("TEXT", oObj);
153 TextSectionDsc tDsc = new TextSectionDsc();
154 log.println( " adding InstCreator object" );
155 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
157 log.println( " adding Paragraph" );
158 ParagraphDsc pDsc = new ParagraphDsc();
159 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
161 return tEnv;
162 } // finish method getTestEnvironment
164 } // finish class SwXFootnoteText