bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTableCellText.java
blob700780ee1eac3ec7da7f33c38865c4b10bba18d1
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.table.XCell;
34 import com.sun.star.text.XSimpleText;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.text.XTextTable;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
41 * Test for object which is represented by cell text of the text table.<p>
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 SwXTableCellText extends TestCase {
73 XTextDocument xTextDoc;
74 SOfficeFactory SOF;
76 /**
77 * Creates text document.
79 protected void initialize( TestParameters tParam, PrintWriter log ) {
80 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. After creation
100 * of text table, it is inserted to a text document. Then cell named 'A1' is
101 * obtained from table, string 'SwXTableCellText' is set to this cell, then
102 * cell text is gotten from cell obtained before and returned as a test
103 * component.
104 * Object relations created :
105 * <ul>
106 * <li> <code>'TEXT'</code> for
107 * {@link ifc.text._XTextRangeCompare} : table cell text</li>
108 * <li> <code>'PARA'</code> for
109 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
110 * <li> <code>'XTEXTINFO'</code> for
111 * {@link ifc.text._XRelativeTextContentInsert},
112 * {@link ifc.text._XText} : creates text sections</li>
113 * </ul>
115 public synchronized TestEnvironment createTestEnvironment(
116 TestParameters Param, PrintWriter log ) throws StatusException {
117 XInterface oObj = null;
118 XTextTable oTable = null;
120 log.println( "Creating a test environment" );
121 try {
122 oTable = SOfficeFactory.createTextTable( xTextDoc );
123 } catch ( com.sun.star.uno.Exception e ) {
124 e.printStackTrace( log );
125 throw new StatusException("Couldn't create TextTable : "
126 +e.getMessage(),e);
129 try {
130 SOfficeFactory.insertTextContent(xTextDoc, oTable );
131 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
132 e.printStackTrace( log );
133 throw new StatusException("Couldn't insert text content : "
134 +e.getMessage(),e);
137 XCell oCell = oTable.getCellByName("A1");
138 XSimpleText oCellText = UnoRuntime.queryInterface(XSimpleText.class, oCell);
139 oCellText.setString("SwXTableCellText");
140 oObj = oCellText.getText();
142 log.println( "creating a new environment for Cell object" );
143 TestEnvironment tEnv = new TestEnvironment( oObj );
145 log.println( "adding TextDocument as mod relation to environment" );
146 tEnv.addObjRelation("TEXT", oObj);
148 log.println( " adding InstCreator object" );
149 TextSectionDsc tDsc = new TextSectionDsc();
150 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
152 log.println( " adding Paragraph" );
153 ParagraphDsc pDsc = new ParagraphDsc();
154 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
156 return tEnv;
157 } // finish method getTestEnvironment
160 } // finish class SwXTableCellText