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
;
30 import com
.sun
.star
.beans
.XPropertySet
;
31 import com
.sun
.star
.container
.XIndexAccess
;
32 import com
.sun
.star
.container
.XNameAccess
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.sheet
.XSheetLinkable
;
36 import com
.sun
.star
.sheet
.XSpreadsheet
;
37 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
38 import com
.sun
.star
.sheet
.XSpreadsheets
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.sheet.SheetLink</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::container::XNamed</code></li>
50 * <li> <code>com::sun::star::util::XRefreshable</code></li>
51 * <li> <code>com::sun::star::sheet::SheetLink</code></li>
52 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
54 * The following files used by this test :
56 * <li><b> ScSheetLinksObj.sdc </b> : for creating link </li>
58 * @see com.sun.star.sheet.SheetLink
59 * @see com.sun.star.container.XNamed
60 * @see com.sun.star.util.XRefreshable
61 * @see com.sun.star.sheet.SheetLink
62 * @see com.sun.star.beans.XPropertySet
63 * @see ifc.container._XNamed
64 * @see ifc.util._XRefreshable
65 * @see ifc.sheet._SheetLink
66 * @see ifc.beans._XPropertySet
68 public class ScSheetLinkObj
extends TestCase
{
69 private 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 occurs.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
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
);
93 util
.DesktopTools
.closeDoc(oComp
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Retrieves a collection of spreadsheets from a document
99 * and takes one of them. Links the sheet to another sheet in another
100 * document using the interface <code>XSheetLinkable</code>. Obtains the
101 * value of the property <code>'SheetLinks'</code> that is the collection of
102 * sheet links. Retrieves from the collection one of the sheet link that
103 * is the instance of the service <code>com.sun.star.sheet.SheetLink</code>.
104 * @see com.sun.star.sheet.SheetLink
105 * @see com.sun.star.sheet.XSheetLinkable
107 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
109 XInterface oObj
= null;
111 // creation of testobject here
112 // first we write what we are intend to do to log file
113 log
.println( "Creating a test environment" );
114 XSpreadsheet oSheet
= null;
116 log
.println("Getting test object ") ;
117 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
118 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
120 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
121 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
122 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
123 e
.printStackTrace(log
);
124 throw new StatusException("Couldn't get a spreadsheet", e
);
125 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
126 e
.printStackTrace(log
);
127 throw new StatusException("Couldn't get a spreadsheet", e
);
128 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
129 e
.printStackTrace(log
);
130 throw new StatusException("Couldn't get a spreadsheet", e
);
133 XSheetLinkable SL
= UnoRuntime
.queryInterface(XSheetLinkable
.class, oSheet
);
135 // creating link. Doesn't matter that it refers to unexistant object.
136 // this is for proper work of XAccess tests.
137 String sURL
= utils
.getFullTestDocName("ScSheetLinksObj.ods");
138 SL
.link(sURL
, "Sheet1", "", "", com
.sun
.star
.sheet
.SheetLinkMode
.VALUE
);
141 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
142 Object oLinks
= null;
144 oLinks
= docProps
.getPropertyValue("SheetLinks");
145 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
146 e
.printStackTrace(log
);
147 throw new StatusException("Couldn't get SheetLinks", e
);
148 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
149 e
.printStackTrace(log
);
150 throw new StatusException("Couldn't get SheetLinks", e
);
153 XNameAccess links
= UnoRuntime
.queryInterface(XNameAccess
.class, oLinks
);
155 String
[] names
= links
.getElementNames();
158 oObj
= (XInterface
)AnyConverter
.toObject(
159 new Type(XInterface
.class),links
.getByName(names
[0]));
160 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
161 e
.printStackTrace(log
);
162 throw new StatusException("Couldn't get by name", e
);
163 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
164 e
.printStackTrace(log
);
165 throw new StatusException("Couldn't get by name", e
);
166 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
167 e
.printStackTrace(log
);
168 throw new StatusException("Couldn't get by name", e
);
171 log
.println("Creating object - " +
172 ((oObj
== null) ?
"FAILED" : "OK"));
174 TestEnvironment tEnv
= new TestEnvironment( oObj
);