bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableSheetsObj.java
blob5cf9a0a3d5e6f6fe065d8bfe4ae39462c9b44f1e
1 /*
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.lang.XComponent;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.sheet.XSpreadsheet;
32 import com.sun.star.sheet.XSpreadsheetDocument;
33 import com.sun.star.sheet.XSpreadsheets;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.sheet.Spreadsheets</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li> <code>com::sun::star::sheet::XSpreadsheets</code></li>
43 * <li> <code>com::sun::star::container::XNameAccess</code></li>
44 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
45 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * <li> <code>com::sun::star::container::XNameReplace</code></li>
47 * <li> <code>com::sun::star::container::XNameContainer</code></li>
48 * </ul>
49 * @see com.sun.star.sheet.Spreadsheets
50 * @see com.sun.star.sheet.XSpreadsheets
51 * @see com.sun.star.container.XNameAccess
52 * @see com.sun.star.container.XIndexAccess
53 * @see com.sun.star.container.XElementAccess
54 * @see com.sun.star.container.XNameReplace
55 * @see com.sun.star.container.XNameContainer
56 * @see ifc.sheet._XSpreadsheets
57 * @see ifc.container._XNameAccess
58 * @see ifc.container._XIndexAccess
59 * @see ifc.container._XElementAccess
60 * @see ifc.container._XNameReplace
61 * @see ifc.container._XNameContainer
63 public class ScTableSheetsObj extends TestCase {
64 private XSpreadsheetDocument xSpreadsheetDoc = null;
66 /**
67 * Creates Spreadsheet document.
69 public void initialize( TestParameters Param, PrintWriter log ) {
70 // get a soffice factory object
72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
73 try {
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 );
82 /**
83 * Disposes Spreadsheet document.
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println("disposing xSpreadsheetDocument");
87 XComponent oComp = UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc);
88 util.DesktopTools.closeDoc(oComp);
91 /**
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Retrieves the collection of the spreadsheets using the interface
94 * <code>XSpreadsheetDocument</code>. The retrieved collection is the
95 * instance of the service <code>com.sun.star.sheet.Spreadsheets</code>.
96 * Creates instances of the service <code>com.sun.star.sheet.Spreadsheet</code>.
97 * Object relations created :
98 * <ul>
99 * <li> <code>'SecondInstance'</code> for
100 * {@link ifc.container._XNameContainer} (the created instance of the
101 * service <code>com.sun.star.sheet.Spreadsheet</code>) </li>
102 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
103 * {@link ifc.container._XNameContainer} (the created instances of the
104 * service <code>com.sun.star.sheet.Spreadsheet</code>) </li>
105 * </ul>
106 * @see com.sun.star.sheet.Spreadsheets
107 * @see com.sun.star.sheet.XSpreadsheetDocument
108 * @see com.sun.star.sheet.Spreadsheet
110 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
112 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
114 log.println("getting sheets");
115 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
117 XInterface oObj = UnoRuntime.queryInterface(XInterface.class, xSpreadsheets);
119 log.println("creating a new environment for object");
120 TestEnvironment tEnv = new TestEnvironment(oObj);
122 log.println("creating instance of the sheet object to use it in tests");
123 XSpreadsheet oSecondSheet = null;
125 try {
126 oSecondSheet = SOfficeFactory.createSpreadsheet(xSpreadsheetDoc);
127 } catch (com.sun.star.uno.Exception e) {
128 e.printStackTrace(log);
129 throw new StatusException("Couldn't create instances", e);
132 //adding Instance for XNameContainer
133 tEnv.addObjRelation("SecondInstance",oSecondSheet);
135 // INSTANCEn : _XNameContainer; _XNameReplace
136 log.println( "adding INSTANCEn as mod relation to environment" );
138 int THRCNT = 1;
139 if ((String)Param.get("THRCNT") != null) {
140 THRCNT = Integer.parseInt((String)Param.get("THRCNT"));
142 try {
143 for (int n = 1; n < (THRCNT+1) ;n++ ) {
144 log.println(
145 "adding INSTANCE" + n +" as mod relation to environment" );
146 tEnv.addObjRelation(
147 "INSTANCE" + n,
148 SOfficeFactory.createSpreadsheet(xSpreadsheetDoc) );
150 } catch (com.sun.star.uno.Exception e) {
151 e.printStackTrace(log);
152 throw new StatusException(
153 "Couldn't create instances for object relations", e);
156 return tEnv;