Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellSearchObj.java
blob0d005fd7de72de912e1a54ed1d95f606ed6e2cbe
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.XSpreadsheet;
32 import com.sun.star.sheet.XSpreadsheetDocument;
33 import com.sun.star.sheet.XSpreadsheets;
34 import com.sun.star.uno.AnyConverter;
35 import com.sun.star.uno.Type;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.util.XSearchable;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.util.SearchDescriptor</code> that was implemented by
43 * a spreadsheet. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>com::sun::star::util::XSearchDescriptor</code></li>
47 * <li> <code>com::sun::star::util::SearchDescriptor</code></li>
48 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
49 * <li> <code>com::sun::star::util::XReplaceDescriptor</code></li>
50 * </ul>
51 * @see com.sun.star.util.SearchDescriptor
52 * @see com.sun.star.util.XSearchDescriptor
53 * @see com.sun.star.util.SearchDescriptor
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.util.XReplaceDescriptor
56 * @see ifc.util._XSearchDescriptor
57 * @see ifc.util._SearchDescriptor
58 * @see ifc.beans._XPropertySet
59 * @see ifc.util._XReplaceDescriptor
61 public class ScCellSearchObj extends TestCase {
62 private XSpreadsheetDocument xSheetDoc = null;
64 /**
65 * Creates Spreadsheet document.
67 @Override
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 // get a soffice factory object
70 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
72 try {
73 log.println( "creating a sheetdocument" );
74 xSheetDoc = SOF.createCalcDoc(null);
75 } catch (com.sun.star.uno.Exception e) {
76 // Some exception occurs.FAILED
77 e.printStackTrace( log );
78 throw new StatusException( "Couldn't create document", e );
82 /**
83 * Disposes Spreadsheet document.
85 @Override
86 protected void cleanup( TestParameters tParam, PrintWriter log ) {
87 log.println( " disposing xSheetDoc " );
88 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
89 util.DesktopTools.closeDoc(oComp);
92 /**
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Retrieves a collection of spreadsheets from a document,
95 * and takes one of them. Creates search descriptor using the interface
96 * <code>XSearchable</code>. The created search descriptor is instance of
97 * the service <code>com.sun.star.util.SearchDescriptor</code> that
98 * implemented by a spreasheet.
99 * @see com.sun.star.util.XSearchable
101 @Override
102 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
104 XInterface oObj = null;
106 // creation of testobject here
107 // first we write what we are intend to do to log file
108 log.println( "creating a test environment" );
110 log.println("getting sheets");
111 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
113 log.println("getting a sheet");
114 XSpreadsheet oSheet = null;
115 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
117 try {
118 oSheet = (XSpreadsheet) AnyConverter.toObject(
119 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
120 } catch (com.sun.star.lang.WrappedTargetException e) {
121 e.printStackTrace(log);
122 throw new StatusException( "Couldn't get a spreadsheet", e);
123 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
124 e.printStackTrace(log);
125 throw new StatusException( "Couldn't get a spreadsheet", e);
126 } catch (com.sun.star.lang.IllegalArgumentException e) {
127 e.printStackTrace(log);
128 throw new StatusException( "Couldn't get a spreadsheet", e);
131 XSearchable xSearch = UnoRuntime.queryInterface(XSearchable.class,oSheet);
133 oObj = xSearch.createSearchDescriptor();
134 // create testobject here
135 log.println("creating a new environment for object");
136 TestEnvironment tEnv = new TestEnvironment(oObj);
138 return tEnv;
139 } // finish method getTestEnvironment
140 } // finish class ScCellSearchObj