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: ScSheetLinkObj.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
.XIndexAccess
;
44 import com
.sun
.star
.container
.XNameAccess
;
45 import com
.sun
.star
.lang
.XComponent
;
46 import com
.sun
.star
.lang
.XMultiServiceFactory
;
47 import com
.sun
.star
.sheet
.XSheetLinkable
;
48 import com
.sun
.star
.sheet
.XSpreadsheet
;
49 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
50 import com
.sun
.star
.sheet
.XSpreadsheets
;
51 import com
.sun
.star
.uno
.AnyConverter
;
52 import com
.sun
.star
.uno
.Type
;
53 import com
.sun
.star
.uno
.UnoRuntime
;
54 import com
.sun
.star
.uno
.XInterface
;
57 * Test for object which is represented by service
58 * <code>com.sun.star.sheet.SheetLink</code>. <p>
59 * Object implements the following interfaces :
61 * <li> <code>com::sun::star::container::XNamed</code></li>
62 * <li> <code>com::sun::star::util::XRefreshable</code></li>
63 * <li> <code>com::sun::star::sheet::SheetLink</code></li>
64 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
66 * The following files used by this test :
68 * <li><b> ScSheetLinksObj.sdc </b> : for creating link </li>
70 * @see com.sun.star.sheet.SheetLink
71 * @see com.sun.star.container.XNamed
72 * @see com.sun.star.util.XRefreshable
73 * @see com.sun.star.sheet.SheetLink
74 * @see com.sun.star.beans.XPropertySet
75 * @see ifc.container._XNamed
76 * @see ifc.util._XRefreshable
77 * @see ifc.sheet._SheetLink
78 * @see ifc.beans._XPropertySet
80 public class ScSheetLinkObj
extends TestCase
{
81 static XSpreadsheetDocument xSheetDoc
= null;
84 * Creates Spreadsheet document.
86 protected void initialize( TestParameters tParam
, PrintWriter log
) {
87 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
90 log
.println( "creating a Spreadsheet document" );
91 xSheetDoc
= SOF
.createCalcDoc(null);
92 } catch ( com
.sun
.star
.uno
.Exception e
) {
93 // Some exception occures.FAILED
94 e
.printStackTrace( log
);
95 throw new StatusException( "Couldn't create document", e
);
100 * Disposes Spreadsheet document.
102 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
103 log
.println( " disposing xSheetDoc " );
104 XComponent oComp
= (XComponent
)
105 UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
);
106 util
.DesktopTools
.closeDoc(oComp
);
110 * Creating a Testenvironment for the interfaces to be tested.
111 * Retrieves a collection of spreadsheets from a document
112 * and takes one of them. Links the sheet to another sheet in another
113 * document using the interface <code>XSheetLinkable</code>. Obtains the
114 * value of the property <code>'SheetLinks'</code> that is the collection of
115 * sheet links. Retrieves from the collection one of the sheet link that
116 * is the instance of the service <code>com.sun.star.sheet.SheetLink</code>.
117 * @see com.sun.star.sheet.SheetLink
118 * @see com.sun.star.sheet.XSheetLinkable
120 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
122 XInterface oObj
= null;
124 // creation of testobject here
125 // first we write what we are intend to do to log file
126 log
.println( "Creating a test environment" );
127 XSpreadsheet oSheet
= null;
129 log
.println("Getting test object ") ;
130 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
131 XIndexAccess oIndexSheets
= (XIndexAccess
)
132 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
134 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
135 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
136 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
137 e
.printStackTrace(log
);
138 throw new StatusException("Couldn't get a spreadsheet", e
);
139 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
140 e
.printStackTrace(log
);
141 throw new StatusException("Couldn't get a spreadsheet", e
);
142 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
143 e
.printStackTrace(log
);
144 throw new StatusException("Couldn't get a spreadsheet", e
);
147 XSheetLinkable SL
= (XSheetLinkable
)
148 UnoRuntime
.queryInterface(XSheetLinkable
.class, oSheet
);
150 // creating link. Doesn't matter that it refers to unexistant object.
151 // this is for proper work of XAccess tests.
152 String sURL
= utils
.getFullTestDocName("ScSheetLinksObj.sdc");
153 SL
.link(sURL
, "Sheet1", "", "", com
.sun
.star
.sheet
.SheetLinkMode
.VALUE
);
156 XPropertySet docProps
= (XPropertySet
)
157 UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
158 Object oLinks
= null;
160 oLinks
= docProps
.getPropertyValue("SheetLinks");
161 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
162 e
.printStackTrace(log
);
163 throw new StatusException("Couldn't get SheetLinks", e
);
164 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
165 e
.printStackTrace(log
);
166 throw new StatusException("Couldn't get SheetLinks", e
);
169 XNameAccess links
= (XNameAccess
)
170 UnoRuntime
.queryInterface(XNameAccess
.class, oLinks
);
172 String
[] names
= links
.getElementNames();
175 oObj
= (XInterface
)AnyConverter
.toObject(
176 new Type(XInterface
.class),links
.getByName(names
[0]));
177 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
178 e
.printStackTrace(log
);
179 throw new StatusException("Couldn't get by name", e
);
180 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
181 e
.printStackTrace(log
);
182 throw new StatusException("Couldn't get by name", e
);
183 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
184 e
.printStackTrace(log
);
185 throw new StatusException("Couldn't get by name", e
);
188 log
.println("Creating object - " +
189 ((oObj
== null) ?
"FAILED" : "OK"));
191 TestEnvironment tEnv
= new TestEnvironment( oObj
);