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
.container
.XNameContainer
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
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
;
42 public class ScIndexEnumeration_SheetCellRangesEnumeration
extends TestCase
{
43 private XSpreadsheetDocument xSheetDoc
= null;
46 * Creates Spreadsheet document.
48 protected void initialize( TestParameters tParam
, PrintWriter log
) {
50 // get a soffice factory object
51 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
54 log
.println( "creating a sheetdocument" );
55 xSheetDoc
= SOF
.createCalcDoc(null);
56 } catch (com
.sun
.star
.uno
.Exception e
) {
57 // Some exception occurs.FAILED
58 e
.printStackTrace( log
);
59 throw new StatusException( "Couldn't create document", e
);
64 * Disposes Spreadsheet document.
66 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
67 log
.println( " disposing xSheetDoc " );
69 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
70 util
.DesktopTools
.closeDoc(oComp
);
73 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
75 XInterface oObj
= null;
76 Object oRange
= null ;
78 // creation of testobject here
79 // first we write what we are intend to do to log file
80 log
.println( "Creating a test environment" );
82 // get a soffice factory object
83 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF() );
85 log
.println("Getting test object ");
87 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
90 SOF
.createInstance(oComp
, "com.sun.star.sheet.SheetCellRanges");
92 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
93 XIndexAccess oIndSheets
= UnoRuntime
.queryInterface (XIndexAccess
.class, oSheets
);
94 XSpreadsheet oSheet
= null;
96 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
97 new Type(XSpreadsheet
.class),oIndSheets
.getByIndex(0));
98 XNameContainer oRanges
= UnoRuntime
.queryInterface(XNameContainer
.class, oObj
);
100 oRange
= oSheet
.getCellRangeByName("C1:D4");
101 oRanges
.insertByName("Range1", oRange
);
102 oRange
= oSheet
.getCellRangeByName("E2:F5");
103 oRanges
.insertByName("Range2", oRange
);
104 oRange
= oSheet
.getCellRangeByName("G2:H3");
105 oRanges
.insertByName("Range3", oRange
);
106 oRange
= oSheet
.getCellRangeByName("I7:J8");
107 oRanges
.insertByName("Range4", oRange
);
108 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
109 e
.printStackTrace(log
);
110 throw new StatusException("Couldn't create test object", e
);
111 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
112 e
.printStackTrace(log
);
113 throw new StatusException("Couldn't create test object", e
);
114 } catch(com
.sun
.star
.container
.ElementExistException e
) {
115 e
.printStackTrace(log
);
116 throw new StatusException("Couldn't create test object", e
);
117 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
118 e
.printStackTrace(log
);
119 throw new StatusException("Couldn't create test object", e
);
122 log
.println("filling some cells");
124 for (int i
= 0; i
< 10; i
++) {
125 for (int j
= 0; j
< 5; j
++) {
126 oSheet
.getCellByPosition(i
, j
).setFormula("a");
129 for (int i
= 0; i
< 10; i
++) {
130 for (int j
= 5; j
< 10; j
++) {
131 oSheet
.getCellByPosition(i
, j
).setValue(i
+ j
);
134 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
135 e
.printStackTrace(log
);
136 throw new StatusException (
137 "Exception occurred while filling cells", e
);
140 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
142 oObj
= ea
.createEnumeration();
144 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
145 // creating test environment
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
148 tEnv
.addObjRelation("ENUM",ea
);