Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFootnoteText.java
blob45b0db7d174fd316a4494445ebe7bb29a6f5a967
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 @Override
80 protected void initialize( TestParameters tParam, PrintWriter log ) {
81 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
82 try {
83 log.println( "creating a textdocument" );
84 xTextDoc = SOF.createTextDoc( null );
85 } catch ( com.sun.star.uno.Exception e ) {
86 e.printStackTrace( log );
87 throw new StatusException( "Couldn't create document", e );
91 /**
92 * Disposes text document.
94 @Override
95 protected void cleanup( TestParameters tParam, PrintWriter log ) {
96 log.println( " disposing xTextDoc " );
97 util.DesktopTools.closeDoc(xTextDoc);
101 * Creating a Testenvironment for the interfaces to be tested.
102 * Creates an instance of the service
103 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote
104 * to the text, and finally sets a string to the footnote. Then the text
105 * gotten from the footnote is returned as tested component.<br>
106 * Object relations created :
107 * <ul>
108 * <li> <code>'TEXT'</code> for
109 * {@link ifc.text._XTextRangeCompare} : footnote text</li>
110 * <li> <code>'XTEXTINFO'</code> for
111 * {@link ifc.text._XRelativeTextContentInsert},
112 * {@link ifc.text._XText} : text section creator</li>
113 * <li> <code>'PARA'</code> for
114 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
115 * </ul>
117 @Override
118 public synchronized TestEnvironment createTestEnvironment(
119 TestParameters tParam, PrintWriter log ) throws StatusException {
120 XInterface oObj = null;
121 XFootnote oFootnote;
123 log.println( "creating a test environment" );
124 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
125 log.println("creating a footnote");
127 try {
128 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
129 msf.createInstance("com.sun.star.text.Footnote"));
130 } catch (com.sun.star.uno.Exception e) {
131 e.printStackTrace(log);
132 throw new StatusException("Couldn't create footnote", e);
135 XText oText = xTextDoc.getText();
136 XTextCursor oCursor = oText.createTextCursor();
138 log.println("inserting the footnote into text document");
139 try {
140 oText.insertTextContent(oCursor, oFootnote, false);
141 } catch (com.sun.star.lang.IllegalArgumentException e) {
142 e.printStackTrace(log);
143 throw new StatusException("Couldn't insert the footnote", e);
146 XSimpleText oFootText = UnoRuntime.queryInterface(XSimpleText.class, oFootnote);
147 oFootText.setString("SwXFootnoteText");
149 oObj = oFootText.getText();
151 TestEnvironment tEnv = new TestEnvironment(oObj);
153 log.println( "adding TextDocument as mod relation to environment" );
154 tEnv.addObjRelation("TEXT", oObj);
156 TextSectionDsc tDsc = new TextSectionDsc();
157 log.println( " adding InstCreator object" );
158 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
160 log.println( " adding Paragraph" );
161 ParagraphDsc pDsc = new ParagraphDsc();
162 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
164 return tEnv;
165 } // finish method getTestEnvironment
167 } // finish class SwXFootnoteText