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 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.lang
.XComponent
;
30 import com
.sun
.star
.sheet
.XAreaLinks
;
31 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
32 import com
.sun
.star
.table
.CellAddress
;
33 import com
.sun
.star
.uno
.AnyConverter
;
34 import com
.sun
.star
.uno
.Type
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
40 * Test for object which is represented by service
41 * <code>com.sun.star.sheet.CellAreaLinks</code>.
42 * This is a collection aff all links present
43 * in a Spreadsheet document.
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
47 * <li> <code>com::sun::star::container::XElementAccess</code></li>
48 * <li> <code>com::sun::star::sheet::XAreaLinks</code></li>
50 * This object test <b> is NOT </b> designed to be run in several
51 * threads concurently.
52 * @see com.sun.star.container.XIndexAccess
53 * @see com.sun.star.container.XElementAccess
54 * @see com.sun.star.sheet.XAreaLinks
55 * @see ifc.container._XIndexAccess
56 * @see ifc.container._XElementAccess
57 * @see ifc.sheet._XAreaLinks
58 * @see com.sun.star.sheet.CellAreaLinks
60 public class ScAreaLinksObj
extends TestCase
{
61 private XSpreadsheetDocument xSheetDoc
= null;
64 * Creates Spreadsheet document.
67 protected void initialize( TestParameters tParam
, PrintWriter log
) {
68 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
71 log
.println( "creating a Spreadsheet document" );
72 xSheetDoc
= SOF
.createCalcDoc(null);
73 } catch ( com
.sun
.star
.uno
.Exception e
) {
74 // Some exception occurs.FAILED
75 e
.printStackTrace( log
);
76 throw new StatusException( "Couldn't create document", e
);
82 * Disposes Spreadsheet document.
85 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
86 log
.println( " disposing xSheetDoc " );
87 XComponent oComp
= UnoRuntime
.queryInterface
88 (XComponent
.class, xSheetDoc
) ;
89 util
.DesktopTools
.closeDoc(oComp
);
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Retrieves a collection of Area Links using the 'AreaLinks'
96 * property of the Spreadsheet document. Adds a new link to this
97 * collection, which has a source in the same document. The
98 * link collection is passed as a tested object.
101 public synchronized TestEnvironment createTestEnvironment
102 (TestParameters Param
, PrintWriter log
){
104 XInterface oObj
= null;
105 TestEnvironment tEnv
= null ;
109 // creation of testobject here
110 XPropertySet props
= UnoRuntime
.queryInterface
111 (XPropertySet
.class, xSheetDoc
);
112 oObj
= (XInterface
) AnyConverter
.toObject(
113 new Type(XInterface
.class),props
.getPropertyValue("AreaLinks")) ;
114 XAreaLinks links
= null ;
116 // adding one link into collection (for best testing)
117 links
= UnoRuntime
.queryInterface(XAreaLinks
.class, oObj
) ;
118 CellAddress addr
= new CellAddress ((short) 1,2,3) ;
119 String aSourceArea
= util
.utils
.getFullTestURL("calcshapes.sxc");
120 links
.insertAtPosition (addr
, aSourceArea
, "a2:b5", "", "") ;
122 // creating test environment
123 tEnv
= new TestEnvironment(oObj
);
125 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
126 log
.println ("Exception occurred while creating test Object.") ;
127 e
.printStackTrace(log
) ;
128 throw new StatusException("Couldn't create test object", e
);
129 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
130 log
.println ("Exception occurred while creating test Object.") ;
131 e
.printStackTrace(log
) ;
132 throw new StatusException("Couldn't create test object", e
);
133 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
134 log
.println ("Exception occurred while creating test Object.") ;
135 e
.printStackTrace(log
) ;
136 throw new StatusException("Couldn't create test object", e
);
142 } // finish class ScAreaLinksObj