bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableColumnObj.java
blobf218e24eaed1c8383e209bc8a5be697a75a35ddd
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.sheet.XSpreadsheet;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.sheet.XSpreadsheets;
35 import com.sun.star.table.XColumnRowRange;
36 import com.sun.star.table.XTableColumns;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.table.TableColumn</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::container::XNamed</code></li>
48 * <li> <code>com::sun::star::table::TableColumn</code></li>
49 * <li> <code>com::sun::star::table::XCellRange</code></li>
50 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
51 * </ul>
52 * @see com.sun.star.container.XNamed
53 * @see com.sun.star.table.TableColumn
54 * @see com.sun.star.table.XCellRange
55 * @see com.sun.star.beans.XPropertySet
56 * @see ifc.container._XNamed
57 * @see ifc.table._TableColumn
58 * @see ifc.table._XCellRange
59 * @see ifc.beans._XPropertySet
61 public class ScTableColumnObj 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 the document and takes one of
95 * them. Obtaines the collection of columns in the range using the interface
96 * <code>XColumnRowRange</code>. Retrieves the column with index 10 that is
97 * the instance of the service <code>com.sun.star.table.TableColumn</code>.
98 * Object relations created :
99 * <ul>
100 * <li> <code>'setName'</code> for
101 * {@link ifc.container._XNamed} </li>
102 * <li> <code>'ValidRange'</code> for
103 * {@link ifc.table._XCellRange} </li>
104 * </ul>
105 * @see com.sun.star.table.XColumnRowRange
106 * @see com.sun.star.table.TableColumn
108 @Override
109 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
111 XInterface oObj = null;
113 // creation of the testobject here
114 // first we write what we are intend to do to log file
115 log.println("creating a test environment");
117 XSpreadsheet xSpreadsheet = null;
119 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
120 XNameAccess oNames = UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets );
121 try {
122 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject(
123 new Type(XSpreadsheet.class),
124 oNames.getByName(oNames.getElementNames()[0]));
125 } catch (com.sun.star.lang.WrappedTargetException e) {
126 e.printStackTrace(log);
127 throw new StatusException("Couldn't get element by name", e);
128 } catch (com.sun.star.container.NoSuchElementException e) {
129 e.printStackTrace(log);
130 throw new StatusException("Couldn't get element by name", e);
131 } catch (com.sun.star.lang.IllegalArgumentException e) {
132 e.printStackTrace(log);
133 throw new StatusException("Couldn't get element by name", e);
136 XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
137 XTableColumns oColumns = oColumnRowRange.getColumns();
138 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, oColumns);
139 try {
140 oObj = (XInterface) AnyConverter.toObject(
141 new Type(XInterface.class),oIndexAccess.getByIndex(10));
142 } catch (com.sun.star.lang.WrappedTargetException e) {
143 e.printStackTrace(log);
144 throw new StatusException("Couldn't get by index", e);
145 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
146 e.printStackTrace(log);
147 throw new StatusException("Couldn't get by index", e);
148 } catch (com.sun.star.lang.IllegalArgumentException e) {
149 e.printStackTrace(log);
150 throw new StatusException("Couldn't get by index", e);
153 log.println("creating a new environment for object");
154 TestEnvironment tEnv = new TestEnvironment(oObj);
156 // a valid Range for XCellRange
157 tEnv.addObjRelation("ValidRange","K1:K1");
159 //since TableColumnsNames are fixed XNamed::setName() should always be OK
160 tEnv.addObjRelation("setName",Boolean.TRUE);
161 return tEnv;