bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAnnotationObj.java
bloba88417820ab0855c70d7cd67692946e149f0f489
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.lang.XMultiServiceFactory;
32 import com.sun.star.sheet.XSheetAnnotation;
33 import com.sun.star.sheet.XSheetAnnotationAnchor;
34 import com.sun.star.sheet.XSpreadsheet;
35 import com.sun.star.sheet.XSpreadsheetDocument;
36 import com.sun.star.sheet.XSpreadsheets;
37 import com.sun.star.table.CellAddress;
38 import com.sun.star.table.XCell;
39 import com.sun.star.table.XCellRange;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
46 * Test for object which represents some text annotation
47 * anchored to some cell in spreadsheet (implement
48 * <code>com.sun.star.sheet.CellAnnotation</code>).<p>
49 * Object implements the following interfaces :
50 * <ul>
51 * <li> <code>com::sun::star::text::XSimpleText</code></li>
52 * <li> <code>com::sun::star::text::XTextRange</code></li>
53 * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li>
54 * </ul>
55 * This object test <b> is NOT </b> designed to be run in several
56 * threads concurently.
57 * @see com.sun.star.sheet.CellAnnotation
58 * @see com.sun.star.text.XSimpleText
59 * @see com.sun.star.text.XTextRange
60 * @see com.sun.star.sheet.XSheetAnnotation
61 * @see ifc.text._XSimpleText
62 * @see ifc.text._XTextRange
63 * @see ifc.sheet._XSheetAnnotation
65 public class ScAnnotationObj extends TestCase {
66 private XSpreadsheetDocument xSheetDoc = null;
68 /**
69 * Creates a spreadsheet document.
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
74 try {
75 log.println( "creating a Spreadsheet document" );
76 xSheetDoc = SOF.createCalcDoc(null);
77 } catch ( com.sun.star.uno.Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
85 /**
86 * Disposes a spreadsheet document.
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing xSheetDoc " );
90 XComponent oComp = UnoRuntime.queryInterface
91 (XComponent.class, xSheetDoc) ;
92 util.DesktopTools.closeDoc(oComp);
96 /**
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Retrieves a collection of spreadsheets from a document,
99 * and takes one them. Then a single cell is retrieved, and
100 * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code>
101 * interface an annotation is got.
102 * Object relations created :
103 * <ul>
104 * <li> <code>'CELLPOS'</code> for
105 * {@link ifc.sheet._XSheetAnnotation} (of <code>
106 * com.sun.star.table.CellAddress</code> type) which
107 * contains the annotation cell address.</li>
108 * </ul>
110 public synchronized TestEnvironment createTestEnvironment
111 ( TestParameters Param, PrintWriter log )
112 throws StatusException {
114 XInterface oObj = null;
117 // creation of testobject here
118 // first we write what we are intend to do to log file
119 log.println( "Creating a test environment" );
121 CellAddress cellPos = new CellAddress((short)0, 1, 2);
123 log.println("Getting test object ") ;
125 XSpreadsheetDocument xArea = UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
126 XSpreadsheets oSheets = xArea.getSheets();
128 XIndexAccess XAccess = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
129 XCell oCell = null;
130 try {
131 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
132 new Type(XSpreadsheet.class),XAccess.getByIndex(cellPos.Sheet));
133 XCellRange oCRange = UnoRuntime.queryInterface(XCellRange.class, oSheet);
134 oCell = oCRange.getCellByPosition(cellPos.Column, cellPos.Row);
135 } catch(com.sun.star.lang.WrappedTargetException e) {
136 e.printStackTrace(log);
137 throw new StatusException(
138 "Error getting test object from spreadsheet document",e);
139 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
140 e.printStackTrace(log);
141 throw new StatusException(
142 "Error getting test object from spreadsheet document",e);
143 } catch(com.sun.star.lang.IllegalArgumentException e) {
144 e.printStackTrace(log);
145 throw new StatusException(
146 "Error getting test object from spreadsheet document",e);
149 XSheetAnnotationAnchor oAnnoA = UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, oCell);
150 XSheetAnnotation oAnno = oAnnoA.getAnnotation();
152 oObj = oAnno;
154 TestEnvironment tEnv = new TestEnvironment( oObj );
156 tEnv.addObjRelation("CELLPOS", cellPos);
158 // Other parameters required for interface tests
160 return tEnv;
163 } // finish class ScAnnotationObj