bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableColumnObj.java
blobe129f7a5bf546bfff7acebe18d702e4a4382c822
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.container.XNameAccess;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.sheet.XSpreadsheet;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.sheet.XSpreadsheets;
36 import com.sun.star.table.XColumnRowRange;
37 import com.sun.star.table.XTableColumns;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.table.TableColumn</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::container::XNamed</code></li>
49 * <li> <code>com::sun::star::table::TableColumn</code></li>
50 * <li> <code>com::sun::star::table::XCellRange</code></li>
51 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
52 * </ul>
53 * @see com.sun.star.container.XNamed
54 * @see com.sun.star.table.TableColumn
55 * @see com.sun.star.table.XCellRange
56 * @see com.sun.star.beans.XPropertySet
57 * @see ifc.container._XNamed
58 * @see ifc.table._TableColumn
59 * @see ifc.table._XCellRange
60 * @see ifc.beans._XPropertySet
62 public class ScTableColumnObj extends TestCase {
63 private XSpreadsheetDocument xSheetDoc = null;
65 /**
66 * Creates Spreadsheet document.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 // get a soffice factory object
70 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)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 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing xSheetDoc " );
87 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
88 util.DesktopTools.closeDoc(oComp);
91 /**
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Retrieves a collection of spreadsheets from the document and takes one of
94 * them. Obtaines the collection of columns in the range using the interface
95 * <code>XColumnRowRange</code>. Retrieves the column with index 10 that is
96 * the instance of the service <code>com.sun.star.table.TableColumn</code>.
97 * Object relations created :
98 * <ul>
99 * <li> <code>'setName'</code> for
100 * {@link ifc.container._XNamed} </li>
101 * <li> <code>'ValidRange'</code> for
102 * {@link ifc.table._XCellRange} </li>
103 * </ul>
104 * @see com.sun.star.table.XColumnRowRange
105 * @see com.sun.star.table.TableColumn
107 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
109 XInterface oObj = null;
111 // creation of the testobject here
112 // first we write what we are intend to do to log file
113 log.println("creating a test environment");
115 XSpreadsheet xSpreadsheet = null;
117 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
118 XNameAccess oNames = UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets );
119 try {
120 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject(
121 new Type(XSpreadsheet.class),
122 oNames.getByName(oNames.getElementNames()[0]));
123 } catch (com.sun.star.lang.WrappedTargetException e) {
124 e.printStackTrace(log);
125 throw new StatusException("Couldn't get element by name", e);
126 } catch (com.sun.star.container.NoSuchElementException e) {
127 e.printStackTrace(log);
128 throw new StatusException("Couldn't get element by name", e);
129 } catch (com.sun.star.lang.IllegalArgumentException e) {
130 e.printStackTrace(log);
131 throw new StatusException("Couldn't get element by name", e);
134 XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
135 XTableColumns oColumns = oColumnRowRange.getColumns();
136 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, oColumns);
137 try {
138 oObj = (XInterface) AnyConverter.toObject(
139 new Type(XInterface.class),oIndexAccess.getByIndex(10));
140 } catch (com.sun.star.lang.WrappedTargetException e) {
141 e.printStackTrace(log);
142 throw new StatusException("Couldn't get by index", e);
143 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
144 e.printStackTrace(log);
145 throw new StatusException("Couldn't get by index", e);
146 } catch (com.sun.star.lang.IllegalArgumentException e) {
147 e.printStackTrace(log);
148 throw new StatusException("Couldn't get by index", e);
151 log.println("creating a new environment for object");
152 TestEnvironment tEnv = new TestEnvironment(oObj);
154 // a valid Range for XCellRange
155 tEnv.addObjRelation("ValidRange","K1:K1");
157 //since TableColumnsNames are fixed XNamed::setName() should always be OK
158 tEnv.addObjRelation("setName",new Boolean(true));
159 return tEnv;