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.
67 protected void initialize( TestParameters tParam
, PrintWriter log
) {
68 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
71 log
.println( "creating a Spreadsheet document" );
72 xSheetDoc
= SOF
.createCalcDoc(null);
73 } catch ( com
.sun
.star
.uno
.Exception e
) {
74 // Some exception occurs.FAILED
75 e
.printStackTrace( log
);
76 throw new StatusException( "Couldn't create document", e
);
82 * Disposes Spreadsheet document and testdocument.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xSheetDoc " );
86 XComponent oComp
= UnoRuntime
.
87 queryInterface(XComponent
.class, xSheetDoc
) ;
88 util
.DesktopTools
.closeDoc(oComp
);
89 util
.DesktopTools
.closeDoc(oDoc
);
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Disposes the testdocument if it was loaded already.
95 * Creates an instance of the <code>com.sun.star.frame.Desktop</code>
96 * and loads the predefined testdocument. Retrieves a collection of
97 * spreadsheets from a document and takes one of them. Sets specific formula
98 * to some cells in the spreadsheet(the formula specify DDE links to the
99 * testdocument). Retrieves the collection of DDE links in the document.
100 * The retrived collection of DDE link is the instance of the service
101 * <code>com.sun.star.sheet.DDELinks</code>.
102 * @see com.sun.star.frame.Desktop
103 * @see com.sun.star.sheet.DDELinks
105 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
107 XInterface oObj
= null;
109 // creation of testobject here
110 // first we write what we are intend to do to log file
111 log
.println( "Creating a test environment" );
113 // create testobject here
115 XMultiServiceFactory oMSF
= (XMultiServiceFactory
)Param
.getMSF();
117 // load the predefined testdocument
118 String testdoc
= utils
.getFullTestURL("ScDDELinksObj.ods");
120 oDoc
= SOfficeFactory
.getFactory(oMSF
).loadDocument(testdoc
);
121 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException("Can't load test document", e
);
124 } catch (com
.sun
.star
.io
.IOException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException("Can't load test document", e
);
127 } catch (com
.sun
.star
.uno
.Exception e
) {
128 e
.printStackTrace(log
);
129 throw new StatusException("Can't load test document", e
);
132 log
.println("getting sheets");
133 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
135 log
.println("getting a sheet");
136 XSpreadsheet oSheet
= null;
137 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
139 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
140 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
141 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException("Couldn't get a spreadsheet", e
);
144 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
145 e
.printStackTrace(log
);
146 throw new StatusException("Couldn't get a spreadsheet", e
);
147 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
148 e
.printStackTrace(log
);
149 throw new StatusException("Couldn't get a spreadsheet", e
);
152 testdoc
= utils
.getFullTestDocName("ScDDELinksObj.ods");
153 log
.println("filling some cells");
155 oSheet
.getCellByPosition(5, 5).setFormula(
156 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
157 oSheet
.getCellByPosition(1, 4).setFormula(
158 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
159 oSheet
.getCellByPosition(2, 0).setFormula(
160 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
161 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
162 e
.printStackTrace(log
);
163 throw new StatusException(
164 "Exception occurred while filling cells", e
);
168 log
.println("Getting test object ") ;
170 // Getting named ranges.
171 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
172 oObj
= (XInterface
)AnyConverter
.toObject(
173 new Type(XInterface
.class),docProps
.getPropertyValue("DDELinks"));
174 log
.println("Creating object - " +
175 ((oObj
== null) ?
"FAILED" : "OK"));
176 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
177 e
.printStackTrace(log
) ;
178 throw new StatusException(
179 "Error getting test object from spreadsheet document", e
) ;
180 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
181 e
.printStackTrace(log
) ;
182 throw new StatusException(
183 "Error getting test object from spreadsheet document", e
) ;
184 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
185 e
.printStackTrace(log
) ;
186 throw new StatusException(
187 "Error getting test object from spreadsheet document", e
) ;
190 TestEnvironment tEnv
= new TestEnvironment( oObj
);