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 .
21 import lib
.MultiMethodTest
;
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
;
31 * Testing <code>com.sun.star.sheet.XDataPilotTables</code>
34 * <li><code> createDataPilotDescriptor()</code></li>
35 * <li><code> insertNewByName()</code></li>
36 * <li><code> removeByName()</code></li>
38 * This test needs the following object relations :
40 * <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>):
41 * to have a spreadsheet document for document content checking</li>
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;
54 * Retrieves object relations.
55 * @throws StatusException If one of relations not found.
58 protected void before() {
59 oSheet
= (XSpreadsheet
)tEnv
.getObjRelation("SHEET");
60 if (oSheet
== null) throw new StatusException(Status
.failed
61 ("Relation 'SHEET' not found"));
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);
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
79 * The following method tests are to be completed successfully before :
81 * <li> <code> createDataPilotDescriptor() </code> : to have
82 * <code>XDataPilotDescriptor</code> created by this method</li>
85 public void _insertNewByName(){
86 requiredMethod("createDataPilotDescriptor()");
87 boolean bResult
= true;
88 log
.println("Inserting new Table \"" + name
+ "\"");
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
);
98 log
.println(bResult ?
"OK" : "FAILED");
99 log
.println("Trying to insert element with existent name");
102 oObj
.insertNewByName(name
,new CellAddress((short)0, 7, 7), DPDscr
);
103 log
.println("No exception! - FAILED");
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 :
119 * <li> <code>insertNewByName()</code>: to have name of existent table</li>
122 public void _removeByName(){
123 requiredMethod("insertNewByName()");
124 boolean bResult
= true;
125 log
.println("Remove table with name " + name
);
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
);
134 log
.println(bResult ?
"OK" : "FAILED");
135 log
.println("Removing unexistent element");
137 oObj
.removeByName(name
);
138 log
.println("No exception! - FAILED");
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
);