1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScLabelRangesObj.java,v $
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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XLabelRanges
;
45 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
46 import com
.sun
.star
.table
.CellRangeAddress
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XInterface
;
51 * Test for object which is represented by service
52 * <code>com.sun.star.sheet.LabelRanges</code>. <p>
53 * Object implements the following interfaces :
55 * <li> <code>com::sun::star::sheet::XLabelRanges</code></li>
56 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
57 * <li> <code>com::sun::star::container::XElementAccess</code></li>
59 * @see com.sun.star.sheet.LabelRanges
60 * @see com.sun.star.sheet.XLabelRanges
61 * @see com.sun.star.container.XIndexAccess
62 * @see com.sun.star.container.XElementAccess
63 * @see ifc.sheet._XLabelRanges
64 * @see ifc.container._XIndexAccess
65 * @see ifc.container._XElementAccess
67 public class ScLabelRangesObj
extends TestCase
{
68 static XSpreadsheetDocument xSheetDoc
= null;
71 * Creates Spreadsheet document.
73 protected void initialize( TestParameters tParam
, PrintWriter log
) {
74 // get a soffice factory object
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
78 log
.println( "creating a sheetdocument" );
79 xSheetDoc
= SOF
.createCalcDoc(null);;
80 } catch (com
.sun
.star
.uno
.Exception e
) {
81 // Some exception occures.FAILED
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
88 * Disposes Spreadsheet document.
90 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
91 log
.println( " disposing xSheetDoc " );
92 XComponent oComp
= (XComponent
)
93 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
94 util
.DesktopTools
.closeDoc(oComp
);
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Obtains the value of the property <code>'ColumnLabelRanges'</code>
100 * from the document. The property value is the collection of label ranges.
101 * Adds new label range to the collection using the interface
102 * <code>XLabelRanges</code> that was queried from the property value.
103 * This collection is the instance of the service
104 * <code>com.sun.star.sheet.LabelRanges</code>.
105 * @see com.sun.star.sheet.LabelRanges
106 * @see com.sun.star.sheet.XLabelRanges
108 public synchronized TestEnvironment
createTestEnvironment(
109 TestParameters Param
, PrintWriter log
) throws StatusException
{
111 XInterface oObj
= null;
113 // creation of testobject here
114 // first we write what we are intend to do to log file
115 log
.println( "Creating a test environment" );
118 log
.println("Getting test object ") ;
119 XPropertySet docProps
= (XPropertySet
)
120 UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
121 Object ranges
= docProps
.getPropertyValue("ColumnLabelRanges");
122 XLabelRanges lRanges
= (XLabelRanges
)
123 UnoRuntime
.queryInterface(XLabelRanges
.class, ranges
);
125 log
.println("Adding at least one element for ElementAccess interface");
126 CellRangeAddress aRange2
= new CellRangeAddress((short)0, 0, 1, 0, 6);
127 CellRangeAddress aRange1
= new CellRangeAddress((short)0, 0, 0, 0, 1);
128 lRanges
.addNew(aRange1
, aRange2
);
131 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
132 e
.printStackTrace(log
) ;
133 throw new StatusException(
134 "Error getting test object from spreadsheet document",e
);
135 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
136 e
.printStackTrace(log
) ;
137 throw new StatusException(
138 "Error getting test object from spreadsheet document",e
);
141 log
.println("creating a new environment for object");
142 TestEnvironment tEnv
= new TestEnvironment(oObj
);
144 log
.println("testing...");
147 } // finish method getTestEnvironment
149 } // finish class ScLabelRangesObj