bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAnnotationsObj.java
blobcc6cc28020eee28d1edf8cf173a4994cbae2c1af
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.XSheetAnnotation;
32 import com.sun.star.sheet.XSheetAnnotationAnchor;
33 import com.sun.star.sheet.XSheetAnnotationsSupplier;
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.XCell;
38 import com.sun.star.table.XCellRange;
39 import com.sun.star.text.XSimpleText;
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 a collection of annotations
47 * for a spreadsheet document (implements
48 * <code>com.sun.star.sheet.CellAnnotations</code>). <p>
49 * Object implements the following interfaces :
50 * <ul>
51 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
52 * <li> <code>com::sun::star::container::XElementAccess</code></li>
53 * <li> <code>com::sun::star::sheet::XSheetAnnotations</code></li>
54 * </ul> <p>
55 * This object test <b> is NOT </b> designed to be run in several
56 * threads concurently.
57 * @see com.sun.star.sheet.CellAnnotations
58 * @see com.sun.star.container.XIndexAccess
59 * @see com.sun.star.container.XElementAccess
60 * @see com.sun.star.sheet.XSheetAnnotations
61 * @see ifc.container._XIndexAccess
62 * @see ifc.container._XElementAccess
63 * @see ifc.sheet._XSheetAnnotations
65 public class ScAnnotationsObj extends TestCase {
66 private XSpreadsheetDocument xSheetDoc = null;
68 /**
69 * Creates Spreadsheet document.
71 @Override
72 protected void initialize( TestParameters tParam, PrintWriter log ) {
73 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
75 try {
76 log.println( "creating a Spreadsheet document" );
77 xSheetDoc = SOF.createCalcDoc(null);
78 } catch ( com.sun.star.uno.Exception e ) {
79 // Some exception occurs.FAILED
80 e.printStackTrace( log );
81 throw new StatusException( "Couldn't create document", e );
86 /**
87 * Disposes Spreadsheet document.
89 @Override
90 protected void cleanup( TestParameters tParam, PrintWriter log ) {
91 log.println( " disposing xSheetDoc " );
92 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
93 util.DesktopTools.closeDoc(oComp);
96 /**
97 * Creating a Testenvironment for the interfaces to be tested.
98 * From a document collection of spreadsheets a single one is
99 * retrieved and one annotation is added to it. Then a collection
100 * of annotations is retrieved using spreadsheet's
101 * <code>com.sun.star.sheet.XSheetAnnotationsSupplier</code> interface.
103 @Override
104 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
106 XInterface oObj = null;
108 // creation of testobject here
109 // first we write what we are intend to do to log file
110 log.println( "Creating a test environment" );
112 log.println("Getting test object ") ;
114 XSpreadsheetDocument xSpreadsheetDoc = UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
115 XSpreadsheets sheets = xSpreadsheetDoc.getSheets();
117 XNameAccess oNames = UnoRuntime.queryInterface( XNameAccess.class, sheets );
118 XCell oCell = null;
119 XSpreadsheet oSheet = null;
120 try {
121 oSheet = (XSpreadsheet) AnyConverter.toObject(
122 new Type(XSpreadsheet.class),
123 oNames.getByName(oNames.getElementNames()[0]));
124 // adding an annotation...
125 XCellRange oCRange = UnoRuntime.queryInterface(XCellRange.class, oSheet);
126 oCell = oCRange.getCellByPosition(10,10);
127 } catch (com.sun.star.lang.WrappedTargetException e) {
128 e.printStackTrace(log);
129 throw new StatusException(
130 "Error getting test object from spreadsheet document",e);
131 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
132 e.printStackTrace(log) ;
133 throw new StatusException(
134 "Error getting test object from spreadsheet document",e) ;
135 } catch (com.sun.star.container.NoSuchElementException e) {
136 e.printStackTrace(log) ;
137 throw new StatusException(
138 "Error getting test object from spreadsheet document",e) ;
139 } catch (com.sun.star.lang.IllegalArgumentException e) {
140 e.printStackTrace(log) ;
141 throw new StatusException(
142 "Error getting test object from spreadsheet document",e) ;
145 XSheetAnnotationAnchor oAnnoA = UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, oCell);
146 XSheetAnnotation oAnno = oAnnoA.getAnnotation();
147 XSimpleText sText = UnoRuntime.queryInterface(XSimpleText.class, oAnno);
148 sText.setString("ScAnnotationsObj");
150 XSheetAnnotationsSupplier supp = UnoRuntime.queryInterface(
151 XSheetAnnotationsSupplier.class, oSheet);
152 oObj = supp.getAnnotations();
154 TestEnvironment tEnv = new TestEnvironment( oObj );
156 return tEnv;
159 } // finish class ScAnnotationsObj