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 
28 package mod._sc;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.beans.XPropertySet;
39 import com.sun.star.container.XEnumerationAccess;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.sheet.XAreaLinks;
43 import com.sun.star.sheet.XSpreadsheetDocument;
44 import com.sun.star.table.CellAddress;
45 import com.sun.star.uno.AnyConverter;
46 import com.sun.star.uno.Type;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 
50 public class ScIndexEnumeration_CellAreaLinksEnumeration extends TestCase {
51     static XSpreadsheetDocument xSheetDoc = null;
52 
53     /**
54     * Creates Spreadsheet document.
55     */
56    protected void initialize( TestParameters tParam, PrintWriter log ) {
57         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
58 
59         try {
60             log.println( "creating a Spreadsheet document" );
61             xSheetDoc = SOF.createCalcDoc(null);
62         } catch ( com.sun.star.uno.Exception e ) {
63             // Some exception occures.FAILED
64             e.printStackTrace( log );
65             throw new StatusException( "Couldn't create document", e );
66         }
67 
68     }
69 
70     /**
71     * Disposes Spreadsheet document.
72     */
73     protected void cleanup( TestParameters tParam, PrintWriter log ) {
74         log.println( "    disposing xSheetDoc " );
75         XComponent oComp = (XComponent) UnoRuntime.queryInterface
76             (XComponent.class, xSheetDoc) ;
77         util.DesktopTools.closeDoc(oComp);
78     }
79 
80 
81     public synchronized TestEnvironment createTestEnvironment
82             (TestParameters Param, PrintWriter log){
83 
84       XInterface oObj = null;
85       TestEnvironment tEnv = null ;
86 
87       try {
88 
89         // creation of testobject here
90         XPropertySet props = (XPropertySet)UnoRuntime.queryInterface
91             (XPropertySet.class, xSheetDoc);
92         oObj = (XInterface) AnyConverter.toObject(
93                 new Type(XInterface.class),props.getPropertyValue("AreaLinks")) ;
94         XAreaLinks links = null ;
95 
96         // adding one link into collection (for best testing)
97         links = (XAreaLinks) UnoRuntime.queryInterface(XAreaLinks.class, oObj) ;
98         CellAddress addr = new CellAddress ((short) 1,2,3) ;
99         String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc");
100         links.insertAtPosition (addr, aSourceArea, "a2:b5", "", "") ;
101 
102         XEnumerationAccess ea = (XEnumerationAccess)
103                     UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
104 
105         oObj = ea.createEnumeration();
106 
107         log.println("ImplementationName: "+util.utils.getImplName(oObj));
108         // creating test environment
109         tEnv = new TestEnvironment(oObj);
110 
111         tEnv.addObjRelation("ENUM",ea);
112 
113       } catch (com.sun.star.beans.UnknownPropertyException e) {
114             log.println ("Exception occured while creating test Object.") ;
115             e.printStackTrace(log) ;
116             throw new StatusException("Couldn't create test object", e);
117       } catch (com.sun.star.lang.WrappedTargetException e) {
118             log.println ("Exception occured while creating test Object.") ;
119             e.printStackTrace(log) ;
120             throw new StatusException("Couldn't create test object", e);
121       } catch (com.sun.star.lang.IllegalArgumentException e) {
122             log.println ("Exception occured while creating test Object.") ;
123             e.printStackTrace(log) ;
124             throw new StatusException("Couldn't create test object", e);
125       }
126 
127        return tEnv ;
128     }
129 
130 }
131 
132