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 .
20 import com
.sun
.star
.container
.XIndexAccess
;
21 import com
.sun
.star
.lang
.XComponent
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.sheet
.XSheetAnnotation
;
24 import com
.sun
.star
.sheet
.XSheetAnnotationAnchor
;
25 import com
.sun
.star
.sheet
.XSheetAnnotationShapeSupplier
;
26 import com
.sun
.star
.sheet
.XSpreadsheet
;
27 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
28 import com
.sun
.star
.sheet
.XSpreadsheets
;
29 import com
.sun
.star
.table
.CellAddress
;
30 import com
.sun
.star
.table
.XCell
;
31 import com
.sun
.star
.table
.XCellRange
;
32 import com
.sun
.star
.text
.XSimpleText
;
33 import com
.sun
.star
.uno
.AnyConverter
;
34 import com
.sun
.star
.uno
.Type
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
38 import lib
.StatusException
;
40 import lib
.TestEnvironment
;
41 import lib
.TestParameters
;
43 import util
.SOfficeFactory
;
46 import java
.io
.PrintWriter
;
47 import util
.DefaultDsc
;
48 import util
.InstCreator
;
52 * Test for object which represents some text annotation
53 * anchored to some cell in spreadsheet (implement
54 * <code>com.sun.star.sheet.CellAnnotation</code>).<p>
55 * Object implements the following interfaces :
57 * <li> <code>com::sun::star::text::XSimpleText</code></li>
58 * <li> <code>com::sun::star::text::XTextRange</code></li>
59 * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li>
61 * This object test <b> is NOT </b> designed to be run in several
62 * threads concurently.
63 * @see com.sun.star.sheet.CellAnnotation
64 * @see com.sun.star.text.XSimpleText
65 * @see com.sun.star.text.XTextRange
66 * @see com.sun.star.sheet.XSheetAnnotation
67 * @see ifc.text._XSimpleText
68 * @see ifc.text._XTextRange
69 * @see ifc.sheet._XSheetAnnotation
71 public class ScAnnotationShapeObj
extends TestCase
{
72 private XSpreadsheetDocument xSheetDoc
= null;
75 * Creates a spreadsheet document.
77 protected void initialize(TestParameters tParam
, PrintWriter log
) {
79 SOfficeFactory
.getFactory((XMultiServiceFactory
) tParam
83 log
.println("creating a Spreadsheet document");
84 log
.println("Loading: "+utils
.getFullTestURL(
85 "ScAnnotationShapeObj.sxc"));
87 UnoRuntime
.queryInterface(XSpreadsheetDocument
.class,
88 SOF
.loadDocument(utils
.getFullTestURL(
89 "ScAnnotationShapeObj.sxc")));
90 } catch (com
.sun
.star
.uno
.Exception e
) {
91 // Some exception occurs.FAILED
92 e
.printStackTrace(log
);
93 throw new StatusException("Couldn't create document", e
);
98 * Disposes a spreadsheet document.
100 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
101 log
.println(" disposing xSheetDoc ");
104 UnoRuntime
.queryInterface(XComponent
.class,
106 util
.DesktopTools
.closeDoc(oComp
);
110 * Creating a Testenvironment for the interfaces to be tested.
111 * Retrieves a collection of spreadsheets from a document,
112 * and takes one them. Then a single cell is retrieved, and
113 * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code>
114 * interface an annotation is got.
115 * Object relations created :
117 * <li> <code>'CELLPOS'</code> for
118 * {@link ifc.sheet._XSheetAnnotation} (of <code>
119 * com.sun.star.table.CellAddress</code> type) which
120 * contains the annotation cell address.</li>
123 public synchronized TestEnvironment
createTestEnvironment(
124 TestParameters Param
, PrintWriter log
) throws StatusException
{
125 XInterface oObj
= null;
127 // creation of testobject here
128 // first we write what we are intend to do to log file
129 log
.println("Creating a test environment");
131 CellAddress cellPos
= new CellAddress((short) 0, 1, 2);
133 log
.println("Getting test object ");
135 XSpreadsheetDocument xArea
=
136 UnoRuntime
.queryInterface(XSpreadsheetDocument
.class,
138 XSpreadsheets oSheets
= xArea
.getSheets();
140 XIndexAccess XAccess
=
141 UnoRuntime
.queryInterface(XIndexAccess
.class,
146 XSpreadsheet oSheet
=
147 (XSpreadsheet
) AnyConverter
.toObject(new Type(
149 XAccess
.getByIndex(cellPos
.Sheet
));
151 UnoRuntime
.queryInterface(XCellRange
.class,
154 oCRange
.getCellByPosition(cellPos
.Column
, cellPos
.Row
);
155 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
156 e
.printStackTrace(log
);
157 throw new StatusException("Error getting test object from spreadsheet document",
159 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
160 e
.printStackTrace(log
);
161 throw new StatusException("Error getting test object from spreadsheet document",
163 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
164 e
.printStackTrace(log
);
165 throw new StatusException("Error getting test object from spreadsheet document",
169 XSheetAnnotationAnchor oAnnoA
=
170 UnoRuntime
.queryInterface(XSheetAnnotationAnchor
.class,
172 XSheetAnnotation oAnno
= oAnnoA
.getAnnotation();
174 XSimpleText xAnnoText
=
175 UnoRuntime
.queryInterface(XSimpleText
.class,
177 xAnnoText
.setString("ScAnnotationShapeObj");
179 XSheetAnnotationShapeSupplier xSheetAnnotationShapeSupplier
=
180 UnoRuntime
.queryInterface(XSheetAnnotationShapeSupplier
.class,
183 oObj
= xSheetAnnotationShapeSupplier
.getAnnotationShape();
185 log
.println("ImplementationName: "
186 + util
.utils
.getImplName(oObj
));
188 TestEnvironment tEnv
= new TestEnvironment(oObj
);
190 //adding ObjRelation for RotationDescriptor
191 tEnv
.addObjRelation("NoShear", Boolean
.TRUE
);
193 //adding ObjRelation for XText
194 DefaultDsc tDsc
= new DefaultDsc("com.sun.star.text.XTextContent",
195 "com.sun.star.text.TextField.DateTime");
197 log
.println( "adding InstCreator object" );
199 "XTEXTINFO", new InstCreator( xSheetDoc
, tDsc
) );
204 // finish class ScAnnotationShapeObj