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: ScAreaLinkObj.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
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XAreaLinks
;
45 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
46 import com
.sun
.star
.table
.CellAddress
;
47 import com
.sun
.star
.uno
.AnyConverter
;
48 import com
.sun
.star
.uno
.Type
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.uno
.XInterface
;
53 * Test for object which is represented by service
54 * <code>com.sun.star.sheet.CellAreaLink</code>.
55 * This object reflects some cell range (this range
56 * can also be from another saved document) in
57 * any range (of the same size) of the current
59 * Object implements the following interfaces :
61 * <li> <code>com::sun::star::sheet::XAreaLink</code></li>
62 * <li> <code>com::sun::star::util::XRefreshable</code></li>
63 * <li> <code>com::sun::star::sheet::CellAreaLink</code></li>
64 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
66 * This object test <b> is NOT </b> designed to be run in several
67 * threads concurently.
68 * @see com.sun.star.sheet.XAreaLink
69 * @see com.sun.star.util.XRefreshable
70 * @see com.sun.star.sheet.CellAreaLink
71 * @see com.sun.star.beans.XPropertySet
72 * @see ifc.sheet._XAreaLink
73 * @see ifc.util._XRefreshable
74 * @see ifc.sheet._CellAreaLink
75 * @see ifc.beans._XPropertySet
77 public class ScAreaLinkObj
extends TestCase
{
78 static XSpreadsheetDocument xSheetDoc
= null;
81 * Creates Spreadsheet document.
83 protected void initialize( TestParameters tParam
, PrintWriter log
) {
84 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
87 log
.println( "creating a Spreadsheet document" );
88 xSheetDoc
= SOF
.createCalcDoc(null);
89 } catch ( com
.sun
.star
.uno
.Exception e
) {
90 // Some exception occures.FAILED
91 e
.printStackTrace( log
);
92 throw new StatusException( "Couldn't create document", e
);
98 * Disposes Spreadsheet document.
100 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
101 log
.println( " disposing xSheetDoc " );
102 XComponent oComp
= (XComponent
) UnoRuntime
.queryInterface
103 (XComponent
.class, xSheetDoc
) ;
104 util
.DesktopTools
.closeDoc(oComp
);
109 * Creating a Testenvironment for the interfaces to be tested.
110 * Retrieves a collection of Area Links using the 'AreaLinks'
111 * property of the Spreadsheet document. Adds a new link to this
112 * collection, which has a source in the same document. This
113 * link is passed as a tested object.
115 public synchronized TestEnvironment createTestEnvironment
116 ( TestParameters Param
, PrintWriter log
) throws StatusException
{
118 XInterface oObj
= null;
122 // creation of testobject here
123 XPropertySet props
= (XPropertySet
) UnoRuntime
.queryInterface
124 (XPropertySet
.class, xSheetDoc
);
125 XAreaLinks links
= (XAreaLinks
) AnyConverter
.toObject(
126 new Type(XAreaLinks
.class),props
.getPropertyValue("AreaLinks")) ;
127 CellAddress addr
= new CellAddress ((short) 1,2,3) ;
128 String aSourceArea
= util
.utils
.getFullTestURL("calcshapes.sxc");
129 links
.insertAtPosition (addr
, aSourceArea
, "a2:b5", "", "") ;
131 oObj
= (XInterface
) AnyConverter
.toObject(
132 new Type(XInterface
.class), links
.getByIndex(0)) ;
133 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
134 log
.println ("Exception occured while creating test Object.") ;
135 e
.printStackTrace(log
) ;
136 throw new StatusException("Couldn't create test object", e
);
137 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
138 log
.println ("Exception occured while creating test Object.") ;
139 e
.printStackTrace(log
) ;
140 throw new StatusException("Couldn't create test object", e
);
141 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
142 log
.println ("Exception occured while creating test Object.") ;
143 e
.printStackTrace(log
) ;
144 throw new StatusException("Couldn't create test object", e
);
145 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
146 log
.println ("Exception occured while creating test Object.") ;
147 e
.printStackTrace(log
) ;
148 throw new StatusException("Couldn't create test object", e
);
151 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;