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
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.sheet
.XAreaLinks
;
32 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
33 import com
.sun
.star
.table
.CellAddress
;
34 import com
.sun
.star
.uno
.AnyConverter
;
35 import com
.sun
.star
.uno
.Type
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
40 * Test for object which is represented by service
41 * <code>com.sun.star.sheet.CellAreaLink</code>.
42 * This object reflects some cell range (this range
43 * can also be from another saved document) in
44 * any range (of the same size) of the current
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::sheet::XAreaLink</code></li>
49 * <li> <code>com::sun::star::util::XRefreshable</code></li>
50 * <li> <code>com::sun::star::sheet::CellAreaLink</code></li>
51 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
53 * This object test <b> is NOT </b> designed to be run in several
54 * threads concurently.
55 * @see com.sun.star.sheet.XAreaLink
56 * @see com.sun.star.util.XRefreshable
57 * @see com.sun.star.sheet.CellAreaLink
58 * @see com.sun.star.beans.XPropertySet
59 * @see ifc.sheet._XAreaLink
60 * @see ifc.util._XRefreshable
61 * @see ifc.sheet._CellAreaLink
62 * @see ifc.beans._XPropertySet
64 public class ScAreaLinkObj
extends TestCase
{
65 private XSpreadsheetDocument xSheetDoc
= null;
68 * Creates Spreadsheet document.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
75 log
.println( "creating a Spreadsheet document" );
76 xSheetDoc
= SOF
.createCalcDoc(null);
77 } catch ( com
.sun
.star
.uno
.Exception e
) {
78 // Some exception occurs.FAILED
79 e
.printStackTrace( log
);
80 throw new StatusException( "Couldn't create document", e
);
86 * Disposes Spreadsheet document.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xSheetDoc " );
91 XComponent oComp
= UnoRuntime
.queryInterface
92 (XComponent
.class, xSheetDoc
) ;
93 util
.DesktopTools
.closeDoc(oComp
);
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Retrieves a collection of Area Links using the 'AreaLinks'
100 * property of the Spreadsheet document. Adds a new link to this
101 * collection, which has a source in the same document. This
102 * link is passed as a tested object.
105 public synchronized TestEnvironment createTestEnvironment
106 ( TestParameters Param
, PrintWriter log
) throws StatusException
{
108 XInterface oObj
= null;
112 // creation of testobject here
113 XPropertySet props
= UnoRuntime
.queryInterface
114 (XPropertySet
.class, xSheetDoc
);
115 XAreaLinks links
= (XAreaLinks
) AnyConverter
.toObject(
116 new Type(XAreaLinks
.class),props
.getPropertyValue("AreaLinks")) ;
117 CellAddress addr
= new CellAddress ((short) 1,2,3) ;
118 String aSourceArea
= util
.utils
.getFullTestURL("calcshapes.sxc");
119 links
.insertAtPosition (addr
, aSourceArea
, "a2:b5", "", "") ;
121 oObj
= (XInterface
) AnyConverter
.toObject(
122 new Type(XInterface
.class), links
.getByIndex(0)) ;
123 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
124 log
.println ("Exception occurred while creating test Object.") ;
125 e
.printStackTrace(log
) ;
126 throw new StatusException("Couldn't create test object", e
);
127 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
128 log
.println ("Exception occurred while creating test Object.") ;
129 e
.printStackTrace(log
) ;
130 throw new StatusException("Couldn't create test object", e
);
131 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
132 log
.println ("Exception occurred while creating test Object.") ;
133 e
.printStackTrace(log
) ;
134 throw new StatusException("Couldn't create test object", e
);
135 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
136 log
.println ("Exception occurred while creating test Object.") ;
137 e
.printStackTrace(log
) ;
138 throw new StatusException("Couldn't create test object", e
);
141 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;