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.container.XIndexAccess; 35 import com.sun.star.lang.XComponent; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.sheet.XSpreadsheetDocument; 38 import com.sun.star.sheet.XSpreadsheets; 39 import com.sun.star.uno.UnoRuntime; 40 import com.sun.star.uno.XInterface; 41 import com.sun.star.util.XSortable; 42 43 44 /** 45 * 46 * initial description 47 * @see com.sun.star.beans.XPropertySet 48 * @see com.sun.star.sheet.SheetSortDescriptor 49 * 50 */ 51 public class ScSortDescriptorBase extends TestCase { 52 53 static XSpreadsheetDocument xSpreadsheetDoc; 54 55 /** 56 * in general this method creates a testdocument 57 * 58 * @param tParam class which contains additional test parameters 59 * @param log class to log the test state and result 60 * 61 * 62 * @see TestParameters 63 * @see PrintWriter 64 * 65 */ initialize( TestParameters tParam, PrintWriter log )66 protected void initialize( TestParameters tParam, PrintWriter log ) { 67 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() ); 68 69 try { 70 log.println( "creating a Spreadsheet document" ); 71 xSpreadsheetDoc = SOF.createCalcDoc(null); 72 } catch ( com.sun.star.uno.Exception e ) { 73 // Some exception occures.FAILED 74 e.printStackTrace( log ); 75 throw new StatusException( "Couldn't create document", e ); 76 } 77 78 } 79 80 /** 81 * in general this method disposes the testenvironment and document 82 * 83 * @param tParam class which contains additional test parameters 84 * @param log class to log the test state and result 85 * 86 * 87 * @see TestParameters 88 * @see PrintWriter 89 * 90 */ cleanup( TestParameters tParam, PrintWriter log )91 protected void cleanup( TestParameters tParam, PrintWriter log ) { 92 log.println( " disposing xSheetDoc " ); 93 XComponent oComp = (XComponent) UnoRuntime.queryInterface 94 (XComponent.class, xSpreadsheetDoc) ; 95 util.DesktopTools.closeDoc(oComp); 96 } 97 98 99 100 /** 101 * creating a Testenvironment for the interfaces to be tested 102 * 103 * @param tParam class which contains additional test parameters 104 * @param log class to log the test state and result 105 * 106 * @return Status class 107 * 108 * @see TestParameters 109 * @see PrintWriter 110 */ createTestEnvironment( TestParameters tParam, PrintWriter log )111 public TestEnvironment createTestEnvironment( TestParameters tParam, 112 PrintWriter log ) 113 throws StatusException { 114 115 XInterface oObj = null; 116 XSortable xSORT = null; 117 118 // creation of testobject here 119 // first we write what we are intend to do to log file 120 log.println( "creating a test environment" ); 121 122 // create testobject here 123 124 log.println("getting sheets"); 125 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets(); 126 if (xSpreadsheets == null) log.println("FAILED"); else log.println("OK"); 127 128 log.println("getting a sheet"); 129 XIndexAccess oIndexAccess = (XIndexAccess) 130 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 131 132 try { 133 oObj = (XInterface) UnoRuntime.queryInterface(XInterface.class,oIndexAccess.getByIndex(0)); 134 } catch (Exception e) { 135 throw new StatusException( "Couldn't get a spreadsheet", e); 136 } 137 138 xSORT = (XSortable) UnoRuntime.queryInterface(XSortable.class,oObj); 139 140 TestEnvironment tEnv = new TestEnvironment(oObj); 141 tEnv.addObjRelation("xSORT",xSORT); 142 return tEnv; 143 144 } // finish method getTestEnvironment 145 146 } // finish class ScSortDescriptorBase 147 148