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: ScTableRowsObj.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
.XNameAccess
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XSpreadsheet
;
45 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
46 import com
.sun
.star
.sheet
.XSpreadsheets
;
47 import com
.sun
.star
.table
.XCellRange
;
48 import com
.sun
.star
.table
.XColumnRowRange
;
49 import com
.sun
.star
.table
.XTableRows
;
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.TableRows</code>. <p>
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
61 * <li> <code>com::sun::star::container::XElementAccess</code></li>
62 * <li> <code>com::sun::star::table::XTableRows</code></li>
64 * @see com.sun.star.table.TableRows
65 * @see com.sun.star.container.XIndexAccess
66 * @see com.sun.star.container.XElementAccess
67 * @see com.sun.star.table.XTableRows
68 * @see ifc.container._XIndexAccess
69 * @see ifc.container._XElementAccess
70 * @see ifc.table._XTableRows
72 public class ScTableRowsObj
extends TestCase
{
73 XSpreadsheetDocument xSheetDoc
= null;
76 * Creates Spreadsheet document.
78 protected void initialize( TestParameters tParam
, PrintWriter log
) {
79 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
82 log
.println( "creating a Spreadsheet document" );
83 xSheetDoc
= SOF
.createCalcDoc(null);
84 } catch ( com
.sun
.star
.uno
.Exception e
) {
85 // Some exception occures.FAILED
86 e
.printStackTrace( log
);
87 throw new StatusException( "Couldn't create document", e
);
92 * Disposes Spreadsheet document.
94 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
95 log
.println( " disposing xSheetDoc " );
96 XComponent oComp
= (XComponent
)
97 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
98 util
.DesktopTools
.closeDoc(oComp
);
102 * Creating a Testenvironment for the interfaces to be tested.
103 * Retrieves a collection of spreadsheets from the document and takes one of
104 * them. Obtains the collection of rows using the interface
105 * <code>XColumnRowRange</code>. The obtained collection is the instance of
106 * the service <code>com.sun.star.table.TableRows</code>.
107 * @see com.sun.star.table.XColumnRowRange
108 * @see com.sun.star.table.TableRows
110 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
112 XInterface oObj
= null;
114 log
.println("getting row");
115 XSpreadsheet xSpreadsheet
= null;
117 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSheetDoc
.getSheets();
118 XNameAccess oNames
= (XNameAccess
)
119 UnoRuntime
.queryInterface( XNameAccess
.class, xSpreadsheets
);
121 xSpreadsheet
= (XSpreadsheet
) AnyConverter
.toObject(
122 new Type(XSpreadsheet
.class),
123 oNames
.getByName(oNames
.getElementNames()[0]));
124 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException("Couldn't get spreadsheet", e
);
127 } catch(com
.sun
.star
.container
.NoSuchElementException e
) {
128 e
.printStackTrace(log
);
129 throw new StatusException("Couldn't get spreadsheet", e
);
130 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
131 e
.printStackTrace(log
);
132 throw new StatusException("Couldn't get spreadsheet", e
);
135 XColumnRowRange oColumnRowRange
= (XColumnRowRange
)
136 UnoRuntime
.queryInterface(XColumnRowRange
.class, xSpreadsheet
);
138 XTableRows oRows
= (XTableRows
) oColumnRowRange
.getRows();
141 log
.println("creating a new environment for object");
142 TestEnvironment tEnv
= new TestEnvironment(oObj
);
144 // adding relation for XTableRows
145 tEnv
.addObjRelation("XTableRows.XCellRange",
146 UnoRuntime
.queryInterface(XCellRange
.class, xSpreadsheet
));
150 } // finish class ScTableRowsObj