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: ScTableSheetsObj.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
.lang
.XComponent
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.sheet
.XSpreadsheet
;
44 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
45 import com
.sun
.star
.sheet
.XSpreadsheets
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.sheet.Spreadsheets</code>. <p>
52 * Object implements the following interfaces :
54 * <li> <code>com::sun::star::sheet::XSpreadsheets</code></li>
55 * <li> <code>com::sun::star::container::XNameAccess</code></li>
56 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
57 * <li> <code>com::sun::star::container::XElementAccess</code></li>
58 * <li> <code>com::sun::star::container::XNameReplace</code></li>
59 * <li> <code>com::sun::star::container::XNameContainer</code></li>
61 * @see com.sun.star.sheet.Spreadsheets
62 * @see com.sun.star.sheet.XSpreadsheets
63 * @see com.sun.star.container.XNameAccess
64 * @see com.sun.star.container.XIndexAccess
65 * @see com.sun.star.container.XElementAccess
66 * @see com.sun.star.container.XNameReplace
67 * @see com.sun.star.container.XNameContainer
68 * @see ifc.sheet._XSpreadsheets
69 * @see ifc.container._XNameAccess
70 * @see ifc.container._XIndexAccess
71 * @see ifc.container._XElementAccess
72 * @see ifc.container._XNameReplace
73 * @see ifc.container._XNameContainer
75 public class ScTableSheetsObj
extends TestCase
{
76 private static XSpreadsheetDocument xSpreadsheetDoc
= null;
79 * Creates Spreadsheet document.
81 public void initialize( TestParameters Param
, PrintWriter log
) {
82 // get a soffice factory object
84 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
86 log
.println("creating a spreadsheetdocument");
87 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
88 } catch (com
.sun
.star
.uno
.Exception e
) {
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 xSpreadsheetDocument");
99 XComponent oComp
= (XComponent
)
100 UnoRuntime
.queryInterface(XComponent
.class, xSpreadsheetDoc
);
101 util
.DesktopTools
.closeDoc(oComp
);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Retrieves the collection of the spreadsheets using the interface
107 * <code>XSpreadsheetDocument</code>. The retrieved collection is the
108 * instance of the service <code>com.sun.star.sheet.Spreadsheets</code>.
109 * Creates instances of the service <code>com.sun.star.sheet.Spreadsheet</code>.
110 * Object relations created :
112 * <li> <code>'SecondInstance'</code> for
113 * {@link ifc.container._XNameContainer} (the created instance of the
114 * service <code>com.sun.star.sheet.Spreadsheet</code>) </li>
115 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
116 * {@link ifc.container._XNameContainer} (the created instances of the
117 * service <code>com.sun.star.sheet.Spreadsheet</code>) </li>
119 * @see com.sun.star.sheet.Spreadsheets
120 * @see com.sun.star.sheet.XSpreadsheetDocument
121 * @see com.sun.star.sheet.Spreadsheet
123 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
125 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
127 log
.println("getting sheets");
128 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSpreadsheetDoc
.getSheets();
130 XInterface oObj
= (XInterface
)
131 UnoRuntime
.queryInterface(XInterface
.class, xSpreadsheets
);
133 log
.println("creating a new environment for object");
134 TestEnvironment tEnv
= new TestEnvironment(oObj
);
136 log
.println("creating instance of the sheet object to use it in tests");
137 XSpreadsheet oSecondSheet
= null;
140 oSecondSheet
= SOF
.createSpreadsheet(xSpreadsheetDoc
);
141 } catch (com
.sun
.star
.uno
.Exception e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException("Couldn't create instances", e
);
146 //adding Instance for XNameContainer
147 tEnv
.addObjRelation("SecondInstance",oSecondSheet
);
149 // INSTANCEn : _XNameContainer; _XNameReplace
150 log
.println( "adding INSTANCEn as mod relation to environment" );
153 if ((String
)Param
.get("THRCNT") != null) {
154 THRCNT
= Integer
.parseInt((String
)Param
.get("THRCNT"));
157 for (int n
= 1; n
< (THRCNT
+1) ;n
++ ) {
159 "adding INSTANCE" + n
+" as mod relation to environment" );
162 SOF
.createSpreadsheet(xSpreadsheetDoc
) );
164 } catch (com
.sun
.star
.uno
.Exception e
) {
165 e
.printStackTrace(log
);
166 throw new StatusException(
167 "Couldn't create instances for object relations", e
);