bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableColumnsObj.java
blob45af0f8fdb39ca61a0770d16db132017a6166911
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.XNameAccess;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
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.XCellRange;
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.TableColumns</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
49 * <li> <code>com::sun::star::container::XElementAccess</code></li>
50 * <li> <code>com::sun::star::container::XNameAccess</code></li>
51 * <li> <code>com::sun::star::table::XTableColumns</code></li>
52 * </ul>
53 * @see com.sun.star.table.TableColumns
54 * @see com.sun.star.container.XIndexAccess
55 * @see com.sun.star.container.XElementAccess
56 * @see com.sun.star.container.XNameAccess
57 * @see com.sun.star.table.XTableColumns
58 * @see ifc.container._XIndexAccess
59 * @see ifc.container._XElementAccess
60 * @see ifc.container._XNameAccess
61 * @see ifc.table._XTableColumns
63 public class ScTableColumnsObj extends TestCase {
64 private XSpreadsheetDocument xSheetDoc = null;
66 /**
67 * Creates Spreadsheet document.
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
70 // get a soffice factory object
71 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
73 try {
74 log.println( "creating a sheetdocument" );
75 xSheetDoc = SOF.createCalcDoc(null);
76 } catch (com.sun.star.uno.Exception e) {
77 // Some exception occurs.FAILED
78 e.printStackTrace( log );
79 throw new StatusException( "Couldn't create document", e );
83 /**
84 * Disposes Spreadsheet document.
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>. This collection is the instance of the
97 * service <code>com.sun.star.table.TableColumns</code>.
98 * @see com.sun.star.table.XColumnRowRange
99 * @see com.sun.star.table.TableColumns
101 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
103 XInterface oObj = null;
105 // creation of the testobject here
106 // first we write what we are intend to do to log file
107 log.println("craeting a test environment");
109 log.println("getting column");
110 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
111 XNameAccess oNames = UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets );
112 XSpreadsheet xSpreadsheet = null;
113 try {
114 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject(
115 new Type(XSpreadsheet.class),
116 oNames.getByName(oNames.getElementNames()[0]));
117 } catch (com.sun.star.lang.WrappedTargetException e) {
118 e.printStackTrace(log);
119 throw new StatusException("Couldn't get spreadsheet", e);
120 } catch (com.sun.star.container.NoSuchElementException e) {
121 e.printStackTrace(log);
122 throw new StatusException("Couldn't get spreadsheet", e);
123 } catch (com.sun.star.lang.IllegalArgumentException e) {
124 e.printStackTrace(log);
125 throw new StatusException("Couldn't get spreadsheet", e);
128 XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
129 XTableColumns oColumns = oColumnRowRange.getColumns();
130 oObj = oColumns;
132 log.println("creating a new environment for object");
133 TestEnvironment tEnv = new TestEnvironment(oObj);
135 // adding relation for XTableColumns
136 tEnv.addObjRelation("XTableColumns.XCellRange",
137 UnoRuntime.queryInterface(XCellRange.class, xSpreadsheet));
139 return tEnv;
141 } // finish class ScTableColumnsObj