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
.XIndexAccess
;
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
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.sheet.DDELinks</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::container::XNameAccess</code></li>
48 * <li> <code>com::sun::star::container::XElementAccess</code></li>
50 * The following files used by this test :
52 * <li><b> ScDDELinksObj.ods </b> : the predefined testdocument </li>
54 * @see com.sun.star.sheet.DDELinks
55 * @see com.sun.star.container.XNameAccess
56 * @see com.sun.star.container.XElementAccess
57 * @see ifc.container._XNameAccess
58 * @see ifc.container._XElementAccess
60 public class ScDDELinksObj
extends TestCase
{
61 private XSpreadsheetDocument xSheetDoc
= null;
62 static XComponent oDoc
= null;
65 * Creates Spreadsheet document.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) {
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
72 log
.println( "creating a Spreadsheet document" );
73 xSheetDoc
= SOF
.createCalcDoc(null);
74 } catch ( com
.sun
.star
.uno
.Exception e
) {
75 // Some exception occurs.FAILED
76 e
.printStackTrace( log
);
77 throw new StatusException( "Couldn't create document", e
);
83 * Disposes Spreadsheet document and testdocument.
86 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
87 log
.println( " disposing xSheetDoc " );
88 XComponent oComp
= UnoRuntime
.
89 queryInterface(XComponent
.class, xSheetDoc
) ;
90 util
.DesktopTools
.closeDoc(oComp
);
91 util
.DesktopTools
.closeDoc(oDoc
);
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Disposes the testdocument if it was loaded already.
97 * Creates an instance of the <code>com.sun.star.frame.Desktop</code>
98 * and loads the predefined testdocument. Retrieves a collection of
99 * spreadsheets from a document and takes one of them. Sets specific formula
100 * to some cells in the spreadsheet(the formula specify DDE links to the
101 * testdocument). Retrieves the collection of DDE links in the document.
102 * The retrieved collection of DDE link is the instance of the service
103 * <code>com.sun.star.sheet.DDELinks</code>.
104 * @see com.sun.star.frame.Desktop
105 * @see com.sun.star.sheet.DDELinks
108 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
110 XInterface oObj
= null;
112 // creation of testobject here
113 // first we write what we are intend to do to log file
114 log
.println( "Creating a test environment" );
116 // create testobject here
118 XMultiServiceFactory oMSF
= Param
.getMSF();
120 // load the predefined testdocument
121 String testdoc
= utils
.getFullTestURL("ScDDELinksObj.ods");
123 oDoc
= SOfficeFactory
.getFactory(oMSF
).loadDocument(testdoc
);
124 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException("Can't load test document", e
);
127 } catch (com
.sun
.star
.io
.IOException e
) {
128 e
.printStackTrace(log
);
129 throw new StatusException("Can't load test document", e
);
130 } catch (com
.sun
.star
.uno
.Exception e
) {
131 e
.printStackTrace(log
);
132 throw new StatusException("Can't load test document", e
);
135 log
.println("getting sheets");
136 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
138 log
.println("getting a sheet");
139 XSpreadsheet oSheet
= null;
140 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
142 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
143 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
144 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
145 e
.printStackTrace(log
);
146 throw new StatusException("Couldn't get a spreadsheet", e
);
147 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
148 e
.printStackTrace(log
);
149 throw new StatusException("Couldn't get a spreadsheet", e
);
150 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
151 e
.printStackTrace(log
);
152 throw new StatusException("Couldn't get a spreadsheet", e
);
155 testdoc
= utils
.getFullTestDocName("ScDDELinksObj.ods");
156 log
.println("filling some cells");
158 oSheet
.getCellByPosition(5, 5).setFormula(
159 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
160 oSheet
.getCellByPosition(1, 4).setFormula(
161 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
162 oSheet
.getCellByPosition(2, 0).setFormula(
163 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
164 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
165 e
.printStackTrace(log
);
166 throw new StatusException(
167 "Exception occurred while filling cells", e
);
171 log
.println("Getting test object ") ;
173 // Getting named ranges.
174 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
175 oObj
= (XInterface
)AnyConverter
.toObject(
176 new Type(XInterface
.class),docProps
.getPropertyValue("DDELinks"));
177 log
.println("Creating object - " +
178 ((oObj
== null) ?
"FAILED" : "OK"));
179 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
180 e
.printStackTrace(log
) ;
181 throw new StatusException(
182 "Error getting test object from spreadsheet document", e
) ;
183 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
184 e
.printStackTrace(log
) ;
185 throw new StatusException(
186 "Error getting test object from spreadsheet document", e
) ;
187 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
188 e
.printStackTrace(log
) ;
189 throw new StatusException(
190 "Error getting test object from spreadsheet document", e
) ;
193 TestEnvironment tEnv
= new TestEnvironment( oObj
);