merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAutoFormatsObj.java
blobc23bc277bc17add3cb8097bdd0a510d780e2c01c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScAutoFormatsObj.java,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._sc;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.SOfficeFactory;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.sheet.XSpreadsheetDocument;
43 import com.sun.star.uno.AnyConverter;
44 import com.sun.star.uno.Type;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
48 /**
49 * Test for object which is represented by service
50 * <code>com.sun.star.TableAutoFormats</code>. <p>
51 * In StarCalc application there is a collection of autoformats
52 * for tables (you can select a predefined format for a
53 * table or create your own). The object represents
54 * this collection. <p>
55 * Object implements the following interfaces :
56 * <ul>
57 * <li> <code>com::sun::star::container::XNameAccess</code></li>
58 * <li> <code>com::sun::star::container::XElementAccess</code></li>
59 * <li> <code>com::sun::star::container::XNameReplace</code></li>
60 * <li> <code>com::sun::star::container::XNameContainer</code></li>
61 * </ul>
62 * This object test <b> is NOT </b> designed to be run in several
63 * threads concurently.
64 * @see com.sun.star.container.XNameAccess
65 * @see com.sun.star.container.XElementAccess
66 * @see com.sun.star.container.XNameReplace
67 * @see com.sun.star.container.XNameContainer
68 * @see ifc.container._XNameAccess
69 * @see ifc.container._XElementAccess
70 * @see ifc.container._XNameReplace
71 * @see ifc.container._XNameContainer
73 public class ScAutoFormatsObj extends TestCase{
74 static XSpreadsheetDocument xSheetDoc = null;
75 static SOfficeFactory SOF = null;
77 /**
78 * Creates Spreadsheet document.
80 protected void initialize( TestParameters tParam, PrintWriter log ) {
81 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
83 try {
84 log.println( "creating a Spreadsheet document" );
85 xSheetDoc = SOF.createCalcDoc(null);
86 } catch ( com.sun.star.uno.Exception e ) {
87 // Some exception occures.FAILED
88 e.printStackTrace( log );
89 throw new StatusException( "Couldn't create document", e );
93 /**
94 * Disposes Spreadsheet document.
96 protected void cleanup( TestParameters tParam, PrintWriter log ) {
97 log.println( " disposing xSheetDoc " );
98 XComponent oComp = (XComponent) UnoRuntime.queryInterface
99 (XComponent.class, xSheetDoc) ;
100 util.DesktopTools.closeDoc(oComp);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Creates an instance of the service
107 * <code>com.sun.star.sheet.TableAutoFormats</code>.
108 * Object relations created :
109 * <ul>
110 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
111 * {@link ifc.container._XNameContainer},
112 * {@link ifc.container._XNameReplace} N relations
113 * which represents objects to be inserted - one
114 * object for each interface thread. </li>
115 * </ul>
117 public synchronized TestEnvironment createTestEnvironment
118 (TestParameters Param, PrintWriter log )
119 throws StatusException {
121 XInterface oObj = null;
123 try {
124 // creation of testobject here
125 // get AutoFormats
126 XComponent xComp = (XComponent)UnoRuntime.queryInterface
127 (XComponent.class, xSheetDoc);
128 oObj = (XInterface) AnyConverter.toObject(
129 new Type(XInterface.class),((XMultiServiceFactory)Param.getMSF()).createInstance
130 ("com.sun.star.sheet.TableAutoFormats"));
131 Object secondInstance = SOF.createInstance
132 (xComp, "com.sun.star.sheet.TableAutoFormat");
134 TestEnvironment tEnv = new TestEnvironment(oObj) ;
136 //adding ObjRelation for XNameContainer
137 tEnv.addObjRelation("SecondInstance",secondInstance);
139 // INSTANCEn : _XNameContainer; _XNameReplace
140 log.println( "adding INSTANCEn as mod relation to environment" );
141 int THRCNT = 1;
142 if ((String)Param.get("THRCNT") != null) {
143 Integer.parseInt((String)Param.get("THRCNT"));
145 for (int n = 1; n < (THRCNT+1) ;n++ ) {
146 log.println( "adding INSTANCE" + n
147 +" as mod relation to environment" );
148 tEnv.addObjRelation("INSTANCE" + n, SOF.createInstance(xComp,
149 "com.sun.star.sheet.TableAutoFormat"));
152 return tEnv;
153 } catch (com.sun.star.uno.Exception e) {
154 log.println ("Exception occured while creating test Object.");
155 e.printStackTrace(log);
156 throw new StatusException("Couldn't create test object", e);
160 } // finish class ScAutoFormatsObj