bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScImportDescriptorBase.java
blob6d94824d7374f156cbe216d75a71f220f6f100ec
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.sheet.XSpreadsheetDocument;
32 import com.sun.star.sheet.XSpreadsheets;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 import com.sun.star.util.XImportable;
37 /**
39 * initial description
40 * @see com.sun.star.sheet.DatabaseImportDescriptor
43 public class ScImportDescriptorBase extends TestCase {
45 XSpreadsheetDocument xSpreadsheetDoc;
47 /**
48 * in general this method creates a testdocument
50 * @param tParam class which contains additional test parameters
51 * @param log class to log the test state and result
54 * @see TestParameters
55 * @see PrintWriter
58 @Override
59 protected void initialize( TestParameters tParam, PrintWriter log ) {
60 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
62 try {
63 log.println( "creating a Spreadsheet document" );
64 xSpreadsheetDoc = SOF.createCalcDoc(null);
65 } catch ( com.sun.star.uno.Exception e ) {
66 // Some exception occurs.FAILED
67 e.printStackTrace( log );
68 throw new StatusException( "Couldn't create document", e );
73 /**
74 * in general this method disposes the testenvironment and document
76 * @param tParam class which contains additional test parameters
77 * @param log class to log the test state and result
80 * @see TestParameters
81 * @see PrintWriter
84 @Override
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing xSheetDoc " );
87 XComponent oComp = UnoRuntime.queryInterface
88 (XComponent.class, xSpreadsheetDoc) ;
89 util.DesktopTools.closeDoc(oComp);
94 /**
95 * creating a Testenvironment for the interfaces to be tested
97 * @param tParam class which contains additional test parameters
98 * @param log class to log the test state and result
100 * @return Status class
102 * @see TestParameters
103 * @see PrintWriter
105 @Override
106 public TestEnvironment createTestEnvironment( TestParameters tParam,
107 PrintWriter log )
108 throws StatusException {
110 XInterface oObj = null;
111 XImportable xIMP = null;
113 // creation of testobject here
114 // first we write what we are intend to do to log file
115 log.println( "creating a test environment" );
117 // create testobject here
119 log.println("getting sheets");
120 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
121 if (xSpreadsheets == null) log.println("FAILED"); else log.println("OK");
123 log.println("getting a sheet");
124 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
126 try {
127 oObj = UnoRuntime.queryInterface(XInterface.class,oIndexAccess.getByIndex(0));
128 } catch (Exception e) {
129 throw new StatusException( "Couldn't get a spreadsheet", e);
132 xIMP = UnoRuntime.queryInterface(XImportable.class,oObj);
134 TestEnvironment tEnv = new TestEnvironment(oObj);
135 tEnv.addObjRelation("xIMP",xIMP);
136 return tEnv;
138 } // finish method getTestEnvironment
140 } // finish class ScImportDescriptorBase