merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAreaLinksObj.java
blob71d7936572f6e051374a0cbc715ecc097537bafe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScAreaLinksObj.java,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._sc;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.SOfficeFactory;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.lang.XComponent;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.sheet.XAreaLinks;
44 import com.sun.star.sheet.XSpreadsheetDocument;
45 import com.sun.star.table.CellAddress;
46 import com.sun.star.uno.AnyConverter;
47 import com.sun.star.uno.Type;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
52 /**
53 * Test for object which is represented by service
54 * <code>com.sun.star.sheet.CellAreaLinks</code>.
55 * This is a collection aff all links present
56 * in a Spreadsheet document.
57 * Object implements the following interfaces :
58 * <ul>
59 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
60 * <li> <code>com::sun::star::container::XElementAccess</code></li>
61 * <li> <code>com::sun::star::sheet::XAreaLinks</code></li>
62 * </ul>
63 * This object test <b> is NOT </b> designed to be run in several
64 * threads concurently.
65 * @see com.sun.star.container.XIndexAccess
66 * @see com.sun.star.container.XElementAccess
67 * @see com.sun.star.sheet.XAreaLinks
68 * @see ifc.container._XIndexAccess
69 * @see ifc.container._XElementAccess
70 * @see ifc.sheet._XAreaLinks
71 * @see com.sun.star.sheet.CellAreaLinks
73 public class ScAreaLinksObj extends TestCase {
74 static XSpreadsheetDocument xSheetDoc = null;
76 /**
77 * Creates Spreadsheet document.
79 protected void initialize( TestParameters tParam, PrintWriter log ) {
80 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
82 try {
83 log.println( "creating a Spreadsheet document" );
84 xSheetDoc = SOF.createCalcDoc(null);
85 } catch ( com.sun.star.uno.Exception e ) {
86 // Some exception occures.FAILED
87 e.printStackTrace( log );
88 throw new StatusException( "Couldn't create document", e );
93 /**
94 * Disposes Spreadsheet document.
96 protected void cleanup( TestParameters tParam, PrintWriter log ) {
97 log.println( " disposing xSheetDoc " );
98 XComponent oComp = (XComponent) UnoRuntime.queryInterface
99 (XComponent.class, xSheetDoc) ;
100 util.DesktopTools.closeDoc(oComp);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Retrieves a collection of Area Links using the 'AreaLinks'
107 * property of the Spreadsheet document. Adds a new link to this
108 * collection, which has a source in the same document. The
109 * link collection is passed as a tested object.
111 public synchronized TestEnvironment createTestEnvironment
112 (TestParameters Param, PrintWriter log){
114 XInterface oObj = null;
115 TestEnvironment tEnv = null ;
117 try {
119 // creation of testobject here
120 XPropertySet props = (XPropertySet)UnoRuntime.queryInterface
121 (XPropertySet.class, xSheetDoc);
122 oObj = (XInterface) AnyConverter.toObject(
123 new Type(XInterface.class),props.getPropertyValue("AreaLinks")) ;
124 XAreaLinks links = null ;
126 // adding one link into collection (for best testing)
127 links = (XAreaLinks) UnoRuntime.queryInterface(XAreaLinks.class, oObj) ;
128 CellAddress addr = new CellAddress ((short) 1,2,3) ;
129 String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc");
130 links.insertAtPosition (addr, aSourceArea, "a2:b5", "", "") ;
132 // creating test environment
133 tEnv = new TestEnvironment(oObj);
135 } catch (com.sun.star.beans.UnknownPropertyException e) {
136 log.println ("Exception occured while creating test Object.") ;
137 e.printStackTrace(log) ;
138 throw new StatusException("Couldn't create test object", e);
139 } catch (com.sun.star.lang.WrappedTargetException e) {
140 log.println ("Exception occured while creating test Object.") ;
141 e.printStackTrace(log) ;
142 throw new StatusException("Couldn't create test object", e);
143 } catch (com.sun.star.lang.IllegalArgumentException e) {
144 log.println ("Exception occured while creating test Object.") ;
145 e.printStackTrace(log) ;
146 throw new StatusException("Couldn't create test object", e);
149 return tEnv ;
152 } // finish class ScAreaLinksObj