1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sc; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.container.XIndexAccess; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.sheet.XCellFormatRangesSupplier; 42 import com.sun.star.sheet.XSpreadsheet; 43 import com.sun.star.sheet.XSpreadsheetDocument; 44 import com.sun.star.sheet.XSpreadsheets; 45 import com.sun.star.uno.AnyConverter; 46 import com.sun.star.uno.Type; 47 import com.sun.star.uno.UnoRuntime; 48 import com.sun.star.uno.XInterface; 49 50 /** 51 * Test for object which is represented by service 52 * <code>com.sun.star.sheet.CellFormatRanges</code>. <p> 53 * Object implements the following interfaces : 54 * <ul> 55 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 56 * <li> <code>com::sun::star::container::XElementAccess</code></li> 57 * </ul> 58 * @see com.sun.star.sheet.CellFormatRanges 59 * @see com.sun.star.container.XEnumerationAccess 60 * @see com.sun.star.container.XElementAccess 61 * @see ifc.container._XEnumerationAccess 62 * @see ifc.container._XElementAccess 63 */ 64 public class ScCellFormatsObj extends TestCase { 65 static XSpreadsheetDocument xSheetDoc = null; 66 67 /** 68 * Creates Spreadsheet document. 69 */ 70 protected void initialize( TestParameters tParam, PrintWriter log ) { 71 // get a soffice factory object 72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 73 74 try { 75 log.println( "creating a sheetdocument" ); 76 xSheetDoc = SOF.createCalcDoc(null);; 77 } catch (com.sun.star.uno.Exception e) { 78 // Some exception occures.FAILED 79 e.printStackTrace( log ); 80 throw new StatusException( "Couldn't create document", e ); 81 } 82 } 83 84 /** 85 * Disposes Spreadsheet document. 86 */ 87 protected void cleanup( TestParameters tParam, PrintWriter log ) { 88 log.println( " disposing xSheetDoc " ); 89 XComponent oComp = (XComponent) 90 UnoRuntime.queryInterface (XComponent.class, xSheetDoc); 91 util.DesktopTools.closeDoc(oComp); 92 } 93 94 /** 95 * Creating a Testenvironment for the interfaces to be tested. 96 * Retrieves a collection of spreadsheets from a document, 97 * and takes one of them. Then retrieves a collection of format cell 98 * range using the interface <code>XCellFormatRangesSupplier</code> that is 99 * instance of service <code>com.sun.star.sheet.CellFormatRanges</code>. 100 * @see com.sun.star.sheet.CellFormatRanges 101 * @see com.sun.star.sheet.XCellFormatRangesSupplier 102 */ 103 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 104 105 XInterface oObj = null; 106 107 log.println("getting sheets"); 108 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 109 110 log.println("getting a sheet"); 111 XSpreadsheet oSheet = null; 112 XIndexAccess oIndexAccess = (XIndexAccess) 113 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 114 try { 115 oSheet = (XSpreadsheet) AnyConverter.toObject( 116 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0)); 117 } catch (com.sun.star.lang.WrappedTargetException e) { 118 e.printStackTrace(log); 119 throw new StatusException( "Couldn't get a spreadsheet", e); 120 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 121 e.printStackTrace(log); 122 throw new StatusException( "Couldn't get a spreadsheet", e); 123 } catch (com.sun.star.lang.IllegalArgumentException e) { 124 e.printStackTrace(log); 125 throw new StatusException( "Couldn't get a spreadsheet", e); 126 } 127 128 log.println("getting CellFormats"); 129 XCellFormatRangesSupplier xCFRS = (XCellFormatRangesSupplier) 130 UnoRuntime.queryInterface(XCellFormatRangesSupplier.class, oSheet); 131 XIndexAccess formats = xCFRS.getCellFormatRanges(); 132 133 oObj = formats; 134 135 log.println("creating a new environment for object"); 136 TestEnvironment tEnv = new TestEnvironment(oObj); 137 138 return tEnv; 139 } 140 } // finish class ScCellFormatsObj 141 142