Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XDataPilotTables.java
blob820bd4413340a83afc290223bb8fa0d9ee15f205
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 ifc.sheet;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.sheet.XDataPilotDescriptor;
26 import com.sun.star.sheet.XDataPilotTables;
27 import com.sun.star.sheet.XSpreadsheet;
28 import com.sun.star.table.CellAddress;
30 /**
31 * Testing <code>com.sun.star.sheet.XDataPilotTables</code>
32 * interface methods :
33 * <ul>
34 * <li><code> createDataPilotDescriptor()</code></li>
35 * <li><code> insertNewByName()</code></li>
36 * <li><code> removeByName()</code></li>
37 * </ul> <p>
38 * This test needs the following object relations :
39 * <ul>
40 * <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>):
41 * to have a spreadsheet document for document content checking</li>
42 * <ul> <p>
43 * @see com.sun.star.sheet.XDataPilotTables
45 public class _XDataPilotTables extends MultiMethodTest {
47 public XDataPilotTables oObj = null;
48 XDataPilotDescriptor DPDscr = null;
49 String name = "XDataPilotTables";
50 CellAddress CA = new CellAddress((short)0, 9, 8);
51 XSpreadsheet oSheet = null;
53 /**
54 * Retrieves object relations.
55 * @throws StatusException If one of relations not found.
57 @Override
58 protected void before() {
59 oSheet = (XSpreadsheet)tEnv.getObjRelation("SHEET");
60 if (oSheet == null) throw new StatusException(Status.failed
61 ("Relation 'SHEET' not found"));
64 /**
65 * Test calls the method, stores returned value and checks returned value.
66 * <p>Has <b> OK </b> status if returned value isn't null. <p>
68 public void _createDataPilotDescriptor(){
69 DPDscr = oObj.createDataPilotDescriptor();
70 tRes.tested("createDataPilotDescriptor()", DPDscr != null);
73 /**
74 * Test calls the method inserting new table with new name and then calls
75 * the method inserting table with existent name. <p>
76 * Has <b> OK </b> status if the cell content where table was inserted is
77 * equal to 'Filter' after first call and exception was thrown during
78 * second call. <p>
79 * The following method tests are to be completed successfully before :
80 * <ul>
81 * <li> <code> createDataPilotDescriptor() </code> : to have
82 * <code>XDataPilotDescriptor</code> created by this method</li>
83 * </ul>
85 public void _insertNewByName(){
86 requiredMethod("createDataPilotDescriptor()");
87 boolean bResult = true;
88 log.println("Inserting new Table \"" + name + "\"");
89 try {
90 oObj.insertNewByName(name, CA, DPDscr);
91 bResult &= oSheet.getCellByPosition
92 (CA.Column, CA.Row).getFormula().equals("Filter");
93 } catch (com.sun.star.uno.Exception e) {
94 log.println("Exception occurred! " + e);
95 bResult = false;
98 log.println(bResult ? "OK" : "FAILED");
99 log.println("Trying to insert element with existent name");
101 try {
102 oObj.insertNewByName(name,new CellAddress((short)0, 7, 7), DPDscr);
103 log.println("No exception! - FAILED");
104 bResult = false;
105 } catch (com.sun.star.uno.RuntimeException e) {
106 log.println("Expected exception - OK " + e);
109 log.println("Inserting new table " + (bResult ? "OK" : "FAILED"));
110 tRes.tested("insertNewByName()", bResult);
114 * Test calls the method for existent table and for unexistent table. <p>
115 * Has <b> OK </b> status if the cell where table was removed from is empty
116 * after first call and exception was thrown during second call. <p>
117 * The following method tests are to be completed successfully before :
118 * <ul>
119 * <li> <code>insertNewByName()</code>: to have name of existent table</li>
120 * </ul>
122 public void _removeByName(){
123 requiredMethod("insertNewByName()");
124 boolean bResult = true;
125 log.println("Remove table with name " + name);
126 try {
127 oObj.removeByName(name);
128 bResult &= oSheet.getCellByPosition
129 (CA.Column, CA.Row).getFormula().equals("");
130 } catch (com.sun.star.uno.Exception e) {
131 log.println("Exception occurred ! " + e);
132 bResult = false;
134 log.println(bResult ? "OK" : "FAILED");
135 log.println("Removing unexistent element");
136 try {
137 oObj.removeByName(name);
138 log.println("No exception! - FAILED");
139 bResult = false;
140 } catch (com.sun.star.uno.RuntimeException e) {
141 log.println("Expected exception - OK " + e);
144 log.println("Removing a table " + (bResult ? "OK" : "FAILED"));
145 tRes.tested("removeByName()", bResult);