bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableColumnsObj.java
blobd2d49551a16d2da2504b53c710ec40c1e271b83f
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.sheet.XSpreadsheet;
32 import com.sun.star.sheet.XSpreadsheetDocument;
33 import com.sun.star.sheet.XSpreadsheets;
34 import com.sun.star.table.XCellRange;
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.TableColumns</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
48 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * <li> <code>com::sun::star::container::XNameAccess</code></li>
50 * <li> <code>com::sun::star::table::XTableColumns</code></li>
51 * </ul>
52 * @see com.sun.star.table.TableColumns
53 * @see com.sun.star.container.XIndexAccess
54 * @see com.sun.star.container.XElementAccess
55 * @see com.sun.star.container.XNameAccess
56 * @see com.sun.star.table.XTableColumns
57 * @see ifc.container._XIndexAccess
58 * @see ifc.container._XElementAccess
59 * @see ifc.container._XNameAccess
60 * @see ifc.table._XTableColumns
62 public class ScTableColumnsObj extends TestCase {
63 private XSpreadsheetDocument xSheetDoc = null;
65 /**
66 * Creates Spreadsheet document.
68 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
70 // get a soffice factory object
71 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xSheetDoc " );
89 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
90 util.DesktopTools.closeDoc(oComp);
93 /**
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Retrieves a collection of spreadsheets from the document and takes one of
96 * them. Obtaines the collection of columns in the range using the interface
97 * <code>XColumnRowRange</code>. This collection is the instance of the
98 * service <code>com.sun.star.table.TableColumns</code>.
99 * @see com.sun.star.table.XColumnRowRange
100 * @see com.sun.star.table.TableColumns
102 @Override
103 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
105 XInterface oObj = null;
107 // creation of the testobject here
108 // first we write what we are intend to do to log file
109 log.println("craeting a test environment");
111 log.println("getting column");
112 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
113 XNameAccess oNames = UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets );
114 XSpreadsheet xSpreadsheet = null;
115 try {
116 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject(
117 new Type(XSpreadsheet.class),
118 oNames.getByName(oNames.getElementNames()[0]));
119 } catch (com.sun.star.lang.WrappedTargetException e) {
120 e.printStackTrace(log);
121 throw new StatusException("Couldn't get spreadsheet", e);
122 } catch (com.sun.star.container.NoSuchElementException e) {
123 e.printStackTrace(log);
124 throw new StatusException("Couldn't get spreadsheet", e);
125 } catch (com.sun.star.lang.IllegalArgumentException e) {
126 e.printStackTrace(log);
127 throw new StatusException("Couldn't get spreadsheet", e);
130 XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
131 XTableColumns oColumns = oColumnRowRange.getColumns();
132 oObj = oColumns;
134 log.println("creating a new environment for object");
135 TestEnvironment tEnv = new TestEnvironment(oObj);
137 // adding relation for XTableColumns
138 tEnv.addObjRelation("XTableColumns.XCellRange",
139 UnoRuntime.queryInterface(XCellRange.class, xSpreadsheet));
141 return tEnv;
143 } // finish class ScTableColumnsObj