bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_SheetLinksEnumeration.java
blob4b3f21457f4dd286f44682471fb4d49e5ded31ae
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.container.XEnumerationAccess;
31 import com.sun.star.container.XIndexAccess;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.sheet.XSheetLinkable;
35 import com.sun.star.sheet.XSpreadsheet;
36 import com.sun.star.sheet.XSpreadsheetDocument;
37 import com.sun.star.sheet.XSpreadsheets;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 public class ScIndexEnumeration_SheetLinksEnumeration extends TestCase {
44 private XSpreadsheetDocument xSheetDoc = null;
46 /**
47 * Creates Spreadsheet document.
49 protected void initialize( TestParameters tParam, PrintWriter log ) {
50 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
52 try {
53 log.println( "creating a Spreadsheet document" );
54 xSheetDoc = SOF.createCalcDoc(null);
55 } catch ( com.sun.star.uno.Exception e ) {
56 // Some exception occurs.FAILED
57 e.printStackTrace( log );
58 throw new StatusException( "Couldn't create document", e );
62 /**
63 * Disposes Spreadsheet document.
65 protected void cleanup( TestParameters tParam, PrintWriter log ) {
66 log.println( " disposing xSheetDoc " );
67 XComponent oComp = UnoRuntime.queryInterface(XComponent.class, xSheetDoc) ;
68 util.DesktopTools.closeDoc(oComp);
71 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
73 XInterface oObj = null;
75 // creation of testobject here
76 // first we write what we are intend to do to log file
77 log.println( "Creating a test environment" );
78 XSpreadsheet oSheet = null;
80 log.println("Getting test object ") ;
81 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
82 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
83 try {
84 oSheet = (XSpreadsheet) AnyConverter.toObject(
85 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
86 } catch (com.sun.star.lang.WrappedTargetException e) {
87 e.printStackTrace(log);
88 throw new StatusException( "Couldn't get a spreadsheet", e);
89 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
90 e.printStackTrace(log);
91 throw new StatusException( "Couldn't get a spreadsheet", e);
92 } catch (com.sun.star.lang.IllegalArgumentException e) {
93 e.printStackTrace(log);
94 throw new StatusException( "Couldn't get a spreadsheet", e);
97 XSheetLinkable SL = UnoRuntime.queryInterface(XSheetLinkable.class, oSheet);
99 // creating link.
100 String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc");
101 SL.link(aSourceArea, "Sheet1", "", "",
102 com.sun.star.sheet.SheetLinkMode.VALUE);
104 // Getting links.
105 XPropertySet docProps = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
107 Object links = null;
108 try {
109 links = docProps.getPropertyValue("SheetLinks");
110 } catch(com.sun.star.lang.WrappedTargetException e){
111 e.printStackTrace(log);
112 throw new StatusException("Couldn't get SheetLinks", e);
113 } catch(com.sun.star.beans.UnknownPropertyException e){
114 e.printStackTrace(log);
115 throw new StatusException("Couldn't get SheetLinks", e);
118 oObj = UnoRuntime.queryInterface(XInterface.class, links);
120 XEnumerationAccess ea = UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
122 oObj = ea.createEnumeration();
124 log.println("ImplementationName: "+util.utils.getImplName(oObj));
125 // creating test environment
126 TestEnvironment tEnv = new TestEnvironment( oObj );
128 tEnv.addObjRelation("ENUM",ea);
130 return tEnv;