1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScTableColumnObj.java,v $
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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XIndexAccess
;
42 import com
.sun
.star
.container
.XNameAccess
;
43 import com
.sun
.star
.lang
.XComponent
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.sheet
.XSpreadsheet
;
46 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
47 import com
.sun
.star
.sheet
.XSpreadsheets
;
48 import com
.sun
.star
.table
.XColumnRowRange
;
49 import com
.sun
.star
.table
.XTableColumns
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
56 * Test for object which is represented by service
57 * <code>com.sun.star.table.TableColumn</code>. <p>
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::container::XNamed</code></li>
61 * <li> <code>com::sun::star::table::TableColumn</code></li>
62 * <li> <code>com::sun::star::table::XCellRange</code></li>
63 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
65 * @see com.sun.star.container.XNamed
66 * @see com.sun.star.table.TableColumn
67 * @see com.sun.star.table.XCellRange
68 * @see com.sun.star.beans.XPropertySet
69 * @see ifc.container._XNamed
70 * @see ifc.table._TableColumn
71 * @see ifc.table._XCellRange
72 * @see ifc.beans._XPropertySet
74 public class ScTableColumnObj
extends TestCase
{
75 static XSpreadsheetDocument xSheetDoc
= null;
78 * Creates Spreadsheet document.
80 protected void initialize( TestParameters tParam
, PrintWriter log
) {
81 // get a soffice factory object
82 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
85 log
.println( "creating a sheetdocument" );
86 xSheetDoc
= SOF
.createCalcDoc(null);;
87 } catch (com
.sun
.star
.uno
.Exception e
) {
88 // Some exception occures.FAILED
89 e
.printStackTrace( log
);
90 throw new StatusException( "Couldn't create document", e
);
95 * Disposes Spreadsheet document.
97 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
98 log
.println( " disposing xSheetDoc " );
99 XComponent oComp
= (XComponent
)
100 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
101 util
.DesktopTools
.closeDoc(oComp
);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Retrieves a collection of spreadsheets from the document and takes one of
107 * them. Obtaines the collection of columns in the range using the interface
108 * <code>XColumnRowRange</code>. Retrieves the column with index 10 that is
109 * the instance of the service <code>com.sun.star.table.TableColumn</code>.
110 * Object relations created :
112 * <li> <code>'setName'</code> for
113 * {@link ifc.container._XNamed} </li>
114 * <li> <code>'ValidRange'</code> for
115 * {@link ifc.table._XCellRange} </li>
117 * @see com.sun.star.table.XColumnRowRange
118 * @see com.sun.star.table.TableColumn
120 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
122 XInterface oObj
= null;
124 // creation of the testobject here
125 // first we write what we are intend to do to log file
126 log
.println("creating a test environment");
128 XSpreadsheet xSpreadsheet
= null;
130 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSheetDoc
.getSheets();
131 XNameAccess oNames
= (XNameAccess
)
132 UnoRuntime
.queryInterface( XNameAccess
.class, xSpreadsheets
);
134 xSpreadsheet
= (XSpreadsheet
) AnyConverter
.toObject(
135 new Type(XSpreadsheet
.class),
136 oNames
.getByName(oNames
.getElementNames()[0]));
137 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
138 e
.printStackTrace(log
);
139 throw new StatusException("Couldn't get element by name", e
);
140 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
141 e
.printStackTrace(log
);
142 throw new StatusException("Couldn't get element by name", e
);
143 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
144 e
.printStackTrace(log
);
145 throw new StatusException("Couldn't get element by name", e
);
148 XColumnRowRange oColumnRowRange
= (XColumnRowRange
)
149 UnoRuntime
.queryInterface(XColumnRowRange
.class, xSpreadsheet
);
150 XTableColumns oColumns
= (XTableColumns
) oColumnRowRange
.getColumns();
151 XIndexAccess oIndexAccess
= (XIndexAccess
)
152 UnoRuntime
.queryInterface(XIndexAccess
.class, oColumns
);
154 oObj
= (XInterface
) AnyConverter
.toObject(
155 new Type(XInterface
.class),oIndexAccess
.getByIndex(10));
156 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
157 e
.printStackTrace(log
);
158 throw new StatusException("Couldn't get by index", e
);
159 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
160 e
.printStackTrace(log
);
161 throw new StatusException("Couldn't get by index", e
);
162 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
163 e
.printStackTrace(log
);
164 throw new StatusException("Couldn't get by index", e
);
167 log
.println("creating a new environment for object");
168 TestEnvironment tEnv
= new TestEnvironment(oObj
);
170 // a valid Range for XCellRange
171 tEnv
.addObjRelation("ValidRange","K1:K1");
173 //since TableColumnsNames are fixed XNamed::setName() should always be OK
174 tEnv
.addObjRelation("setName",new Boolean(true));