bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXCell.java
blob257c699aeccfb4ba8f58709d900b392437522368
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.lang.XMultiServiceFactory;
30 import com.sun.star.text.XTextContent;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
35 /**
36 * Test for object which is a cell of the table in a text document, and
37 * represented by service <code>com.sun.star.table.Cell</code><p>
38 * Object implements the following interfaces :
39 * <ul>
40 * <li> <code>com::sun::star::text::CellProperties</code></li>
41 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
42 * </ul> <p>
43 * This object test <b> is NOT </b> designed to be run in several
44 * threads concurently.
45 * @see com.sun.star.table.Cell
46 * @see com.sun.star.text.CellProperties
47 * @see com.sun.star.beans.XPropertySet
48 * @see ifc.text._CellProperties
49 * @see ifc.beans._XPropertySet
51 public class SwXCell extends TestCase {
52 XTextDocument xTextDoc;
54 /**
55 * Creates text document.
57 protected void initialize( TestParameters tParam, PrintWriter log ) {
58 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
59 try {
60 log.println( "creating a textdocument" );
61 xTextDoc = SOF.createTextDoc( null );
62 } catch ( com.sun.star.uno.Exception e ) {
63 e.printStackTrace( log );
64 throw new StatusException( "Couldn't create document", e );
68 /**
69 * Disposes text document.
71 protected void cleanup( TestParameters tParam, PrintWriter log ) {
72 log.println( " disposing xTextDoc " );
73 util.DesktopTools.closeDoc(xTextDoc);
76 /**
77 * Creating a Testenvironment for the interfaces to be tested. After creating
78 * a text table, it is inserted to the text document. Finally, first cell of
79 * this table is gotten.
80 * Object relations created :
81 * <ul>
82 * <li> <code>'CellProperties.TextSection'</code> for
83 * {@link ifc.text._CellProperties} : range of complete paragraphs
84 * within a text</li>
85 * </ul>
87 public TestEnvironment createTestEnvironment(
88 TestParameters tParam, PrintWriter log ) throws StatusException {
89 XInterface oObj = null;
90 XTextContent oTable = null;
92 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
93 log.println( "creating a test environment" );
94 try {
95 oTable = SOfficeFactory.createTextTable(xTextDoc, 3, 4);
96 } catch ( com.sun.star.uno.Exception e ) {
97 log.println("Unable to create TextTable...");
98 e.printStackTrace(log);
100 try {
101 SOfficeFactory.insertTextContent( xTextDoc, oTable );
102 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
103 log.println("Unable to insert TextContent...");
104 e.printStackTrace(log);
106 oObj = SOfficeFactory.getFirstTableCell( oTable );
108 log.println( " creating a new environment for bodytext object" );
109 TestEnvironment tEnv = new TestEnvironment( oObj );
111 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
112 try {
113 XInterface oTS = (XInterface) oDocMSF.createInstance
114 ("com.sun.star.text.TextSection");
115 log.println(" adding TextSection object");
116 tEnv.addObjRelation("CellProperties.TextSection", oTS);
117 } catch (com.sun.star.uno.Exception e) {
118 log.println("Could not get instance of TextSection");
119 e.printStackTrace(log);
122 return tEnv;
123 } // finish method getTestEnvironment
124 } // finish class SwXCell