bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScSheetLinksObj.java
blob1cb7b41cc3ebb79dfcfba48ff22741698d4bd1e6
1 /*
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
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.lang.XMultiServiceFactory;
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;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.sheet.SheetLinks</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::container::XNameAccess</code></li>
48 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * </ul>
50 * @see com.sun.star.sheet.SheetLinks
51 * @see com.sun.star.container.XNameAccess
52 * @see com.sun.star.container.XElementAccess
53 * @see ifc.container._XNameAccess
54 * @see ifc.container._XElementAccess
56 public class ScSheetLinksObj extends TestCase {
57 private XSpreadsheetDocument xSheetDoc = null;
59 /**
60 * Creates Spreadsheet document.
62 protected void initialize( TestParameters tParam, PrintWriter log ) {
63 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
65 try {
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 );
75 /**
76 * Disposes Spreadsheet document.
78 protected void cleanup( TestParameters tParam, PrintWriter log ) {
79 log.println( " disposing xSheetDoc " );
80 XComponent oComp = UnoRuntime.queryInterface(XComponent.class, xSheetDoc) ;
81 util.DesktopTools.closeDoc(oComp);
84 /**
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Retrieves a collection of spreadsheets from a document
87 * and takes one of them. Links the sheet to another sheet using the
88 * interface <code>XSheetLinkable</code>. Obtains the
89 * value of the property <code>'SheetLinks'</code> that is the collection of
90 * sheet links. This collection is the instance of the service
91 * <code>com.sun.star.sheet.SheetLinks</code>.
92 * @see com.sun.star.sheet.SheetLink
93 * @see com.sun.star.sheet.XSheetLinkable
95 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
97 XInterface oObj = null;
99 // creation of testobject here
100 // first we write what we are intend to do to log file
101 log.println( "Creating a test environment" );
102 XSpreadsheet oSheet = null;
104 log.println("Getting test object ") ;
105 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
106 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
107 try {
108 oSheet = (XSpreadsheet) AnyConverter.toObject(
109 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
110 } catch (com.sun.star.lang.WrappedTargetException e) {
111 e.printStackTrace(log);
112 throw new StatusException("Couldn't get a spreadsheet", e);
113 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
114 e.printStackTrace(log);
115 throw new StatusException("Couldn't get a spreadsheet", e);
116 } catch (com.sun.star.lang.IllegalArgumentException e) {
117 e.printStackTrace(log);
118 throw new StatusException("Couldn't get a spreadsheet", e);
121 XSheetLinkable SL = UnoRuntime.queryInterface(XSheetLinkable.class, oSheet);
123 // creating link. Doesn't matter that it refers to unexistant object.
124 // this is for proper work of X*Access tests.
125 String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc");
126 SL.link(aSourceArea, "Sheet1", "", "",
127 com.sun.star.sheet.SheetLinkMode.VALUE);
129 // Getting links.
130 XPropertySet docProps = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
132 Object links = null;
133 try {
134 links = docProps.getPropertyValue("SheetLinks");
135 } catch(com.sun.star.lang.WrappedTargetException e){
136 e.printStackTrace(log);
137 throw new StatusException("Couldn't get SheetLinks", e);
138 } catch(com.sun.star.beans.UnknownPropertyException e){
139 e.printStackTrace(log);
140 throw new StatusException("Couldn't get SheetLinks", e);
143 oObj = UnoRuntime.queryInterface(XInterface.class, links);
145 log.println("Creating object - " +
146 ((oObj == null) ? "FAILED" : "OK"));
148 TestEnvironment tEnv = new TestEnvironment( oObj );
150 return tEnv;