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: ScSheetLinksObj.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
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.container
.XIndexAccess
;
43 import com
.sun
.star
.lang
.XComponent
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.sheet
.XSheetLinkable
;
46 import com
.sun
.star
.sheet
.XSpreadsheet
;
47 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
48 import com
.sun
.star
.sheet
.XSpreadsheets
;
49 import com
.sun
.star
.uno
.AnyConverter
;
50 import com
.sun
.star
.uno
.Type
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
52 import com
.sun
.star
.uno
.XInterface
;
55 * Test for object which is represented by service
56 * <code>com.sun.star.sheet.SheetLinks</code>. <p>
57 * Object implements the following interfaces :
59 * <li> <code>com::sun::star::container::XNameAccess</code></li>
60 * <li> <code>com::sun::star::container::XElementAccess</code></li>
62 * @see com.sun.star.sheet.SheetLinks
63 * @see com.sun.star.container.XNameAccess
64 * @see com.sun.star.container.XElementAccess
65 * @see ifc.container._XNameAccess
66 * @see ifc.container._XElementAccess
68 public class ScSheetLinksObj
extends TestCase
{
69 static XSpreadsheetDocument xSheetDoc
= null;
72 * Creates Spreadsheet document.
74 protected void initialize( TestParameters tParam
, PrintWriter log
) {
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
78 log
.println( "creating a Spreadsheet document" );
79 xSheetDoc
= SOF
.createCalcDoc(null);
80 } catch ( com
.sun
.star
.uno
.Exception e
) {
81 // Some exception occures.FAILED
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
88 * Disposes Spreadsheet document.
90 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
91 log
.println( " disposing xSheetDoc " );
92 XComponent oComp
= (XComponent
)
93 UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
) ;
94 util
.DesktopTools
.closeDoc(oComp
);
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Retrieves a collection of spreadsheets from a document
100 * and takes one of them. Links the sheet to another sheet using the
101 * interface <code>XSheetLinkable</code>. Obtains the
102 * value of the property <code>'SheetLinks'</code> that is the collection of
103 * sheet links. This collection is the instance of the service
104 * <code>com.sun.star.sheet.SheetLinks</code>.
105 * @see com.sun.star.sheet.SheetLink
106 * @see com.sun.star.sheet.XSheetLinkable
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" );
115 XSpreadsheet oSheet
= null;
117 log
.println("Getting test object ") ;
118 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
119 XIndexAccess oIndexSheets
= (XIndexAccess
)
120 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
122 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
123 new Type(XSpreadsheet
.class),oIndexSheets
.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 XSheetLinkable SL
= (XSheetLinkable
)
136 UnoRuntime
.queryInterface(XSheetLinkable
.class, oSheet
);
138 // creating link. Doesn't matter that it refers to unexistant object.
139 // this is for proper work of X*Access tests.
140 String aSourceArea
= util
.utils
.getFullTestURL("calcshapes.sxc");
141 SL
.link(aSourceArea
, "Sheet1", "", "",
142 com
.sun
.star
.sheet
.SheetLinkMode
.VALUE
);
145 XPropertySet docProps
= (XPropertySet
)
146 UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
150 links
= docProps
.getPropertyValue("SheetLinks");
151 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
152 e
.printStackTrace(log
);
153 throw new StatusException("Couldn't get SheetLinks", e
);
154 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
155 e
.printStackTrace(log
);
156 throw new StatusException("Couldn't get SheetLinks", e
);
159 oObj
= (XInterface
)UnoRuntime
.queryInterface(XInterface
.class, links
);
161 log
.println("Creating object - " +
162 ((oObj
== null) ?
"FAILED" : "OK"));
164 TestEnvironment tEnv
= new TestEnvironment( oObj
);