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 37 import com.sun.star.container.XIndexAccess; 38 import com.sun.star.container.XNamed; 39 import com.sun.star.lang.XMultiServiceFactory; 40 import com.sun.star.uno.AnyConverter; 41 import com.sun.star.uno.Type; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 45 /** 46 * Test for object which is represented by service 47 * <code>com.sun.star.sheet.TableAutoFormat</code>. <p> 48 * In StarCalc application there is a collection of autoformats 49 * for tables (you can select a predefined format for a 50 * table or create your own). This object represents 51 * one of these autoformats. <p> 52 * Object implements the following interfaces : 53 * <ul> 54 * <li> <code>com::sun::star::container::XNamed</code></li> 55 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 56 * <li> <code>com::sun::star::container::XElementAccess</code></li> 57 * <li> <code>com::sun::star::sheet::TableAutoFormat</code></li> 58 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 59 * </ul> 60 * This object test <b> is NOT </b> designed to be run in several 61 * threads concurently. 62 * @see com.sun.star.container.XNamed 63 * @see com.sun.star.container.XIndexAccess 64 * @see com.sun.star.container.XElementAccess 65 * @see com.sun.star.sheet.TableAutoFormat 66 * @see com.sun.star.beans.XPropertySet 67 * @see ifc.container._XNamed 68 * @see ifc.container._XIndexAccess 69 * @see ifc.container._XElementAccess 70 * @see ifc.sheet._TableAutoFormat 71 * @see ifc.beans._XPropertySet 72 */ 73 public class ScAutoFormatObj extends TestCase { 74 75 /** 76 * Creating a Testenvironment for the interfaces to be tested. 77 * Using SOffice ServiceManager an instance of 78 * <code>com.sun.star.sheet.TableAutoFormatField</code> service 79 * is created. From this collection one Format is retrieved as 80 * object tested. 81 */ 82 public TestEnvironment createTestEnvironment(TestParameters tParam, 83 PrintWriter log) { 84 85 XInterface oObj = null; 86 XMultiServiceFactory oMSF = (XMultiServiceFactory)(XMultiServiceFactory)tParam.getMSF(); 87 try { 88 XInterface formats = (XInterface)oMSF.createInstance 89 ("com.sun.star.sheet.TableAutoFormats"); 90 XIndexAccess formatsIndex = (XIndexAccess) 91 UnoRuntime.queryInterface(XIndexAccess.class, formats); 92 oObj = (XInterface) AnyConverter.toObject( 93 new Type(XInterface.class),formatsIndex.getByIndex 94 (formatsIndex.getCount() - 1)); 95 96 XNamed objNamed = (XNamed) 97 UnoRuntime.queryInterface(XNamed.class, oObj) ; 98 log.println("AutoFormat name is '" + objNamed.getName() + "'") ; 99 } catch (com.sun.star.uno.Exception e) { 100 e.printStackTrace(log); 101 throw new StatusException("Unexpected exception", e); 102 } 103 104 TestEnvironment tEnv = new TestEnvironment(oObj); 105 106 return tEnv; 107 } 108 } 109 110