Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScSortDescriptorBase.java
blob5415366efc30919604e81d3d6d8f0221b5563fbb
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.XSortable;
38 /**
40 * initial description
41 * @see com.sun.star.beans.XPropertySet
42 * @see com.sun.star.sheet.SheetSortDescriptor
45 public class ScSortDescriptorBase extends TestCase {
47 private XSpreadsheetDocument xSpreadsheetDoc;
49 /**
50 * in general this method creates a testdocument
52 * @param tParam class which contains additional test parameters
53 * @param log class to log the test state and result
56 * @see TestParameters
57 * @see PrintWriter
60 @Override
61 protected void initialize( TestParameters tParam, PrintWriter log ) {
62 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
64 try {
65 log.println( "creating a Spreadsheet document" );
66 xSpreadsheetDoc = SOF.createCalcDoc(null);
67 } catch ( com.sun.star.uno.Exception e ) {
68 // Some exception occurs.FAILED
69 e.printStackTrace( log );
70 throw new StatusException( "Couldn't create document", e );
75 /**
76 * in general this method disposes the testenvironment and document
78 * @param tParam class which contains additional test parameters
79 * @param log class to log the test state and result
82 * @see TestParameters
83 * @see PrintWriter
86 @Override
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xSheetDoc " );
89 XComponent oComp = UnoRuntime.queryInterface
90 (XComponent.class, xSpreadsheetDoc) ;
91 util.DesktopTools.closeDoc(oComp);
96 /**
97 * creating a Testenvironment for the interfaces to be tested
99 * @param tParam class which contains additional test parameters
100 * @param log class to log the test state and result
102 * @return Status class
104 * @see TestParameters
105 * @see PrintWriter
107 @Override
108 public TestEnvironment createTestEnvironment( TestParameters tParam,
109 PrintWriter log )
110 throws StatusException {
112 XInterface oObj = null;
113 XSortable xSORT = null;
115 // creation of testobject here
116 // first we write what we are intend to do to log file
117 log.println( "creating a test environment" );
119 // create testobject here
121 log.println("getting sheets");
122 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
123 if (xSpreadsheets == null) log.println("FAILED"); else log.println("OK");
125 log.println("getting a sheet");
126 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
128 try {
129 oObj = UnoRuntime.queryInterface(XInterface.class,oIndexAccess.getByIndex(0));
130 } catch (Exception e) {
131 throw new StatusException( "Couldn't get a spreadsheet", e);
134 xSORT = UnoRuntime.queryInterface(XSortable.class,oObj);
136 TestEnvironment tEnv = new TestEnvironment(oObj);
137 tEnv.addObjRelation("xSORT",xSORT);
138 return tEnv;
140 } // finish method getTestEnvironment
142 } // finish class ScSortDescriptorBase