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 ************************************************************************/
29 import com
.sun
.star
.sheet
.XSpreadsheets
;
31 import lib
.MultiMethodTest
;
35 * Testing <code>com.sun.star.sheet.XSpreadsheets</code>
38 * <li><code> insertNewByName()</code></li>
39 * <li><code> moveByName()</code></li>
40 * <li><code> copyByName()</code></li>
42 * Test is multithread compilant. <p>
43 * @see com.sun.star.sheet.XSpreadsheets
45 public class _XSpreadsheets
extends MultiMethodTest
{
46 protected static int uniqCount
= 0;
47 public XSpreadsheets oObj
= null;
48 protected int uniqNumber
= 0;
51 * Sets the unique number for the current test.
53 protected synchronized void before() {
54 uniqNumber
= uniqCount
++;
58 * Test inserts new sheet using the name returned by the method
59 * <code>newName</code>, copies inserted sheet with the new name,
60 * checks existence of the sheet with this name in collection and removes
61 * the both sheets from the collection. <p>
62 * Has <b> OK </b> status if the sheet with the name of the copy exists
63 * in the collection and no exceptions were thrown. <p>
65 public void _copyByName() {
66 boolean result
= true;
68 //first insert one that should be copied
69 String iS
= newName("copyFrom");
70 log
.println("Inserting sheet '" + iS
+ "'");
71 oObj
.insertNewByName(iS
, (short) 0);
73 String
[] eNames
= oObj
.getElementNames();
74 String NewSheet
= newName("copyTo");
75 log
.println("Try to copy " + eNames
[0] + " to " + NewSheet
);
76 oObj
.copyByName(eNames
[0], NewSheet
, (short) 0);
77 result
= oObj
.hasByName(NewSheet
);
79 //remove all inserted sheets
81 oObj
.removeByName(NewSheet
);
82 oObj
.removeByName(iS
);
83 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
84 log
.print("Can't remove sheet by name");
85 e
.printStackTrace(log
);
87 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
88 log
.print("Can't remove sheet by name");
89 e
.printStackTrace(log
);
93 tRes
.tested("copyByName()", result
);
94 } // finished _copyByName
97 * Test inserts new sheet using the name returned by the method
98 * <code>newName</code>, moves the inserted sheet to the new position
99 * in collection, gets all element names in collection and checks the name
100 * of the sheet in the new position. <p>
101 * Has <b> OK </b> status if the sheet name in the new position is equal to
102 * the name of the sheet that was moved. <p>
104 public void _moveByName() {
105 //first insert one that should be moved
106 String iS
= newName("move");
107 oObj
.insertNewByName(iS
, (short) 0);
109 String
[] eNames
= oObj
.getElementNames();
110 String sheetToMove
= eNames
[0];
111 log
.println("Try to move " + sheetToMove
);
112 oObj
.moveByName(sheetToMove
, (short) 2);
113 eNames
= oObj
.getElementNames();
114 tRes
.tested("moveByName()", sheetToMove
.equals(eNames
[1]));
115 } // finished _moveByName
118 * Test inserts new sheet using the name returned by the method
119 * <code>newName</code>, checks the existence of the inserted sheet in
120 * the collection, removes the sheet, tries to insert the sheet with the
121 * bad name returned by method <code>badName()</code>. <p>
122 * Has <b> OK </b> status if the inserted sheet exists in the collection
123 * after first method call and if exception occurred during the second call. <p>
125 public void _insertNewByName() {
126 boolean result
= false;
128 String NewSheet
= newName("insert");
129 log
.println("Try to insert " + NewSheet
);
130 oObj
.insertNewByName(NewSheet
, (short) 0);
131 result
= oObj
.hasByName(NewSheet
);
134 oObj
.removeByName(NewSheet
);
135 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
136 log
.print("Can't remove sheet '" + NewSheet
+ "':");
137 e
.printStackTrace(log
);
139 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
140 log
.print("Can't remove sheet '" + NewSheet
+ "':");
141 e
.printStackTrace(log
);
146 NewSheet
= badName();
147 log
.println("Try to insert " + NewSheet
);
148 oObj
.insertNewByName(NewSheet
, (short) 0);
150 "No Exception thrown while inserting sheet with invalid name");
152 oObj
.removeByName(NewSheet
);
153 } catch (com
.sun
.star
.uno
.RuntimeException e
) {
155 "Expected exception occurred during testing 'insertNewByName'");
157 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
158 log
.print("Can't remove sheet '" + NewSheet
+ "':");
159 e
.printStackTrace(log
);
161 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
162 log
.print("Can't remove sheet '" + NewSheet
+ "':");
163 e
.printStackTrace(log
);
167 tRes
.tested("insertNewByName()", result
);
168 } // finished _insertByName
171 * Method returns unique new name using passed prefix and unique number
172 * of the current test.
174 public String
newName(String prefix
) {
175 return prefix
+ uniqNumber
;
176 } // finished newName
179 * Method return bad name for a sheet using the name of the current thread.
181 public String
badName() {
183 } // finished badName
184 } //finish class _XSpreadsheets