2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.sheet
.XLabelRanges
;
32 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
33 import com
.sun
.star
.table
.CellRangeAddress
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.sheet.LabelRanges</code>. <p>
40 * Object implements the following interfaces :
42 * <li> <code>com::sun::star::sheet::XLabelRanges</code></li>
43 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
44 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * @see com.sun.star.sheet.LabelRanges
47 * @see com.sun.star.sheet.XLabelRanges
48 * @see com.sun.star.container.XIndexAccess
49 * @see com.sun.star.container.XElementAccess
50 * @see ifc.sheet._XLabelRanges
51 * @see ifc.container._XIndexAccess
52 * @see ifc.container._XElementAccess
54 public class ScLabelRangesObj
extends TestCase
{
55 private XSpreadsheetDocument xSheetDoc
= null;
58 * Creates Spreadsheet document.
61 protected void initialize( TestParameters tParam
, PrintWriter log
) {
62 // get a soffice factory object
63 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
66 log
.println( "creating a sheetdocument" );
67 xSheetDoc
= SOF
.createCalcDoc(null);
68 } catch (com
.sun
.star
.uno
.Exception e
) {
69 // Some exception occurs.FAILED
70 e
.printStackTrace( log
);
71 throw new StatusException( "Couldn't create document", e
);
76 * Disposes Spreadsheet document.
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xSheetDoc " );
81 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
82 util
.DesktopTools
.closeDoc(oComp
);
86 * Creating a Testenvironment for the interfaces to be tested.
87 * Obtains the value of the property <code>'ColumnLabelRanges'</code>
88 * from the document. The property value is the collection of label ranges.
89 * Adds new label range to the collection using the interface
90 * <code>XLabelRanges</code> that was queried from the property value.
91 * This collection is the instance of the service
92 * <code>com.sun.star.sheet.LabelRanges</code>.
93 * @see com.sun.star.sheet.LabelRanges
94 * @see com.sun.star.sheet.XLabelRanges
97 public synchronized TestEnvironment
createTestEnvironment(
98 TestParameters Param
, PrintWriter log
) throws StatusException
{
100 XInterface oObj
= null;
102 // creation of testobject here
103 // first we write what we are intend to do to log file
104 log
.println( "Creating a test environment" );
107 log
.println("Getting test object ") ;
108 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
109 Object ranges
= docProps
.getPropertyValue("ColumnLabelRanges");
110 XLabelRanges lRanges
= UnoRuntime
.queryInterface(XLabelRanges
.class, ranges
);
112 log
.println("Adding at least one element for ElementAccess interface");
113 CellRangeAddress aRange2
= new CellRangeAddress((short)0, 0, 1, 0, 6);
114 CellRangeAddress aRange1
= new CellRangeAddress((short)0, 0, 0, 0, 1);
115 lRanges
.addNew(aRange1
, aRange2
);
118 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
119 e
.printStackTrace(log
) ;
120 throw new StatusException(
121 "Error getting test object from spreadsheet document",e
);
122 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
123 e
.printStackTrace(log
) ;
124 throw new StatusException(
125 "Error getting test object from spreadsheet document",e
);
128 log
.println("creating a new environment for object");
129 TestEnvironment tEnv
= new TestEnvironment(oObj
);
131 log
.println("testing...");
134 } // finish method getTestEnvironment
136 } // finish class ScLabelRangesObj