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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
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
.sheet
.XSheetAnnotation
;
32 import com
.sun
.star
.sheet
.XSheetAnnotationAnchor
;
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
.CellAddress
;
37 import com
.sun
.star
.table
.XCell
;
38 import com
.sun
.star
.table
.XCellRange
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which represents some text annotation
46 * anchored to some cell in spreadsheet (implement
47 * <code>com.sun.star.sheet.CellAnnotation</code>).<p>
48 * Object implements the following interfaces :
50 * <li> <code>com::sun::star::text::XSimpleText</code></li>
51 * <li> <code>com::sun::star::text::XTextRange</code></li>
52 * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li>
54 * This object test <b> is NOT </b> designed to be run in several
55 * threads concurently.
56 * @see com.sun.star.sheet.CellAnnotation
57 * @see com.sun.star.text.XSimpleText
58 * @see com.sun.star.text.XTextRange
59 * @see com.sun.star.sheet.XSheetAnnotation
60 * @see ifc.text._XSimpleText
61 * @see ifc.text._XTextRange
62 * @see ifc.sheet._XSheetAnnotation
64 public class ScAnnotationObj
extends TestCase
{
65 private XSpreadsheetDocument xSheetDoc
= null;
68 * Creates a spreadsheet document.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
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
);
86 * Disposes a spreadsheet document.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xSheetDoc " );
91 XComponent oComp
= UnoRuntime
.queryInterface
92 (XComponent
.class, xSheetDoc
) ;
93 util
.DesktopTools
.closeDoc(oComp
);
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Retrieves a collection of spreadsheets from a document,
100 * and takes one them. Then a single cell is retrieved, and
101 * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code>
102 * interface an annotation is got.
103 * Object relations created :
105 * <li> <code>'CELLPOS'</code> for
106 * {@link ifc.sheet._XSheetAnnotation} (of <code>
107 * com.sun.star.table.CellAddress</code> type) which
108 * contains the annotation cell address.</li>
112 public synchronized TestEnvironment createTestEnvironment
113 ( TestParameters Param
, PrintWriter log
)
114 throws StatusException
{
116 XInterface oObj
= null;
119 // creation of testobject here
120 // first we write what we are intend to do to log file
121 log
.println( "Creating a test environment" );
123 CellAddress cellPos
= new CellAddress((short)0, 1, 2);
125 log
.println("Getting test object ") ;
127 XSpreadsheetDocument xArea
= UnoRuntime
.queryInterface(XSpreadsheetDocument
.class, xSheetDoc
);
128 XSpreadsheets oSheets
= xArea
.getSheets();
130 XIndexAccess XAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
133 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
134 new Type(XSpreadsheet
.class),XAccess
.getByIndex(cellPos
.Sheet
));
135 XCellRange oCRange
= UnoRuntime
.queryInterface(XCellRange
.class, oSheet
);
136 oCell
= oCRange
.getCellByPosition(cellPos
.Column
, cellPos
.Row
);
137 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
138 e
.printStackTrace(log
);
139 throw new StatusException(
140 "Error getting test object from spreadsheet document",e
);
141 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException(
144 "Error getting test object from spreadsheet document",e
);
145 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
146 e
.printStackTrace(log
);
147 throw new StatusException(
148 "Error getting test object from spreadsheet document",e
);
151 XSheetAnnotationAnchor oAnnoA
= UnoRuntime
.queryInterface(XSheetAnnotationAnchor
.class, oCell
);
152 XSheetAnnotation oAnno
= oAnnoA
.getAnnotation();
156 TestEnvironment tEnv
= new TestEnvironment( oObj
);
158 tEnv
.addObjRelation("CELLPOS", cellPos
);
160 // Other parameters required for interface tests
165 } // finish class ScAnnotationObj