1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScIndexEnumeration_DDELinksEnumeration.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
42 import com
.sun
.star
.beans
.XPropertySet
;
43 import com
.sun
.star
.container
.XEnumerationAccess
;
44 import com
.sun
.star
.container
.XIndexAccess
;
45 import com
.sun
.star
.lang
.XComponent
;
46 import com
.sun
.star
.lang
.XMultiServiceFactory
;
47 import com
.sun
.star
.sheet
.XSpreadsheet
;
48 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
49 import com
.sun
.star
.sheet
.XSpreadsheets
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
55 public class ScIndexEnumeration_DDELinksEnumeration
extends TestCase
{
56 static XSpreadsheetDocument xSheetDoc
= null;
57 static XComponent oDoc
= null;
60 * Creates Spreadsheet document.
62 protected void initialize( TestParameters tParam
, PrintWriter log
) {
63 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
66 log
.println( "creating a Spreadsheet document" );
67 xSheetDoc
= SOF
.createCalcDoc(null);
68 } catch ( com
.sun
.star
.uno
.Exception e
) {
69 // Some exception occures.FAILED
70 e
.printStackTrace( log
);
71 throw new StatusException( "Couldn't create document", e
);
77 * Disposes Spreadsheet document and testdocument.
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xSheetDoc " );
81 XComponent oComp
= (XComponent
) UnoRuntime
.
82 queryInterface(XComponent
.class, xSheetDoc
) ;
83 util
.DesktopTools
.closeDoc(oComp
);
84 util
.DesktopTools
.closeDoc(oDoc
);
87 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
89 XInterface oObj
= null;
91 // creation of testobject here
92 // first we write what we are intend to do to log file
93 log
.println( "Creating a test environment" );
95 // create testobject here
97 XMultiServiceFactory oMSF
= (XMultiServiceFactory
)Param
.getMSF();
99 // load the predefined testdocument
100 String testdoc
= utils
.getFullTestURL("ScDDELinksObj.sdc");
102 oDoc
= SOfficeFactory
.getFactory(oMSF
).loadDocument(testdoc
);
103 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
104 e
.printStackTrace(log
);
105 throw new StatusException("Can't load test document", e
);
106 } catch (com
.sun
.star
.io
.IOException e
) {
107 e
.printStackTrace(log
);
108 throw new StatusException("Can't load test document", e
);
109 } catch (com
.sun
.star
.uno
.Exception e
) {
110 e
.printStackTrace(log
);
111 throw new StatusException("Can't load test document", e
);
114 log
.println("getting sheets");
115 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSheetDoc
.getSheets();
117 log
.println("getting a sheet");
118 XSpreadsheet oSheet
= null;
119 XIndexAccess oIndexAccess
= (XIndexAccess
)
120 UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
122 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
123 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
124 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException( "Couldn't get a spreadsheet", e
);
127 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
128 e
.printStackTrace(log
);
129 throw new StatusException( "Couldn't get a spreadsheet", e
);
130 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
131 e
.printStackTrace(log
);
132 throw new StatusException( "Couldn't get a spreadsheet", e
);
135 testdoc
= utils
.getFullTestDocName("ScDDELinksObj.sdc");
136 log
.println("filling some cells");
138 oSheet
.getCellByPosition(5, 5).setFormula(
139 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
140 oSheet
.getCellByPosition(1, 4).setFormula(
141 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
142 oSheet
.getCellByPosition(2, 0).setFormula(
143 "=DDE(\"soffice\";\""+testdoc
+"\";\"Sheet1.A1\"");
144 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
145 e
.printStackTrace(log
);
146 throw new StatusException(
147 "Exception occurred while filling cells", e
);
151 log
.println("Getting test object ") ;
153 // Getting named ranges.
154 XPropertySet docProps
= (XPropertySet
)
155 UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
156 oObj
= (XInterface
)AnyConverter
.toObject(
157 new Type(XInterface
.class),docProps
.getPropertyValue("DDELinks"));
158 log
.println("Creating object - " +
159 ((oObj
== null) ?
"FAILED" : "OK"));
160 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
161 e
.printStackTrace(log
) ;
162 throw new StatusException(
163 "Error getting test object from spreadsheet document", e
) ;
164 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
165 e
.printStackTrace(log
) ;
166 throw new StatusException(
167 "Error getting test object from spreadsheet document", e
) ;
168 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
169 e
.printStackTrace(log
) ;
170 throw new StatusException(
171 "Error getting test object from spreadsheet document", e
) ;
174 XEnumerationAccess ea
= (XEnumerationAccess
)
175 UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
177 oObj
= ea
.createEnumeration();
179 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
180 // creating test environment
181 TestEnvironment tEnv
= new TestEnvironment( oObj
);
183 tEnv
.addObjRelation("ENUM",ea
);