Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAnnotationShapeObj.java
blobea8f9c32e14ca583a2cf38d1a00e326885a8ac66
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 .
18 package mod._sc;
20 import com.sun.star.container.XIndexAccess;
21 import com.sun.star.lang.XComponent;
22 import com.sun.star.sheet.XSheetAnnotation;
23 import com.sun.star.sheet.XSheetAnnotationAnchor;
24 import com.sun.star.sheet.XSheetAnnotationShapeSupplier;
25 import com.sun.star.sheet.XSpreadsheet;
26 import com.sun.star.sheet.XSpreadsheetDocument;
27 import com.sun.star.sheet.XSpreadsheets;
28 import com.sun.star.table.CellAddress;
29 import com.sun.star.table.XCell;
30 import com.sun.star.table.XCellRange;
31 import com.sun.star.text.XSimpleText;
32 import com.sun.star.uno.AnyConverter;
33 import com.sun.star.uno.Type;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 import lib.StatusException;
38 import lib.TestCase;
39 import lib.TestEnvironment;
40 import lib.TestParameters;
42 import util.SOfficeFactory;
43 import util.utils;
45 import java.io.PrintWriter;
46 import util.DefaultDsc;
47 import util.InstCreator;
50 /**
51 * Test for object which represents some text annotation
52 * anchored to some cell in spreadsheet (implement
53 * <code>com.sun.star.sheet.CellAnnotation</code>).<p>
54 * Object implements the following interfaces :
55 * <ul>
56 * <li> <code>com::sun::star::text::XSimpleText</code></li>
57 * <li> <code>com::sun::star::text::XTextRange</code></li>
58 * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li>
59 * </ul>
60 * This object test <b> is NOT </b> designed to be run in several
61 * threads concurently.
62 * @see com.sun.star.sheet.CellAnnotation
63 * @see com.sun.star.text.XSimpleText
64 * @see com.sun.star.text.XTextRange
65 * @see com.sun.star.sheet.XSheetAnnotation
66 * @see ifc.text._XSimpleText
67 * @see ifc.text._XTextRange
68 * @see ifc.sheet._XSheetAnnotation
70 public class ScAnnotationShapeObj extends TestCase {
71 private XSpreadsheetDocument xSheetDoc = null;
73 /**
74 * Creates a spreadsheet document.
76 @Override
77 protected void initialize(TestParameters tParam, PrintWriter log) {
78 SOfficeFactory SOF =
79 SOfficeFactory.getFactory(tParam
80 .getMSF());
82 try {
83 log.println("creating a Spreadsheet document");
84 log.println("Loading: "+utils.getFullTestURL(
85 "ScAnnotationShapeObj.sxc"));
86 xSheetDoc =
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);
97 /**
98 * Disposes a spreadsheet document.
100 @Override
101 protected void cleanup(TestParameters tParam, PrintWriter log) {
102 log.println(" disposing xSheetDoc ");
104 XComponent oComp =
105 UnoRuntime.queryInterface(XComponent.class,
106 xSheetDoc);
107 util.DesktopTools.closeDoc(oComp);
111 * Creating a Testenvironment for the interfaces to be tested.
112 * Retrieves a collection of spreadsheets from a document,
113 * and takes one them. Then a single cell is retrieved, and
114 * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code>
115 * interface an annotation is got.
116 * Object relations created :
117 * <ul>
118 * <li> <code>'CELLPOS'</code> for
119 * {@link ifc.sheet._XSheetAnnotation} (of <code>
120 * com.sun.star.table.CellAddress</code> type) which
121 * contains the annotation cell address.</li>
122 * </ul>
124 @Override
125 public synchronized TestEnvironment createTestEnvironment(
126 TestParameters Param, PrintWriter log) throws StatusException {
127 XInterface oObj = null;
129 // creation of testobject here
130 // first we write what we are intend to do to log file
131 log.println("Creating a test environment");
133 CellAddress cellPos = new CellAddress((short) 0, 1, 2);
135 log.println("Getting test object ");
137 XSpreadsheetDocument xArea =
138 UnoRuntime.queryInterface(XSpreadsheetDocument.class,
139 xSheetDoc);
140 XSpreadsheets oSheets = xArea.getSheets();
142 XIndexAccess XAccess =
143 UnoRuntime.queryInterface(XIndexAccess.class,
144 oSheets);
145 XCell oCell = null;
147 try {
148 XSpreadsheet oSheet =
149 (XSpreadsheet) AnyConverter.toObject(new Type(
150 XSpreadsheet.class),
151 XAccess.getByIndex(cellPos.Sheet));
152 XCellRange oCRange =
153 UnoRuntime.queryInterface(XCellRange.class,
154 oSheet);
155 oCell =
156 oCRange.getCellByPosition(cellPos.Column, cellPos.Row);
157 } catch (com.sun.star.lang.WrappedTargetException e) {
158 e.printStackTrace(log);
159 throw new StatusException("Error getting test object from spreadsheet document",
161 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
162 e.printStackTrace(log);
163 throw new StatusException("Error getting test object from spreadsheet document",
165 } catch (com.sun.star.lang.IllegalArgumentException e) {
166 e.printStackTrace(log);
167 throw new StatusException("Error getting test object from spreadsheet document",
171 XSheetAnnotationAnchor oAnnoA =
172 UnoRuntime.queryInterface(XSheetAnnotationAnchor.class,
173 oCell);
174 XSheetAnnotation oAnno = oAnnoA.getAnnotation();
176 XSimpleText xAnnoText =
177 UnoRuntime.queryInterface(XSimpleText.class,
178 oAnno);
179 xAnnoText.setString("ScAnnotationShapeObj");
181 XSheetAnnotationShapeSupplier xSheetAnnotationShapeSupplier =
182 UnoRuntime.queryInterface(XSheetAnnotationShapeSupplier.class,
183 oAnno);
185 oObj = xSheetAnnotationShapeSupplier.getAnnotationShape();
187 log.println("ImplementationName: "
188 + util.utils.getImplName(oObj));
190 TestEnvironment tEnv = new TestEnvironment(oObj);
192 //adding ObjRelation for RotationDescriptor
193 tEnv.addObjRelation("NoShear", Boolean.TRUE);
195 //adding ObjRelation for XText
196 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
197 "com.sun.star.text.TextField.DateTime");
199 log.println( "adding InstCreator object" );
200 tEnv.addObjRelation(
201 "XTEXTINFO", new InstCreator( xSheetDoc, tDsc ) );
203 return tEnv;
206 // finish class ScAnnotationShapeObj