bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAreaLinksObj.java
bloba144964c2c0e2190c4b1b1ed3a0b870b8bab746e
1 /*
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 .
18 package mod._sc;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.lang.XComponent;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.sheet.XAreaLinks;
32 import com.sun.star.sheet.XSpreadsheetDocument;
33 import com.sun.star.table.CellAddress;
34 import com.sun.star.uno.AnyConverter;
35 import com.sun.star.uno.Type;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.sheet.CellAreaLinks</code>.
43 * This is a collection aff all links present
44 * in a Spreadsheet document.
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
48 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * <li> <code>com::sun::star::sheet::XAreaLinks</code></li>
50 * </ul>
51 * This object test <b> is NOT </b> designed to be run in several
52 * threads concurently.
53 * @see com.sun.star.container.XIndexAccess
54 * @see com.sun.star.container.XElementAccess
55 * @see com.sun.star.sheet.XAreaLinks
56 * @see ifc.container._XIndexAccess
57 * @see ifc.container._XElementAccess
58 * @see ifc.sheet._XAreaLinks
59 * @see com.sun.star.sheet.CellAreaLinks
61 public class ScAreaLinksObj extends TestCase {
62 private XSpreadsheetDocument xSheetDoc = null;
64 /**
65 * Creates Spreadsheet document.
67 protected void initialize( TestParameters tParam, PrintWriter log ) {
68 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
70 try {
71 log.println( "creating a Spreadsheet document" );
72 xSheetDoc = SOF.createCalcDoc(null);
73 } catch ( com.sun.star.uno.Exception e ) {
74 // Some exception occurs.FAILED
75 e.printStackTrace( log );
76 throw new StatusException( "Couldn't create document", e );
81 /**
82 * Disposes Spreadsheet document.
84 protected void cleanup( TestParameters tParam, PrintWriter log ) {
85 log.println( " disposing xSheetDoc " );
86 XComponent oComp = UnoRuntime.queryInterface
87 (XComponent.class, xSheetDoc) ;
88 util.DesktopTools.closeDoc(oComp);
92 /**
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Retrieves a collection of Area Links using the 'AreaLinks'
95 * property of the Spreadsheet document. Adds a new link to this
96 * collection, which has a source in the same document. The
97 * link collection is passed as a tested object.
99 public synchronized TestEnvironment createTestEnvironment
100 (TestParameters Param, PrintWriter log){
102 XInterface oObj = null;
103 TestEnvironment tEnv = null ;
105 try {
107 // creation of testobject here
108 XPropertySet props = UnoRuntime.queryInterface
109 (XPropertySet.class, xSheetDoc);
110 oObj = (XInterface) AnyConverter.toObject(
111 new Type(XInterface.class),props.getPropertyValue("AreaLinks")) ;
112 XAreaLinks links = null ;
114 // adding one link into collection (for best testing)
115 links = UnoRuntime.queryInterface(XAreaLinks.class, oObj) ;
116 CellAddress addr = new CellAddress ((short) 1,2,3) ;
117 String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc");
118 links.insertAtPosition (addr, aSourceArea, "a2:b5", "", "") ;
120 // creating test environment
121 tEnv = new TestEnvironment(oObj);
123 } catch (com.sun.star.beans.UnknownPropertyException e) {
124 log.println ("Exception occurred while creating test Object.") ;
125 e.printStackTrace(log) ;
126 throw new StatusException("Couldn't create test object", e);
127 } catch (com.sun.star.lang.WrappedTargetException e) {
128 log.println ("Exception occurred while creating test Object.") ;
129 e.printStackTrace(log) ;
130 throw new StatusException("Couldn't create test object", e);
131 } catch (com.sun.star.lang.IllegalArgumentException e) {
132 log.println ("Exception occurred while creating test Object.") ;
133 e.printStackTrace(log) ;
134 throw new StatusException("Couldn't create test object", e);
137 return tEnv ;
140 } // finish class ScAreaLinksObj