bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAreaLinkObj.java
blobdfc852b1c0bfacfe65971d1df78c65d2bead6d83
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.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.sheet.XAreaLinks;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.table.CellAddress;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.sheet.CellAreaLink</code>.
43 * This object reflects some cell range (this range
44 * can also be from another saved document) in
45 * any range (of the same size) of the current
46 * document.<p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::sheet::XAreaLink</code></li>
50 * <li> <code>com::sun::star::util::XRefreshable</code></li>
51 * <li> <code>com::sun::star::sheet::CellAreaLink</code></li>
52 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
53 * </ul>
54 * This object test <b> is NOT </b> designed to be run in several
55 * threads concurently.
56 * @see com.sun.star.sheet.XAreaLink
57 * @see com.sun.star.util.XRefreshable
58 * @see com.sun.star.sheet.CellAreaLink
59 * @see com.sun.star.beans.XPropertySet
60 * @see ifc.sheet._XAreaLink
61 * @see ifc.util._XRefreshable
62 * @see ifc.sheet._CellAreaLink
63 * @see ifc.beans._XPropertySet
65 public class ScAreaLinkObj extends TestCase {
66 private XSpreadsheetDocument xSheetDoc = null;
68 /**
69 * Creates Spreadsheet document.
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
74 try {
75 log.println( "creating a Spreadsheet document" );
76 xSheetDoc = SOF.createCalcDoc(null);
77 } catch ( com.sun.star.uno.Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
85 /**
86 * Disposes Spreadsheet document.
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing xSheetDoc " );
90 XComponent oComp = UnoRuntime.queryInterface
91 (XComponent.class, xSheetDoc) ;
92 util.DesktopTools.closeDoc(oComp);
96 /**
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Retrieves a collection of Area Links using the 'AreaLinks'
99 * property of the Spreadsheet document. Adds a new link to this
100 * collection, which has a source in the same document. This
101 * link is passed as a tested object.
103 public synchronized TestEnvironment createTestEnvironment
104 ( TestParameters Param, PrintWriter log ) throws StatusException {
106 XInterface oObj = null;
108 try {
110 // creation of testobject here
111 XPropertySet props = UnoRuntime.queryInterface
112 (XPropertySet.class, xSheetDoc);
113 XAreaLinks links = (XAreaLinks) AnyConverter.toObject(
114 new Type(XAreaLinks.class),props.getPropertyValue("AreaLinks")) ;
115 CellAddress addr = new CellAddress ((short) 1,2,3) ;
116 String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc");
117 links.insertAtPosition (addr, aSourceArea, "a2:b5", "", "") ;
119 oObj = (XInterface) AnyConverter.toObject(
120 new Type(XInterface.class), links.getByIndex(0)) ;
121 } catch (com.sun.star.beans.UnknownPropertyException e) {
122 log.println ("Exception occurred while creating test Object.") ;
123 e.printStackTrace(log) ;
124 throw new StatusException("Couldn't create test object", e);
125 } catch (com.sun.star.lang.WrappedTargetException 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.IndexOutOfBoundsException 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);
139 TestEnvironment tEnv = new TestEnvironment(oObj) ;
141 return tEnv;