bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableValidationObj.java
blob1b7efbb4c9254655ccfd0bacb2e2fdd54b920029
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.XIndexAccess;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.sheet.XSpreadsheet;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.sheet.XSpreadsheets;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.sheet.TableValidation</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li> <code>com::sun::star::sheet::TableValidation</code></li>
46 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
47 * <li> <code>com::sun::star::sheet::XSheetCondition</code></li>
48 * </ul>
49 * @see com.sun.star.sheet.TableValidation
50 * @see com.sun.star.beans.XPropertySet
51 * @see com.sun.star.sheet.XSheetCondition
52 * @see ifc.sheet._TableValidation
53 * @see ifc.beans._XPropertySet
54 * @see ifc.sheet._XSheetCondition
56 public class ScTableValidationObj extends TestCase {
57 private XSpreadsheetDocument xSpreadsheetDoc = null;
59 /**
60 * Creates Spreadsheet document.
62 @Override
63 protected void initialize( TestParameters tParam, PrintWriter log ) {
64 // get a soffice factory object
65 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
67 try {
68 log.println( "creating a sheetdocument" );
69 xSpreadsheetDoc = SOF.createCalcDoc(null);
70 } catch (com.sun.star.uno.Exception e ) {
71 // Some exception occurs.FAILED
72 e.printStackTrace( log );
73 throw new StatusException( "Couldn't create document", e );
77 /**
78 * Disposes Spreadsheet document.
80 @Override
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xSheetDoc " );
83 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
84 util.DesktopTools.closeDoc(oComp);
87 /**
88 * Creating a Testenvironment for the interfaces to be tested.
89 * Retrieves a collection of spreadsheets from the document and takes one of
90 * them. Fills some cell in the spreadsheet. Obtains the property
91 * <code>'Validation'</code> of the spreadsheet. The value of the property
92 * is the instance of the service <code>com.sun.star.sheet.TableValidation</code>.
93 * @see com.sun.star.sheet.TableValidation
95 @Override
96 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
98 XInterface oObj = null;
100 log.println("getting sheets");
101 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
103 log.println("getting a sheet");
104 XSpreadsheet oSheet = null;
105 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
106 try {
107 oSheet = (XSpreadsheet) AnyConverter.toObject(
108 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
109 } catch (com.sun.star.lang.WrappedTargetException e) {
110 e.printStackTrace(log);
111 throw new StatusException( "Couldn't get a spreadsheet", e);
112 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
113 e.printStackTrace(log);
114 throw new StatusException( "Couldn't get a spreadsheet", e);
115 } catch (com.sun.star.lang.IllegalArgumentException e) {
116 e.printStackTrace(log);
117 throw new StatusException( "Couldn't get a spreadsheet", e);
120 log.println("filling some cells");
121 try {
122 oSheet.getCellByPosition(5, 5).setValue(15);
123 oSheet.getCellByPosition(1, 4).setValue(10);
124 oSheet.getCellByPosition(2, 0).setValue(-5.15);
125 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
126 e.printStackTrace(log);
127 throw new StatusException(
128 "Exception occurred while filling cells", e);
131 XPropertySet Props = null;
133 try {
134 Props = UnoRuntime.queryInterface(XPropertySet.class, oSheet);
135 oObj = (XInterface) AnyConverter.toObject(
136 new Type(XInterface.class),Props.getPropertyValue("Validation"));
137 } catch (com.sun.star.lang.WrappedTargetException e){
138 e.printStackTrace(log);
139 throw new StatusException("Couldn't get property 'Validation'", e);
140 } catch (com.sun.star.beans.UnknownPropertyException e){
141 e.printStackTrace(log);
142 throw new StatusException("Couldn't get property 'Validation'", e);
143 } catch (com.sun.star.lang.IllegalArgumentException e){
144 e.printStackTrace(log);
145 throw new StatusException("Couldn't get property 'Validation'", e);
148 log.println("creating a new environment for object");
149 TestEnvironment tEnv = new TestEnvironment(oObj);
151 return tEnv;
152 } // finish method getTestEnvironment
153 } // finish class ScTableValidationObj