bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableValidationObj.java
blob604ed259f3da2ab39090cb0d92cdbfdd345d88d6
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.beans.XPropertySet;
30 import com.sun.star.container.XIndexAccess;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.sheet.XSpreadsheet;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.sheet.XSpreadsheets;
36 import com.sun.star.uno.AnyConverter;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.sheet.TableValidation</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>com::sun::star::sheet::TableValidation</code></li>
47 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
48 * <li> <code>com::sun::star::sheet::XSheetCondition</code></li>
49 * </ul>
50 * @see com.sun.star.sheet.TableValidation
51 * @see com.sun.star.beans.XPropertySet
52 * @see com.sun.star.sheet.XSheetCondition
53 * @see ifc.sheet._TableValidation
54 * @see ifc.beans._XPropertySet
55 * @see ifc.sheet._XSheetCondition
57 public class ScTableValidationObj extends TestCase {
58 private XSpreadsheetDocument xSpreadsheetDoc = null;
60 /**
61 * Creates Spreadsheet document.
63 protected void initialize( TestParameters tParam, PrintWriter log ) {
64 // get a soffice factory object
65 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
67 try {
68 log.println( "creating a sheetdocument" );
69 xSpreadsheetDoc = SOF.createCalcDoc(null);
70 } catch (com.sun.star.uno.Exception e ) {
71 // Some exception occurs.FAILED
72 e.printStackTrace( log );
73 throw new StatusException( "Couldn't create document", e );
77 /**
78 * Disposes Spreadsheet document.
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xSheetDoc " );
82 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
83 util.DesktopTools.closeDoc(oComp);
86 /**
87 * Creating a Testenvironment for the interfaces to be tested.
88 * Retrieves a collection of spreadsheets from the document and takes one of
89 * them. Fills some cell in the spreadsheet. Obtains the property
90 * <code>'Validation'</code> of the spreadsheet. The value of the property
91 * is the instance of the service <code>com.sun.star.sheet.TableValidation</code>.
92 * @see com.sun.star.sheet.TableValidation
94 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
96 XInterface oObj = null;
98 log.println("getting sheets");
99 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
101 log.println("getting a sheet");
102 XSpreadsheet oSheet = null;
103 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
104 try {
105 oSheet = (XSpreadsheet) AnyConverter.toObject(
106 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
107 } catch (com.sun.star.lang.WrappedTargetException e) {
108 e.printStackTrace(log);
109 throw new StatusException( "Couldn't get a spreadsheet", e);
110 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
111 e.printStackTrace(log);
112 throw new StatusException( "Couldn't get a spreadsheet", e);
113 } catch (com.sun.star.lang.IllegalArgumentException e) {
114 e.printStackTrace(log);
115 throw new StatusException( "Couldn't get a spreadsheet", e);
118 log.println("filling some cells");
119 try {
120 oSheet.getCellByPosition(5, 5).setValue(15);
121 oSheet.getCellByPosition(1, 4).setValue(10);
122 oSheet.getCellByPosition(2, 0).setValue(-5.15);
123 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
124 e.printStackTrace(log);
125 throw new StatusException(
126 "Exception occurred while filling cells", e);
129 XPropertySet Props = null;
131 try {
132 Props = UnoRuntime.queryInterface(XPropertySet.class, oSheet);
133 oObj = (XInterface) AnyConverter.toObject(
134 new Type(XInterface.class),Props.getPropertyValue("Validation"));
135 } catch (com.sun.star.lang.WrappedTargetException e){
136 e.printStackTrace(log);
137 throw new StatusException("Couldn't get property 'Validation'", e);
138 } catch (com.sun.star.beans.UnknownPropertyException e){
139 e.printStackTrace(log);
140 throw new StatusException("Couldn't get property 'Validation'", e);
141 } catch (com.sun.star.lang.IllegalArgumentException e){
142 e.printStackTrace(log);
143 throw new StatusException("Couldn't get property 'Validation'", e);
146 log.println("creating a new environment for object");
147 TestEnvironment tEnv = new TestEnvironment(oObj);
149 return tEnv;
150 } // finish method getTestEnvironment
151 } // finish class ScTableValidationObj