1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScImportDescriptorBase.java,v $
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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XIndexAccess
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
45 import com
.sun
.star
.sheet
.XSpreadsheets
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
48 import com
.sun
.star
.util
.XImportable
;
53 * @see com.sun.star.sheet.DatabaseImportDescriptor
56 public class ScImportDescriptorBase
extends TestCase
{
58 XSpreadsheetDocument xSpreadsheetDoc
;
61 * in general this method creates a testdocument
63 * @param tParam class which contains additional test parameters
64 * @param log class to log the test state and result
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) tParam
.getMSF() );
75 log
.println( "creating a Spreadsheet document" );
76 xSpreadsheetDoc
= 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
);
86 * in general this method disposes the testenvironment and document
88 * @param tParam class which contains additional test parameters
89 * @param log class to log the test state and result
96 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
97 log
.println( " disposing xSheetDoc " );
98 XComponent oComp
= (XComponent
) UnoRuntime
.queryInterface
99 (XComponent
.class, xSpreadsheetDoc
) ;
100 util
.DesktopTools
.closeDoc(oComp
);
106 * creating a Testenvironment for the interfaces to be tested
108 * @param tParam class which contains additional test parameters
109 * @param log class to log the test state and result
111 * @return Status class
113 * @see TestParameters
116 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
118 throws StatusException
{
120 XInterface oObj
= null;
121 XImportable xIMP
= null;
123 // creation of testobject here
124 // first we write what we are intend to do to log file
125 log
.println( "creating a test environment" );
127 // create testobject here
129 log
.println("getting sheets");
130 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSpreadsheetDoc
.getSheets();
131 if (xSpreadsheets
== null) log
.println("FAILED"); else log
.println("OK");
133 log
.println("getting a sheet");
134 XIndexAccess oIndexAccess
= (XIndexAccess
)
135 UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
138 oObj
= (XInterface
) UnoRuntime
.queryInterface(XInterface
.class,oIndexAccess
.getByIndex(0));
139 } catch (Exception e
) {
140 throw new StatusException( "Couldn't get a spreadsheet", e
);
143 xIMP
= (XImportable
) UnoRuntime
.queryInterface(XImportable
.class,oObj
);
145 TestEnvironment tEnv
= new TestEnvironment(oObj
);
146 tEnv
.addObjRelation("xIMP",xIMP
);
149 } // finish method getTestEnvironment
151 } // finish class ScImportDescriptorBase