merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXCellRange.java
blobee6c76cea5267a7353d16d59ea476113336b3cea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXCellRange.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.table.XCellRange;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.text.XTextTable;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
48 /**
49 * Test for object which is represented by service
50 * <code>com.sun.star.table.CellRange</code>. <p>
51 * Object implements the following interfaces :
52 * <ul>
53 * <li> <code>com::sun::star::text::CellProperties</code></li>
54 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
55 * </ul> <p>
56 * This object test <b> is NOT </b> designed to be run in several
57 * threads concurently.
58 * @see com.sun.star.table.CellRange
59 * @see com.sun.star.text.CellProperties
60 * @see com.sun.star.beans.XPropertySet
61 * @see ifc.text._CellProperties
62 * @see ifc.beans._XPropertySet
64 public class SwXCellRange extends TestCase {
65 SOfficeFactory SOF;
66 XTextDocument xTextDoc;
68 /**
69 * Creates text document.
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
73 try {
74 log.println( "creating a textdocument" );
75 xTextDoc = SOF.createTextDoc( null );
76 } catch ( com.sun.star.uno.Exception e ) {
77 e.printStackTrace( log );
78 throw new StatusException( "Couldn't create document", e );
82 /**
83 * Disposes text document.
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing xTextDoc " );
87 util.DesktopTools.closeDoc(xTextDoc);
90 /**
91 * Creating a Testenvironment for the interfaces to be tested. At first
92 * method creates and initializes the table, then if text document has no
93 * tables, previously created table is inserted to text document. Finally,
94 * custom cell range is gotten from the table created.
95 * Object relations created :
96 * <ul>
97 * <li> <code>'CellProperties.TextSection'</code> for
98 * {@link ifc.text._CellProperties} : range of complete paragraphs
99 * within a text</li>
100 * </ul>
102 protected synchronized TestEnvironment createTestEnvironment
103 (TestParameters tParam, PrintWriter log) {
105 XTextTable the_table = null;
106 XInterface oObj = null;
107 try {
108 the_table = SOF.createTextTable( xTextDoc );
109 the_table.initialize(5, 5);
110 } catch ( com.sun.star.uno.Exception e ) {
111 e.printStackTrace( log );
112 throw new StatusException("Couldn't create testobj: "
113 +e.getMessage(),e);
116 if( SOF.getTableCollection( xTextDoc ).getCount() == 0 ) {
117 try {
118 SOF.insertTextContent(xTextDoc, the_table );
119 } catch( com.sun.star.uno.Exception e ) {
120 e.printStackTrace( log );
121 throw new StatusException("Couldn't create TextTable : "
122 + e.getMessage(), e);
125 try {
126 XCellRange the_Range = (XCellRange)
127 UnoRuntime.queryInterface(XCellRange.class, the_table);
128 oObj = the_Range.getCellRangeByPosition(0, 0, 3, 4);
129 } catch (com.sun.star.uno.Exception e) {
130 e.printStackTrace( log );
131 throw new StatusException("Couldn't get CellRange : "
132 + e.getMessage(), e);
135 log.println("Creating instance...");
136 TestEnvironment tEnv = new TestEnvironment( oObj );
137 log.println("ImplName: " + util.utils.getImplName(oObj));
139 XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
140 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
141 try {
142 XInterface oTS = (XInterface)
143 oDocMSF.createInstance("com.sun.star.text.TextSection");
144 log.println(" adding TextSection object");
145 tEnv.addObjRelation("CellProperties.TextSection", oTS);
146 } catch (com.sun.star.uno.Exception e) {
147 log.println("Could not get instance of TextSection");
148 e.printStackTrace(log);
151 Object[][] NewData = new Object[5][];
152 NewData[0] = new Double[]
153 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
154 NewData[1] = new Double[]
155 {new Double(4),new Double(9),new Double(2.5),new Double(5)};
156 NewData[2] = new Double[]
157 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
158 NewData[3] = new Double[]
159 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
160 NewData[4] = new Double[]
161 {new Double(4),new Double(9),new Double(2.5),new Double(5)};
162 tEnv.addObjRelation("NewData",NewData);
164 // com::sun::star::chart::XChartDataArray
165 tEnv.addObjRelation("CRDESC",
166 "Column and RowDescriptions can't be changed for this Object");
169 return tEnv;
171 } // finish class SwXCellRange