xref: /AOO41X/main/qadevOOo/tests/java/mod/_sc/ScIndexEnumeration_LabelRangesEnumeration.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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.XLabelRanges;
43 import com.sun.star.sheet.XSpreadsheetDocument;
44 import com.sun.star.table.CellRangeAddress;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 
48 public class ScIndexEnumeration_LabelRangesEnumeration extends TestCase {
49     static XSpreadsheetDocument xSheetDoc = null;
50 
51     /**
52     * Creates Spreadsheet document.
53     */
54     protected void initialize( TestParameters tParam, PrintWriter log ) {
55         // get a soffice factory object
56         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
57 
58         try {
59             log.println( "creating a sheetdocument" );
60             xSheetDoc = SOF.createCalcDoc(null);;
61         } catch (com.sun.star.uno.Exception e) {
62             // Some exception occures.FAILED
63             e.printStackTrace( log );
64             throw new StatusException( "Couldn't create document", e );
65         }
66     }
67 
68     /**
69     * Disposes Spreadsheet document.
70     */
71     protected void cleanup( TestParameters tParam, PrintWriter log ) {
72         log.println( "    disposing xSheetDoc " );
73         XComponent oComp = (XComponent)
74             UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
75         util.DesktopTools.closeDoc(oComp);
76     }
77 
78     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
79 
80         XInterface oObj = null;
81 
82         // creation of testobject here
83         // first we write what we are intend to do to log file
84         log.println( "Creating a test environment" );
85 
86         try {
87             log.println("Getting test object ") ;
88             XPropertySet docProps = (XPropertySet)
89                 UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
90             Object ranges = docProps.getPropertyValue("ColumnLabelRanges");
91             XLabelRanges lRanges = (XLabelRanges)
92                 UnoRuntime.queryInterface(XLabelRanges.class, ranges);
93 
94             log.println("Adding at least one element for ElementAccess interface");
95             CellRangeAddress aRange2 = new CellRangeAddress((short)0, 0, 1, 0, 6);
96             CellRangeAddress aRange1 = new CellRangeAddress((short)0, 0, 0, 0, 1);
97             lRanges.addNew(aRange1, aRange2);
98 
99             oObj = lRanges;
100         } catch (com.sun.star.lang.WrappedTargetException e) {
101             e.printStackTrace(log) ;
102             throw new StatusException(
103                 "Error getting test object from spreadsheet document",e);
104         } catch (com.sun.star.beans.UnknownPropertyException e) {
105             e.printStackTrace(log) ;
106             throw new StatusException(
107                 "Error getting test object from spreadsheet document",e);
108         }
109 
110         log.println("creating a new environment for object");
111         XEnumerationAccess ea = (XEnumerationAccess)
112                     UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
113 
114         oObj = ea.createEnumeration();
115 
116         log.println("ImplementationName: "+util.utils.getImplName(oObj));
117         // creating test environment
118         TestEnvironment tEnv = new TestEnvironment( oObj );
119 
120         tEnv.addObjRelation("ENUM",ea);
121 
122         return tEnv;
123     } // finish method getTestEnvironment
124 
125 }
126 
127