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 package mod._sc; 24 25 import java.io.PrintWriter; 26 27 import lib.StatusException; 28 import lib.TestCase; 29 import lib.TestEnvironment; 30 import lib.TestParameters; 31 import util.SOfficeFactory; 32 33 import com.sun.star.lang.XComponent; 34 import com.sun.star.lang.XMultiServiceFactory; 35 import com.sun.star.sheet.XSpreadsheetDocument; 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; 40 41 /** 42 * Test for object which is represented by service 43 * <code>com.sun.star.TableAutoFormats</code>. <p> 44 * In StarCalc application there is a collection of autoformats 45 * for tables (you can select a predefined format for a 46 * table or create your own). The object represents 47 * this collection. <p> 48 * Object implements the following interfaces : 49 * <ul> 50 * <li> <code>com::sun::star::container::XNameAccess</code></li> 51 * <li> <code>com::sun::star::container::XElementAccess</code></li> 52 * <li> <code>com::sun::star::container::XNameReplace</code></li> 53 * <li> <code>com::sun::star::container::XNameContainer</code></li> 54 * </ul> 55 * This object test <b> is NOT </b> designed to be run in several 56 * threads concurently. 57 * @see com.sun.star.container.XNameAccess 58 * @see com.sun.star.container.XElementAccess 59 * @see com.sun.star.container.XNameReplace 60 * @see com.sun.star.container.XNameContainer 61 * @see ifc.container._XNameAccess 62 * @see ifc.container._XElementAccess 63 * @see ifc.container._XNameReplace 64 * @see ifc.container._XNameContainer 65 */ 66 public class ScAutoFormatsObj extends TestCase{ 67 static XSpreadsheetDocument xSheetDoc = null; 68 static SOfficeFactory SOF = null; 69 70 /** 71 * Creates Spreadsheet document. 72 */ 73 protected void initialize( TestParameters tParam, PrintWriter log ) { 74 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 75 76 try { 77 log.println( "creating a Spreadsheet document" ); 78 xSheetDoc = SOF.createCalcDoc(null); 79 } catch ( com.sun.star.uno.Exception e ) { 80 // Some exception occures.FAILED 81 e.printStackTrace( log ); 82 throw new StatusException( "Couldn't create document", e ); 83 } 84 } 85 86 /** 87 * Disposes Spreadsheet document. 88 */ 89 protected void cleanup( TestParameters tParam, PrintWriter log ) { 90 log.println( " disposing xSheetDoc " ); 91 XComponent oComp = (XComponent) UnoRuntime.queryInterface 92 (XComponent.class, xSheetDoc) ; 93 util.DesktopTools.closeDoc(oComp); 94 } 95 96 97 /** 98 * Creating a Testenvironment for the interfaces to be tested. 99 * Creates an instance of the service 100 * <code>com.sun.star.sheet.TableAutoFormats</code>. 101 * Object relations created : 102 * <ul> 103 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for 104 * {@link ifc.container._XNameContainer}, 105 * {@link ifc.container._XNameReplace} N relations 106 * which represents objects to be inserted - one 107 * object for each interface thread. </li> 108 * </ul> 109 */ 110 public synchronized TestEnvironment createTestEnvironment 111 (TestParameters Param, PrintWriter log ) 112 throws StatusException { 113 114 XInterface oObj = null; 115 116 try { 117 // creation of testobject here 118 // get AutoFormats 119 XComponent xComp = (XComponent)UnoRuntime.queryInterface 120 (XComponent.class, xSheetDoc); 121 oObj = (XInterface) AnyConverter.toObject( 122 new Type(XInterface.class),((XMultiServiceFactory)Param.getMSF()).createInstance 123 ("com.sun.star.sheet.TableAutoFormats")); 124 Object secondInstance = SOF.createInstance 125 (xComp, "com.sun.star.sheet.TableAutoFormat"); 126 127 TestEnvironment tEnv = new TestEnvironment(oObj) ; 128 129 //adding ObjRelation for XNameContainer 130 tEnv.addObjRelation("SecondInstance",secondInstance); 131 132 // INSTANCEn : _XNameContainer; _XNameReplace 133 log.println( "adding INSTANCEn as mod relation to environment" ); 134 int THRCNT = 1; 135 if ((String)Param.get("THRCNT") != null) { 136 Integer.parseInt((String)Param.get("THRCNT")); 137 } 138 for (int n = 1; n < (THRCNT+1) ;n++ ) { 139 log.println( "adding INSTANCE" + n 140 +" as mod relation to environment" ); 141 tEnv.addObjRelation("INSTANCE" + n, SOF.createInstance(xComp, 142 "com.sun.star.sheet.TableAutoFormat")); 143 } 144 145 return tEnv; 146 } catch (com.sun.star.uno.Exception e) { 147 log.println ("Exception occured while creating test Object."); 148 e.printStackTrace(log); 149 throw new StatusException("Couldn't create test object", e); 150 } 151 } 152 153 } // finish class ScAutoFormatsObj 154 155