merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScFunctionDescriptionObj.java
blob68da4b9b3b53071863e5c2b0114d7d7a8f696ece
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: ScFunctionDescriptionObj.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
34 import java.util.Random;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.SOfficeFactory;
42 import com.sun.star.container.XNameAccess;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.sheet.XSpreadsheetDocument;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
49 public class ScFunctionDescriptionObj extends TestCase {
50 static XSpreadsheetDocument xSheetDoc = null;
52 protected void initialize( TestParameters tParam, PrintWriter log ) {
53 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() );
55 try {
56 log.println( "creating a Spreadsheet document" );
57 xSheetDoc = SOF.createCalcDoc(null);
58 } catch ( com.sun.star.uno.Exception e ) {
59 // Some exception occures.FAILED
60 e.printStackTrace( log );
61 throw new StatusException( "Couldn't create document", e );
66 protected void cleanup( TestParameters tParam, PrintWriter log ) {
67 log.println( " disposing xSheetDoc " );
68 XComponent oComp = (XComponent) UnoRuntime.
69 queryInterface (XComponent.class, xSheetDoc) ;
70 util.DesktopTools.closeDoc(oComp);
74 /**
75 * creating a Testenvironment for the interfaces to be tested
77 public synchronized TestEnvironment createTestEnvironment(
78 TestParameters Param, PrintWriter log )
79 throws StatusException {
81 XInterface oObj = null;
83 // creation of testobject here
84 // first we write what we are intend to do to log file
85 log.println( "Creating a test environment" );
87 try {
88 log.println("Getting test object ") ;
90 XMultiServiceFactory oDocMSF = (XMultiServiceFactory) Param.getMSF();
92 XInterface FDs = (XInterface)oDocMSF.
93 createInstance("com.sun.star.sheet.FunctionDescriptions");
94 XNameAccess NA = (XNameAccess)UnoRuntime.queryInterface
95 (XNameAccess.class, FDs);
97 String names[] = NA.getElementNames();
98 Random rnd = new Random();
99 int idx = rnd.nextInt(names.length);
101 oObj = (XInterface)NA.getByName(names[idx]);
103 log.println("Creating object - " +
104 ((oObj == null) ? "FAILED" : "OK"));
106 } catch (Exception e) {
107 e.printStackTrace(log) ;
108 throw new StatusException
109 ("Error getting test object from spreadsheet document",e) ;
112 TestEnvironment tEnv = new TestEnvironment( oObj );
114 // Other parameters required for interface tests
116 return tEnv;