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
.container
.XIndexAccess
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.sheet
.XSheetLinkable
;
33 import com
.sun
.star
.sheet
.XSpreadsheet
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.sheet
.XSpreadsheets
;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.sheet.SheetLinks</code>. <p>
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::container::XNameAccess</code></li>
47 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * @see com.sun.star.sheet.SheetLinks
50 * @see com.sun.star.container.XNameAccess
51 * @see com.sun.star.container.XElementAccess
52 * @see ifc.container._XNameAccess
53 * @see ifc.container._XElementAccess
55 public class ScSheetLinksObj
extends TestCase
{
56 private XSpreadsheetDocument xSheetDoc
= null;
59 * Creates Spreadsheet document.
62 protected void initialize( TestParameters tParam
, PrintWriter log
) {
63 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
66 log
.println( "creating a Spreadsheet document" );
67 xSheetDoc
= SOF
.createCalcDoc(null);
68 } catch ( com
.sun
.star
.uno
.Exception e
) {
69 // Some exception occurs.FAILED
70 e
.printStackTrace( log
);
71 throw new StatusException( "Couldn't create document", e
);
76 * Disposes Spreadsheet document.
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xSheetDoc " );
81 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
) ;
82 util
.DesktopTools
.closeDoc(oComp
);
86 * Creating a Testenvironment for the interfaces to be tested.
87 * Retrieves a collection of spreadsheets from a document
88 * and takes one of them. Links the sheet to another sheet using the
89 * interface <code>XSheetLinkable</code>. Obtains the
90 * value of the property <code>'SheetLinks'</code> that is the collection of
91 * sheet links. This collection is the instance of the service
92 * <code>com.sun.star.sheet.SheetLinks</code>.
93 * @see com.sun.star.sheet.SheetLink
94 * @see com.sun.star.sheet.XSheetLinkable
97 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
99 XInterface oObj
= null;
101 // creation of testobject here
102 // first we write what we are intend to do to log file
103 log
.println( "Creating a test environment" );
104 XSpreadsheet oSheet
= null;
106 log
.println("Getting test object ") ;
107 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
108 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
110 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
111 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
112 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
113 e
.printStackTrace(log
);
114 throw new StatusException("Couldn't get a spreadsheet", e
);
115 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
116 e
.printStackTrace(log
);
117 throw new StatusException("Couldn't get a spreadsheet", e
);
118 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
119 e
.printStackTrace(log
);
120 throw new StatusException("Couldn't get a spreadsheet", e
);
123 XSheetLinkable SL
= UnoRuntime
.queryInterface(XSheetLinkable
.class, oSheet
);
125 // creating link. Doesn't matter that it refers to unexistant object.
126 // this is for proper work of X*Access tests.
127 String aSourceArea
= util
.utils
.getFullTestURL("calcshapes.sxc");
128 SL
.link(aSourceArea
, "Sheet1", "", "",
129 com
.sun
.star
.sheet
.SheetLinkMode
.VALUE
);
132 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
136 links
= docProps
.getPropertyValue("SheetLinks");
137 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
138 e
.printStackTrace(log
);
139 throw new StatusException("Couldn't get SheetLinks", e
);
140 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
141 e
.printStackTrace(log
);
142 throw new StatusException("Couldn't get SheetLinks", e
);
145 oObj
= UnoRuntime
.queryInterface(XInterface
.class, links
);
147 log
.println("Creating object - " +
148 ((oObj
== null) ?
"FAILED" : "OK"));
150 TestEnvironment tEnv
= new TestEnvironment( oObj
);