Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_SheetCellRangesEnumeration.java
blob6e94cb597870922cf0932542f8aa6bd3fc7db07a
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.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.sheet.XSpreadsheet;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.sheet.XSpreadsheets;
36 import com.sun.star.uno.AnyConverter;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 public class ScIndexEnumeration_SheetCellRangesEnumeration extends TestCase {
42 private XSpreadsheetDocument xSheetDoc = null;
44 /**
45 * Creates Spreadsheet document.
47 @Override
48 protected void initialize( TestParameters tParam, PrintWriter log ) {
50 // get a soffice factory object
51 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
53 try {
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 );
63 /**
64 * Disposes Spreadsheet document.
66 @Override
67 protected void cleanup( TestParameters tParam, PrintWriter log ) {
68 log.println( " disposing xSheetDoc " );
69 XComponent oComp =
70 UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
71 util.DesktopTools.closeDoc(oComp);
74 @Override
75 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
77 XInterface oObj = null;
78 Object oRange = null ;
80 // creation of testobject here
81 // first we write what we are intend to do to log file
82 log.println( "Creating a test environment" );
84 // get a soffice factory object
85 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF() );
87 log.println("Getting test object ");
89 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
91 oObj = (XInterface)
92 SOF.createInstance(oComp, "com.sun.star.sheet.SheetCellRanges");
94 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
95 XIndexAccess oIndSheets = UnoRuntime.queryInterface (XIndexAccess.class, oSheets);
96 XSpreadsheet oSheet = null;
97 try {
98 oSheet = (XSpreadsheet) AnyConverter.toObject(
99 new Type(XSpreadsheet.class),oIndSheets.getByIndex(0));
100 XNameContainer oRanges = UnoRuntime.queryInterface(XNameContainer.class, oObj);
102 oRange = oSheet.getCellRangeByName("C1:D4");
103 oRanges.insertByName("Range1", oRange);
104 oRange = oSheet.getCellRangeByName("E2:F5");
105 oRanges.insertByName("Range2", oRange);
106 oRange = oSheet.getCellRangeByName("G2:H3");
107 oRanges.insertByName("Range3", oRange);
108 oRange = oSheet.getCellRangeByName("I7:J8");
109 oRanges.insertByName("Range4", oRange);
110 } catch(com.sun.star.lang.WrappedTargetException e) {
111 e.printStackTrace(log);
112 throw new StatusException("Couldn't create test object", e);
113 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
114 e.printStackTrace(log);
115 throw new StatusException("Couldn't create test object", e);
116 } catch(com.sun.star.container.ElementExistException e) {
117 e.printStackTrace(log);
118 throw new StatusException("Couldn't create test object", e);
119 } catch(com.sun.star.lang.IllegalArgumentException e) {
120 e.printStackTrace(log);
121 throw new StatusException("Couldn't create test object", e);
124 log.println("filling some cells");
125 try {
126 for (int i = 0; i < 10; i++) {
127 for (int j = 0; j < 5; j++) {
128 oSheet.getCellByPosition(i, j).setFormula("a");
131 for (int i = 0; i < 10; i++) {
132 for (int j = 5; j < 10; j++) {
133 oSheet.getCellByPosition(i, j).setValue(i + j);
136 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
137 e.printStackTrace(log);
138 throw new StatusException (
139 "Exception occurred while filling cells", e);
142 XEnumerationAccess ea = UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
144 oObj = ea.createEnumeration();
146 log.println("ImplementationName: "+util.utils.getImplName(oObj));
147 // creating test environment
148 TestEnvironment tEnv = new TestEnvironment( oObj );
150 tEnv.addObjRelation("ENUM",ea);
152 return tEnv ;