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