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
;
30 import com
.sun
.star
.beans
.XPropertySet
;
31 import com
.sun
.star
.container
.XEnumerationAccess
;
32 import com
.sun
.star
.container
.XIndexAccess
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
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
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
43 public class ScIndexEnumeration_DDELinksEnumeration
extends TestCase
{
44 private XSpreadsheetDocument xSheetDoc
= null;
45 static XComponent oDoc
= null;
48 * Creates Spreadsheet document.
51 protected void initialize( TestParameters tParam
, PrintWriter log
) {
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
55 log
.println( "creating a Spreadsheet document" );
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
);
66 * Disposes Spreadsheet document and testdocument.
69 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
70 log
.println( " disposing xSheetDoc " );
71 XComponent oComp
= UnoRuntime
.
72 queryInterface(XComponent
.class, xSheetDoc
) ;
73 util
.DesktopTools
.closeDoc(oComp
);
74 util
.DesktopTools
.closeDoc(oDoc
);
78 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
80 XInterface oObj
= null;
82 // creation of testobject here
83 // first we write what we are intend to do to log file
84 log
.println( "Creating a test environment" );
86 // create testobject here
88 XMultiServiceFactory oMSF
= Param
.getMSF();
90 // load the predefined testdocument
91 String testdoc
= utils
.getFullTestURL("ScDDELinksObj.ods");
93 oDoc
= SOfficeFactory
.getFactory(oMSF
).loadDocument(testdoc
);
94 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
95 e
.printStackTrace(log
);
96 throw new StatusException("Can't load test document", e
);
97 } catch (com
.sun
.star
.io
.IOException e
) {
98 e
.printStackTrace(log
);
99 throw new StatusException("Can't load test document", e
);
100 } catch (com
.sun
.star
.uno
.Exception e
) {
101 e
.printStackTrace(log
);
102 throw new StatusException("Can't load test document", e
);
105 log
.println("getting sheets");
106 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
108 log
.println("getting a sheet");
109 XSpreadsheet oSheet
= null;
110 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
112 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
113 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
114 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
115 e
.printStackTrace(log
);
116 throw new StatusException( "Couldn't get a spreadsheet", e
);
117 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
118 e
.printStackTrace(log
);
119 throw new StatusException( "Couldn't get a spreadsheet", e
);
120 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
121 e
.printStackTrace(log
);
122 throw new StatusException( "Couldn't get a spreadsheet", e
);
125 testdoc
= utils
.getFullTestDocName("ScDDELinksObj.ods");
126 log
.println("filling some cells");
128 oSheet
.getCellByPosition(5, 5).setFormula(
129 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
130 oSheet
.getCellByPosition(1, 4).setFormula(
131 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
132 oSheet
.getCellByPosition(2, 0).setFormula(
133 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
134 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
135 e
.printStackTrace(log
);
136 throw new StatusException(
137 "Exception occurred while filling cells", e
);
141 log
.println("Getting test object ") ;
143 // Getting named ranges.
144 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
145 oObj
= (XInterface
)AnyConverter
.toObject(
146 new Type(XInterface
.class),docProps
.getPropertyValue("DDELinks"));
147 log
.println("Creating object - " +
148 ((oObj
== null) ?
"FAILED" : "OK"));
149 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
150 e
.printStackTrace(log
) ;
151 throw new StatusException(
152 "Error getting test object from spreadsheet document", e
) ;
153 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
154 e
.printStackTrace(log
) ;
155 throw new StatusException(
156 "Error getting test object from spreadsheet document", e
) ;
157 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
158 e
.printStackTrace(log
) ;
159 throw new StatusException(
160 "Error getting test object from spreadsheet document", e
) ;
163 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
165 oObj
= ea
.createEnumeration();
167 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
168 // creating test environment
169 TestEnvironment tEnv
= new TestEnvironment( oObj
);
171 tEnv
.addObjRelation("ENUM",ea
);