1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sc; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.beans.XPropertySet; 35 import com.sun.star.container.XIndexAccess; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.sheet.XSpreadsheet; 39 import com.sun.star.sheet.XSpreadsheetDocument; 40 import com.sun.star.sheet.XSpreadsheets; 41 import com.sun.star.uno.AnyConverter; 42 import com.sun.star.uno.Type; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 /** 47 * Test for object which is represented by service 48 * <code>com.sun.star.sheet.TableValidation</code>. <p> 49 * Object implements the following interfaces : 50 * <ul> 51 * <li> <code>com::sun::star::sheet::TableValidation</code></li> 52 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 53 * <li> <code>com::sun::star::sheet::XSheetCondition</code></li> 54 * </ul> 55 * @see com.sun.star.sheet.TableValidation 56 * @see com.sun.star.beans.XPropertySet 57 * @see com.sun.star.sheet.XSheetCondition 58 * @see ifc.sheet._TableValidation 59 * @see ifc.beans._XPropertySet 60 * @see ifc.sheet._XSheetCondition 61 */ 62 public class ScTableValidationObj extends TestCase { 63 static XSpreadsheetDocument xSpreadsheetDoc = null; 64 65 /** 66 * Creates Spreadsheet document. 67 */ 68 protected void initialize( TestParameters tParam, PrintWriter log ) { 69 // get a soffice factory object 70 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 71 72 try { 73 log.println( "creating a sheetdocument" ); 74 xSpreadsheetDoc = SOF.createCalcDoc(null); 75 } catch (com.sun.star.uno.Exception e ) { 76 // Some exception occures.FAILED 77 e.printStackTrace( log ); 78 throw new StatusException( "Couldn't create document", e ); 79 } 80 } 81 82 /** 83 * Disposes Spreadsheet document. 84 */ 85 protected void cleanup( TestParameters tParam, PrintWriter log ) { 86 log.println( " disposing xSheetDoc " ); 87 XComponent oComp = (XComponent) 88 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ; 89 util.DesktopTools.closeDoc(oComp); 90 } 91 92 /** 93 * Creating a Testenvironment for the interfaces to be tested. 94 * Retrieves a collection of spreadsheets from the document and takes one of 95 * them. Fills some cell in the spreadsheet. Obtains the property 96 * <code>'Validation'</code> of the spreadsheet. The value of the property 97 * is the instance of the service <code>com.sun.star.sheet.TableValidation</code>. 98 * @see com.sun.star.sheet.TableValidation 99 */ 100 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 101 102 XInterface oObj = null; 103 104 log.println("getting sheets"); 105 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets(); 106 107 log.println("getting a sheet"); 108 XSpreadsheet oSheet = null; 109 XIndexAccess oIndexAccess = (XIndexAccess) 110 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 111 try { 112 oSheet = (XSpreadsheet) AnyConverter.toObject( 113 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0)); 114 } catch (com.sun.star.lang.WrappedTargetException e) { 115 e.printStackTrace(log); 116 throw new StatusException( "Couldn't get a spreadsheet", e); 117 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 118 e.printStackTrace(log); 119 throw new StatusException( "Couldn't get a spreadsheet", e); 120 } catch (com.sun.star.lang.IllegalArgumentException e) { 121 e.printStackTrace(log); 122 throw new StatusException( "Couldn't get a spreadsheet", e); 123 } 124 125 log.println("filling some cells"); 126 try { 127 oSheet.getCellByPosition(5, 5).setValue(15); 128 oSheet.getCellByPosition(1, 4).setValue(10); 129 oSheet.getCellByPosition(2, 0).setValue(-5.15); 130 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 131 e.printStackTrace(log); 132 throw new StatusException( 133 "Exception occurred while filling cells", e); 134 } 135 136 XPropertySet Props = null; 137 138 try { 139 Props = (XPropertySet) 140 UnoRuntime.queryInterface(XPropertySet.class, oSheet); 141 oObj = (XInterface) AnyConverter.toObject( 142 new Type(XInterface.class),Props.getPropertyValue("Validation")); 143 } catch (com.sun.star.lang.WrappedTargetException e){ 144 e.printStackTrace(log); 145 throw new StatusException("Couldn't get property 'Validation'", e); 146 } catch (com.sun.star.beans.UnknownPropertyException e){ 147 e.printStackTrace(log); 148 throw new StatusException("Couldn't get property 'Validation'", e); 149 } catch (com.sun.star.lang.IllegalArgumentException e){ 150 e.printStackTrace(log); 151 throw new StatusException("Couldn't get property 'Validation'", e); 152 } 153 154 log.println("creating a new environment for object"); 155 TestEnvironment tEnv = new TestEnvironment(oObj); 156 157 return tEnv; 158 } // finish method getTestEnvironment 159 } // finish class ScTableValidationObj 160 161