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.
50 protected void initialize( TestParameters tParam
, PrintWriter log
) {
51 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
54 log
.println( "creating a Spreadsheet document" );
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
);
65 * Disposes Spreadsheet document and testdocument.
67 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
68 log
.println( " disposing xSheetDoc " );
69 XComponent oComp
= UnoRuntime
.
70 queryInterface(XComponent
.class, xSheetDoc
) ;
71 util
.DesktopTools
.closeDoc(oComp
);
72 util
.DesktopTools
.closeDoc(oDoc
);
75 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
77 XInterface oObj
= null;
79 // creation of testobject here
80 // first we write what we are intend to do to log file
81 log
.println( "Creating a test environment" );
83 // create testobject here
85 XMultiServiceFactory oMSF
= (XMultiServiceFactory
)Param
.getMSF();
87 // load the predefined testdocument
88 String testdoc
= utils
.getFullTestURL("ScDDELinksObj.ods");
90 oDoc
= SOfficeFactory
.getFactory(oMSF
).loadDocument(testdoc
);
91 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
92 e
.printStackTrace(log
);
93 throw new StatusException("Can't load test document", e
);
94 } catch (com
.sun
.star
.io
.IOException e
) {
95 e
.printStackTrace(log
);
96 throw new StatusException("Can't load test document", e
);
97 } catch (com
.sun
.star
.uno
.Exception e
) {
98 e
.printStackTrace(log
);
99 throw new StatusException("Can't load test document", e
);
102 log
.println("getting sheets");
103 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
105 log
.println("getting a sheet");
106 XSpreadsheet oSheet
= null;
107 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
109 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
110 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
111 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
112 e
.printStackTrace(log
);
113 throw new StatusException( "Couldn't get a spreadsheet", e
);
114 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
115 e
.printStackTrace(log
);
116 throw new StatusException( "Couldn't get a spreadsheet", e
);
117 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
118 e
.printStackTrace(log
);
119 throw new StatusException( "Couldn't get a spreadsheet", e
);
122 testdoc
= utils
.getFullTestDocName("ScDDELinksObj.ods");
123 log
.println("filling some cells");
125 oSheet
.getCellByPosition(5, 5).setFormula(
126 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
127 oSheet
.getCellByPosition(1, 4).setFormula(
128 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
129 oSheet
.getCellByPosition(2, 0).setFormula(
130 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
131 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
132 e
.printStackTrace(log
);
133 throw new StatusException(
134 "Exception occurred while filling cells", e
);
138 log
.println("Getting test object ") ;
140 // Getting named ranges.
141 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
142 oObj
= (XInterface
)AnyConverter
.toObject(
143 new Type(XInterface
.class),docProps
.getPropertyValue("DDELinks"));
144 log
.println("Creating object - " +
145 ((oObj
== null) ?
"FAILED" : "OK"));
146 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
147 e
.printStackTrace(log
) ;
148 throw new StatusException(
149 "Error getting test object from spreadsheet document", e
) ;
150 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
151 e
.printStackTrace(log
) ;
152 throw new StatusException(
153 "Error getting test object from spreadsheet document", e
) ;
154 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
155 e
.printStackTrace(log
) ;
156 throw new StatusException(
157 "Error getting test object from spreadsheet document", e
) ;
160 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
162 oObj
= ea
.createEnumeration();
164 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
165 // creating test environment
166 TestEnvironment tEnv
= new TestEnvironment( oObj
);
168 tEnv
.addObjRelation("ENUM",ea
);