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
.XNameAccess
;
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
.XSheetAnnotationsSupplier
;
35 import com
.sun
.star
.sheet
.XSpreadsheet
;
36 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
37 import com
.sun
.star
.sheet
.XSpreadsheets
;
38 import com
.sun
.star
.table
.XCell
;
39 import com
.sun
.star
.table
.XCellRange
;
40 import com
.sun
.star
.text
.XSimpleText
;
41 import com
.sun
.star
.uno
.AnyConverter
;
42 import com
.sun
.star
.uno
.Type
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
47 * Test for object which represents a collection of annotations
48 * for a spreadsheet document (implements
49 * <code>com.sun.star.sheet.CellAnnotations</code>). <p>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
53 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * <li> <code>com::sun::star::sheet::XSheetAnnotations</code></li>
56 * This object test <b> is NOT </b> designed to be run in several
57 * threads concurently.
58 * @see com.sun.star.sheet.CellAnnotations
59 * @see com.sun.star.container.XIndexAccess
60 * @see com.sun.star.container.XElementAccess
61 * @see com.sun.star.sheet.XSheetAnnotations
62 * @see ifc.container._XIndexAccess
63 * @see ifc.container._XElementAccess
64 * @see ifc.sheet._XSheetAnnotations
66 public class ScAnnotationsObj
extends TestCase
{
67 private XSpreadsheetDocument xSheetDoc
= null;
70 * Creates Spreadsheet document.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) {
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
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
);
87 * Disposes Spreadsheet document.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xSheetDoc " );
91 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
92 util
.DesktopTools
.closeDoc(oComp
);
96 * Creating a Testenvironment for the interfaces to be tested.
97 * From a document collection of spreadsheets a single one is
98 * retrieved and one annotation is added to it. Then a collection
99 * of annotations is retrieved using spreadsheet's
100 * <code>com.sun.star.sheet.XSheetAnnotationsSupplier</code> interface.
102 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
104 XInterface oObj
= null;
106 // creation of testobject here
107 // first we write what we are intend to do to log file
108 log
.println( "Creating a test environment" );
110 log
.println("Getting test object ") ;
112 XSpreadsheetDocument xSpreadsheetDoc
= UnoRuntime
.queryInterface(XSpreadsheetDocument
.class, xSheetDoc
);
113 XSpreadsheets sheets
= xSpreadsheetDoc
.getSheets();
115 XNameAccess oNames
= UnoRuntime
.queryInterface( XNameAccess
.class, sheets
);
117 XSpreadsheet oSheet
= null;
119 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
120 new Type(XSpreadsheet
.class),
121 oNames
.getByName(oNames
.getElementNames()[0]));
122 // adding an annotation...
123 XCellRange oCRange
= UnoRuntime
.queryInterface(XCellRange
.class, oSheet
);
124 oCell
= oCRange
.getCellByPosition(10,10);
125 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
126 e
.printStackTrace(log
);
127 throw new StatusException(
128 "Error getting test object from spreadsheet document",e
);
129 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
130 e
.printStackTrace(log
) ;
131 throw new StatusException(
132 "Error getting test object from spreadsheet document",e
) ;
133 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
134 e
.printStackTrace(log
) ;
135 throw new StatusException(
136 "Error getting test object from spreadsheet document",e
) ;
137 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
138 e
.printStackTrace(log
) ;
139 throw new StatusException(
140 "Error getting test object from spreadsheet document",e
) ;
143 XSheetAnnotationAnchor oAnnoA
= UnoRuntime
.queryInterface(XSheetAnnotationAnchor
.class, oCell
);
144 XSheetAnnotation oAnno
= oAnnoA
.getAnnotation();
145 XSimpleText sText
= UnoRuntime
.queryInterface(XSimpleText
.class, oAnno
);
146 sText
.setString("ScAnnotationsObj");
148 XSheetAnnotationsSupplier supp
= UnoRuntime
.queryInterface(
149 XSheetAnnotationsSupplier
.class, oSheet
);
150 oObj
= supp
.getAnnotations();
152 TestEnvironment tEnv
= new TestEnvironment( oObj
);
157 } // finish class ScAnnotationsObj