1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import lib
.StatusException
;
34 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
35 import com
.sun
.star
.sheet
.XDataPilotTables
;
36 import com
.sun
.star
.sheet
.XSpreadsheet
;
37 import com
.sun
.star
.table
.CellAddress
;
40 * Testing <code>com.sun.star.sheet.XDataPilotTables</code>
43 * <li><code> createDataPilotDescriptor()</code></li>
44 * <li><code> insertNewByName()</code></li>
45 * <li><code> removeByName()</code></li>
47 * This test needs the following object relations :
49 * <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>):
50 * to have a spreadsheet document for document content checking</li>
52 * @see com.sun.star.sheet.XDataPilotTables
54 public class _XDataPilotTables
extends MultiMethodTest
{
56 public XDataPilotTables oObj
= null;
57 XDataPilotDescriptor DPDscr
= null;
58 String name
= "XDataPilotTables";
59 CellAddress CA
= new CellAddress((short)0, 9, 8);
60 XSpreadsheet oSheet
= null;
63 * Retrieves object relations.
64 * @throws StatusException If one of relations not found.
66 protected void before() {
67 oSheet
= (XSpreadsheet
)tEnv
.getObjRelation("SHEET");
68 if (oSheet
== null) throw new StatusException(Status
.failed
69 ("Relation 'SHEET' not found"));
73 * Test calls the method, stores returned value and checks returned value.
74 * <p>Has <b> OK </b> status if returned value isn't null. <p>
76 public void _createDataPilotDescriptor(){
77 DPDscr
= oObj
.createDataPilotDescriptor();
78 tRes
.tested("createDataPilotDescriptor()", DPDscr
!= null);
82 * Test calls the method inserting new table with new name and then calls
83 * the method inserting table with existent name. <p>
84 * Has <b> OK </b> status if the cell content where table was inserted is
85 * equal to 'Filter' after first call and exception was thrown during
87 * The following method tests are to be completed successfully before :
89 * <li> <code> createDataPilotDescriptor() </code> : to have
90 * <code>XDataPilotDescriptor</code> created by this method</li>
93 public void _insertNewByName(){
94 requiredMethod("createDataPilotDescriptor()");
95 boolean bResult
= true;
96 log
.println("Inserting new Table \"" + name
+ "\"");
98 oObj
.insertNewByName(name
, CA
, DPDscr
);
99 bResult
&= oSheet
.getCellByPosition
100 (CA
.Column
, CA
.Row
).getFormula().equals("Filter");
101 } catch (com
.sun
.star
.uno
.Exception e
) {
102 log
.println("Exception occurred! " + e
);
106 log
.println(bResult ?
"OK" : "FAILED");
107 log
.println("Trying to insert element with existent name");
110 oObj
.insertNewByName(name
,new CellAddress((short)0, 7, 7), DPDscr
);
111 log
.println("No exception! - FAILED");
113 } catch (com
.sun
.star
.uno
.RuntimeException e
) {
114 log
.println("Expected exception - OK " + e
);
117 log
.println("Inserting new table " + (bResult ?
"OK" : "FAILED"));
118 tRes
.tested("insertNewByName()", bResult
);
122 * Test calls the method for existent table and for unexistent table. <p>
123 * Has <b> OK </b> status if the cell where table was removed from is empty
124 * after first call and exception was thrown during second call. <p>
125 * The following method tests are to be completed successfully before :
127 * <li> <code>insertNewByName()</code>: to have name of existent table</li>
130 public void _removeByName(){
131 requiredMethod("insertNewByName()");
132 boolean bResult
= true;
133 log
.println("Remove table with name " + name
);
135 oObj
.removeByName(name
);
136 bResult
&= oSheet
.getCellByPosition
137 (CA
.Column
, CA
.Row
).getFormula().equals("");
138 } catch (com
.sun
.star
.uno
.Exception e
) {
139 log
.println("Exception occurred ! " + e
);
142 log
.println(bResult ?
"OK" : "FAILED");
143 log
.println("Removing unexistent element");
145 oObj
.removeByName(name
);
146 log
.println("No exception! - FAILED");
148 } catch (com
.sun
.star
.uno
.RuntimeException e
) {
149 log
.println("Expected exception - OK " + e
);
152 log
.println("Removing a table " + (bResult ?
"OK" : "FAILED"));
153 tRes
.tested("removeByName()", bResult
);