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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.lang
.XComponent
;
30 import com
.sun
.star
.sheet
.XSpreadsheet
;
31 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
32 import com
.sun
.star
.sheet
.XSpreadsheets
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.sheet.Spreadsheets</code>. <p>
39 * Object implements the following interfaces :
41 * <li> <code>com::sun::star::sheet::XSpreadsheets</code></li>
42 * <li> <code>com::sun::star::container::XNameAccess</code></li>
43 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
44 * <li> <code>com::sun::star::container::XElementAccess</code></li>
45 * <li> <code>com::sun::star::container::XNameReplace</code></li>
46 * <li> <code>com::sun::star::container::XNameContainer</code></li>
48 * @see com.sun.star.sheet.Spreadsheets
49 * @see com.sun.star.sheet.XSpreadsheets
50 * @see com.sun.star.container.XNameAccess
51 * @see com.sun.star.container.XIndexAccess
52 * @see com.sun.star.container.XElementAccess
53 * @see com.sun.star.container.XNameReplace
54 * @see com.sun.star.container.XNameContainer
55 * @see ifc.sheet._XSpreadsheets
56 * @see ifc.container._XNameAccess
57 * @see ifc.container._XIndexAccess
58 * @see ifc.container._XElementAccess
59 * @see ifc.container._XNameReplace
60 * @see ifc.container._XNameContainer
62 public class ScTableSheetsObj
extends TestCase
{
63 private XSpreadsheetDocument xSpreadsheetDoc
= null;
66 * Creates Spreadsheet document.
69 public void initialize( TestParameters Param
, PrintWriter log
) {
70 // get a soffice factory object
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
74 log
.println("creating a spreadsheetdocument");
75 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
76 } catch (com
.sun
.star
.uno
.Exception e
) {
77 e
.printStackTrace( log
);
78 throw new StatusException( "Couldn't create document ", e
);
83 * Disposes Spreadsheet document.
86 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
87 log
.println("disposing xSpreadsheetDocument");
88 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSpreadsheetDoc
);
89 util
.DesktopTools
.closeDoc(oComp
);
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Retrieves the collection of the spreadsheets using the interface
95 * <code>XSpreadsheetDocument</code>. The retrieved collection is the
96 * instance of the service <code>com.sun.star.sheet.Spreadsheets</code>.
97 * Creates instances of the service <code>com.sun.star.sheet.Spreadsheet</code>.
98 * Object relations created :
100 * <li> <code>'SecondInstance'</code> for
101 * {@link ifc.container._XNameContainer} (the created instance of the
102 * service <code>com.sun.star.sheet.Spreadsheet</code>) </li>
103 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
104 * {@link ifc.container._XNameContainer} (the created instances of the
105 * service <code>com.sun.star.sheet.Spreadsheet</code>) </li>
107 * @see com.sun.star.sheet.Spreadsheets
108 * @see com.sun.star.sheet.XSpreadsheetDocument
109 * @see com.sun.star.sheet.Spreadsheet
112 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
114 SOfficeFactory
.getFactory( Param
.getMSF());
116 log
.println("getting sheets");
117 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
119 XInterface oObj
= UnoRuntime
.queryInterface(XInterface
.class, xSpreadsheets
);
121 log
.println("creating a new environment for object");
122 TestEnvironment tEnv
= new TestEnvironment(oObj
);
124 log
.println("creating instance of the sheet object to use it in tests");
125 XSpreadsheet oSecondSheet
= null;
128 oSecondSheet
= SOfficeFactory
.createSpreadsheet(xSpreadsheetDoc
);
129 } catch (com
.sun
.star
.uno
.Exception e
) {
130 e
.printStackTrace(log
);
131 throw new StatusException("Couldn't create instances", e
);
134 //adding Instance for XNameContainer
135 tEnv
.addObjRelation("SecondInstance",oSecondSheet
);
137 // INSTANCEn : _XNameContainer; _XNameReplace
138 log
.println( "adding INSTANCEn as mod relation to environment" );
141 if ((String
)Param
.get("THRCNT") != null) {
142 THRCNT
= Integer
.parseInt((String
)Param
.get("THRCNT"));
145 for (int n
= 1; n
< (THRCNT
+1) ;n
++ ) {
147 "adding INSTANCE" + n
+" as mod relation to environment" );
150 SOfficeFactory
.createSpreadsheet(xSpreadsheetDoc
) );
152 } catch (com
.sun
.star
.uno
.Exception e
) {
153 e
.printStackTrace(log
);
154 throw new StatusException(
155 "Couldn't create instances for object relations", e
);