Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScTableValidationObj.java
blob7e57706705ad7eec405b2beab7ce485f99e2bd52
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScTableValidationObj.java,v $
10 * $Revision: 1.8 $
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 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.container.XIndexAccess;
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.uno.AnyConverter;
49 import com.sun.star.uno.Type;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
53 /**
54 * Test for object which is represented by service
55 * <code>com.sun.star.sheet.TableValidation</code>. <p>
56 * Object implements the following interfaces :
57 * <ul>
58 * <li> <code>com::sun::star::sheet::TableValidation</code></li>
59 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
60 * <li> <code>com::sun::star::sheet::XSheetCondition</code></li>
61 * </ul>
62 * @see com.sun.star.sheet.TableValidation
63 * @see com.sun.star.beans.XPropertySet
64 * @see com.sun.star.sheet.XSheetCondition
65 * @see ifc.sheet._TableValidation
66 * @see ifc.beans._XPropertySet
67 * @see ifc.sheet._XSheetCondition
69 public class ScTableValidationObj extends TestCase {
70 static XSpreadsheetDocument xSpreadsheetDoc = null;
72 /**
73 * Creates Spreadsheet document.
75 protected void initialize( TestParameters tParam, PrintWriter log ) {
76 // get a soffice factory object
77 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
79 try {
80 log.println( "creating a sheetdocument" );
81 xSpreadsheetDoc = SOF.createCalcDoc(null);;
82 } catch (com.sun.star.uno.Exception e ) {
83 // Some exception occures.FAILED
84 e.printStackTrace( log );
85 throw new StatusException( "Couldn't create document", e );
89 /**
90 * Disposes Spreadsheet document.
92 protected void cleanup( TestParameters tParam, PrintWriter log ) {
93 log.println( " disposing xSheetDoc " );
94 XComponent oComp = (XComponent)
95 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
96 util.DesktopTools.closeDoc(oComp);
99 /**
100 * Creating a Testenvironment for the interfaces to be tested.
101 * Retrieves a collection of spreadsheets from the document and takes one of
102 * them. Fills some cell in the spreadsheet. Obtains the property
103 * <code>'Validation'</code> of the spreadsheet. The value of the property
104 * is the instance of the service <code>com.sun.star.sheet.TableValidation</code>.
105 * @see com.sun.star.sheet.TableValidation
107 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
109 XInterface oObj = null;
111 log.println("getting sheets");
112 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets();
114 log.println("getting a sheet");
115 XSpreadsheet oSheet = null;
116 XIndexAccess oIndexAccess = (XIndexAccess)
117 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
118 try {
119 oSheet = (XSpreadsheet) AnyConverter.toObject(
120 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
121 } catch (com.sun.star.lang.WrappedTargetException e) {
122 e.printStackTrace(log);
123 throw new StatusException( "Couldn't get a spreadsheet", e);
124 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
125 e.printStackTrace(log);
126 throw new StatusException( "Couldn't get a spreadsheet", e);
127 } catch (com.sun.star.lang.IllegalArgumentException e) {
128 e.printStackTrace(log);
129 throw new StatusException( "Couldn't get a spreadsheet", e);
132 log.println("filling some cells");
133 try {
134 oSheet.getCellByPosition(5, 5).setValue(15);
135 oSheet.getCellByPosition(1, 4).setValue(10);
136 oSheet.getCellByPosition(2, 0).setValue(-5.15);
137 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
138 e.printStackTrace(log);
139 throw new StatusException(
140 "Exception occurred while filling cells", e);
143 XPropertySet Props = null;
145 try {
146 Props = (XPropertySet)
147 UnoRuntime.queryInterface(XPropertySet.class, oSheet);
148 oObj = (XInterface) AnyConverter.toObject(
149 new Type(XInterface.class),Props.getPropertyValue("Validation"));
150 } catch (com.sun.star.lang.WrappedTargetException e){
151 e.printStackTrace(log);
152 throw new StatusException("Couldn't get property 'Validation'", e);
153 } catch (com.sun.star.beans.UnknownPropertyException e){
154 e.printStackTrace(log);
155 throw new StatusException("Couldn't get property 'Validation'", e);
156 } catch (com.sun.star.lang.IllegalArgumentException e){
157 e.printStackTrace(log);
158 throw new StatusException("Couldn't get property 'Validation'", e);
161 log.println("creating a new environment for object");
162 TestEnvironment tEnv = new TestEnvironment(oObj);
164 return tEnv;
165 } // finish method getTestEnvironment
166 } // finish class ScTableValidationObj