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
.XEnumerationAccess
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.sheet
.XSheetAnnotations
;
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
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
43 public class ScIndexEnumeration_CellAnnotationsEnumeration
extends TestCase
{
44 private XSpreadsheetDocument xSheetDoc
= null;
47 * Creates Spreadsheet document.
50 protected void initialize( TestParameters tParam
, PrintWriter log
) {
51 // get a soffice factory object
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
55 log
.println( "creating a sheetdocument" );
56 xSheetDoc
= SOF
.createCalcDoc(null);
57 } catch (com
.sun
.star
.uno
.Exception e
) {
58 // Some exception occurs.FAILED
59 e
.printStackTrace( log
);
60 throw new StatusException( "Couldn't create document", e
);
65 * Disposes Spreadsheet document.
68 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
69 log
.println( " disposing xSheetDoc " );
70 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
71 util
.DesktopTools
.closeDoc(oComp
);
75 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
77 XInterface oObj
= null;
79 log
.println("getting sheets");
80 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
82 log
.println("getting a sheet");
83 XSpreadsheet oSheet
= null;
84 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
86 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
87 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
88 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
89 e
.printStackTrace(log
);
90 throw new StatusException( "Couldn't get a spreadsheet", e
);
91 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
92 e
.printStackTrace(log
);
93 throw new StatusException( "Couldn't get a spreadsheet", e
);
94 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
95 e
.printStackTrace(log
);
96 throw new StatusException( "Couldn't get a spreadsheet", e
);
99 log
.println("filling some cells");
101 oSheet
.getCellByPosition(5, 5).setValue(15);
102 oSheet
.getCellByPosition(1, 4).setValue(10);
103 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
104 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
105 e
.printStackTrace(log
);
106 throw new StatusException(
107 "Exception occurred while filling cells", e
);
110 XSheetAnnotationsSupplier sas
= UnoRuntime
.queryInterface(XSheetAnnotationsSupplier
.class, oSheet
);
112 XSheetAnnotations anno
= sas
.getAnnotations();
113 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class, anno
);
115 oObj
= ea
.createEnumeration();
117 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
119 log
.println("creating a new environment for object");
120 TestEnvironment tEnv
= new TestEnvironment(oObj
);
122 tEnv
.addObjRelation("ENUM",ea
);