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.XDatabaseRanges;
43 import com.sun.star.sheet.XSpreadsheetDocument;
44 import com.sun.star.table.CellRangeAddress;
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 
51 public class ScIndexEnumeration_DatabaseRangesEnumeration extends TestCase {
52     static XSpreadsheetDocument xSheetDoc = null;
53 
54     /**
55     * Creates Spreadsheet document.
56     */
57     protected void initialize( TestParameters tParam, PrintWriter log ) {
58         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
59 
60         try {
61             log.println( "creating a Spreadsheet document" );
62             xSheetDoc = SOF.createCalcDoc(null);
63         } catch ( com.sun.star.uno.Exception e ) {
64             // Some exception occures.FAILED
65             e.printStackTrace( log );
66             throw new StatusException( "Couldn't create document", e );
67         }
68 
69     }
70 
71     /**
72     * Disposes Spreadsheet document.
73     */
74     protected void cleanup( TestParameters tParam, PrintWriter log ) {
75         log.println( "    disposing xSheetDoc " );
76         XComponent oComp = (XComponent)
77             UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
78         util.DesktopTools.closeDoc(oComp);
79     }
80 
81     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
82 
83         XInterface oObj = null;
84 
85         // creation of testobject here
86         // first we write what we are intend to do to log file
87         log.println( "Creating a test environment" );
88 
89         log.println("Getting test object ") ;
90         XPropertySet docProps = (XPropertySet)
91             UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
92 
93         XDatabaseRanges dbRanges = null;
94         try {
95             dbRanges = (XDatabaseRanges) AnyConverter.toObject(
96                 new Type(XDatabaseRanges.class),
97                     docProps.getPropertyValue("DatabaseRanges"));
98         } catch (com.sun.star.lang.WrappedTargetException e) {
99             e.printStackTrace(log) ;
100             throw new StatusException(
101                 "Error getting test object from spreadsheet document",e) ;
102         } catch (com.sun.star.beans.UnknownPropertyException e) {
103             e.printStackTrace(log) ;
104             throw new StatusException(
105                 "Error getting test object from spreadsheet document",e) ;
106         } catch (com.sun.star.lang.IllegalArgumentException e) {
107             e.printStackTrace(log) ;
108             throw new StatusException(
109                 "Error getting test object from spreadsheet document",e) ;
110         }
111 
112         log.println("Adding at least one element for ElementAccess interface");
113         CellRangeAddress aRange = new CellRangeAddress((short)0, 2, 4, 5, 6);
114         if (!dbRanges.hasByName("dbRange")) {
115             dbRanges.addNewByName("dbRange", aRange);
116         }
117 
118         oObj = dbRanges;
119         XEnumerationAccess ea = (XEnumerationAccess)
120                     UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
121 
122         oObj = ea.createEnumeration();
123 
124         log.println("ImplementationName: "+util.utils.getImplName(oObj));
125         // creating test environment
126         TestEnvironment tEnv = new TestEnvironment( oObj );
127 
128         tEnv.addObjRelation("ENUM",ea);
129         return tEnv;
130     }
131 
132 }
133 
134 
135