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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.container
.XNameAccess
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.sheet
.XSheetLinkable
;
34 import com
.sun
.star
.sheet
.XSpreadsheet
;
35 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
36 import com
.sun
.star
.sheet
.XSpreadsheets
;
37 import com
.sun
.star
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.sheet.SheetLink</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::container::XNamed</code></li>
48 * <li> <code>com::sun::star::util::XRefreshable</code></li>
49 * <li> <code>com::sun::star::sheet::SheetLink</code></li>
50 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
52 * The following files used by this test :
54 * <li><b> ScSheetLinksObj.sdc </b> : for creating link </li>
56 * @see com.sun.star.sheet.SheetLink
57 * @see com.sun.star.container.XNamed
58 * @see com.sun.star.util.XRefreshable
59 * @see com.sun.star.sheet.SheetLink
60 * @see com.sun.star.beans.XPropertySet
61 * @see ifc.container._XNamed
62 * @see ifc.util._XRefreshable
63 * @see ifc.sheet._SheetLink
64 * @see ifc.beans._XPropertySet
66 public class ScSheetLinkObj
extends TestCase
{
67 private XSpreadsheetDocument xSheetDoc
= null;
70 * Creates Spreadsheet document.
73 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
74 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
76 log
.println( "creating a Spreadsheet document" );
77 xSheetDoc
= SOF
.createCalcDoc(null);
81 * Disposes Spreadsheet document.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xSheetDoc " );
86 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
);
87 util
.DesktopTools
.closeDoc(oComp
);
91 * Creating a TestEnvironment for the interfaces to be tested.
92 * Retrieves a collection of spreadsheets from a document
93 * and takes one of them. Links the sheet to another sheet in another
94 * document using the interface <code>XSheetLinkable</code>. Obtains the
95 * value of the property <code>'SheetLinks'</code> that is the collection of
96 * sheet links. Retrieves from the collection one of the sheet link that
97 * is the instance of the service <code>com.sun.star.sheet.SheetLink</code>.
98 * @see com.sun.star.sheet.SheetLink
99 * @see com.sun.star.sheet.XSheetLinkable
102 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
104 XInterface oObj
= null;
106 // creation of testobject here
107 // first we write what we are intend to do to log file
108 log
.println( "Creating a test environment" );
109 XSpreadsheet oSheet
= null;
111 log
.println("Getting test object ") ;
112 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
113 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
114 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
115 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
117 XSheetLinkable SL
= UnoRuntime
.queryInterface(XSheetLinkable
.class, oSheet
);
119 // creating link. Doesn't matter that it refers to unexistent object.
120 // this is for proper work of XAccess tests.
121 String sURL
= utils
.getFullTestDocName("ScSheetLinksObj.ods");
122 SL
.link(sURL
, "Sheet1", "", "", com
.sun
.star
.sheet
.SheetLinkMode
.VALUE
);
125 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
126 Object oLinks
= docProps
.getPropertyValue("SheetLinks");
128 XNameAccess links
= UnoRuntime
.queryInterface(XNameAccess
.class, oLinks
);
130 String
[] names
= links
.getElementNames();
132 oObj
= (XInterface
)AnyConverter
.toObject(
133 new Type(XInterface
.class),links
.getByName(names
[0]));
135 log
.println("Creating object - " +
136 ((oObj
== null) ?
"FAILED" : "OK"));
138 TestEnvironment tEnv
= new TestEnvironment( oObj
);