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 .
20 import com
.sun
.star
.sheet
.XSpreadsheets
;
22 import lib
.MultiMethodTest
;
26 * Testing <code>com.sun.star.sheet.XSpreadsheets</code>
29 * <li><code> insertNewByName()</code></li>
30 * <li><code> moveByName()</code></li>
31 * <li><code> copyByName()</code></li>
33 * Test is multithread compilant. <p>
34 * @see com.sun.star.sheet.XSpreadsheets
36 public class _XSpreadsheets
extends MultiMethodTest
{
37 protected static int uniqCount
= 0;
38 public XSpreadsheets oObj
= null;
39 protected int uniqNumber
= 0;
42 * Sets the unique number for the current test.
44 protected synchronized void before() {
45 uniqNumber
= uniqCount
++;
49 * Test inserts new sheet using the name returned by the method
50 * <code>newName</code>, copies inserted sheet with the new name,
51 * checks existence of the sheet with this name in collection and removes
52 * the both sheets from the collection. <p>
53 * Has <b> OK </b> status if the sheet with the name of the copy exists
54 * in the collection and no exceptions were thrown. <p>
56 public void _copyByName() {
57 boolean result
= true;
59 //first insert one that should be copied
60 String iS
= newName("copyFrom");
61 log
.println("Inserting sheet '" + iS
+ "'");
62 oObj
.insertNewByName(iS
, (short) 0);
64 String
[] eNames
= oObj
.getElementNames();
65 String NewSheet
= newName("copyTo");
66 log
.println("Try to copy " + eNames
[0] + " to " + NewSheet
);
67 oObj
.copyByName(eNames
[0], NewSheet
, (short) 0);
68 result
= oObj
.hasByName(NewSheet
);
70 //remove all inserted sheets
72 oObj
.removeByName(NewSheet
);
73 oObj
.removeByName(iS
);
74 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
75 log
.print("Can't remove sheet by name");
76 e
.printStackTrace(log
);
78 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
79 log
.print("Can't remove sheet by name");
80 e
.printStackTrace(log
);
84 tRes
.tested("copyByName()", result
);
85 } // finished _copyByName
88 * Test inserts new sheet using the name returned by the method
89 * <code>newName</code>, moves the inserted sheet to the new position
90 * in collection, gets all element names in collection and checks the name
91 * of the sheet in the new position. <p>
92 * Has <b> OK </b> status if the sheet name in the new position is equal to
93 * the name of the sheet that was moved. <p>
95 public void _moveByName() {
96 //first insert one that should be moved
97 String iS
= newName("move");
98 oObj
.insertNewByName(iS
, (short) 0);
100 String
[] eNames
= oObj
.getElementNames();
101 String sheetToMove
= eNames
[0];
102 log
.println("Try to move " + sheetToMove
);
103 oObj
.moveByName(sheetToMove
, (short) 2);
104 eNames
= oObj
.getElementNames();
105 tRes
.tested("moveByName()", sheetToMove
.equals(eNames
[1]));
106 } // finished _moveByName
109 * Test inserts new sheet using the name returned by the method
110 * <code>newName</code>, checks the existence of the inserted sheet in
111 * the collection, removes the sheet, tries to insert the sheet with the
112 * bad name returned by method <code>badName()</code>. <p>
113 * Has <b> OK </b> status if the inserted sheet exists in the collection
114 * after first method call and if exception occurred during the second call. <p>
116 public void _insertNewByName() {
117 boolean result
= false;
119 String NewSheet
= newName("insert");
120 log
.println("Try to insert " + NewSheet
);
121 oObj
.insertNewByName(NewSheet
, (short) 0);
122 result
= oObj
.hasByName(NewSheet
);
125 oObj
.removeByName(NewSheet
);
126 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
127 log
.print("Can't remove sheet '" + NewSheet
+ "':");
128 e
.printStackTrace(log
);
130 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
131 log
.print("Can't remove sheet '" + NewSheet
+ "':");
132 e
.printStackTrace(log
);
137 NewSheet
= badName();
138 log
.println("Try to insert " + NewSheet
);
139 oObj
.insertNewByName(NewSheet
, (short) 0);
141 "No Exception thrown while inserting sheet with invalid name");
143 oObj
.removeByName(NewSheet
);
144 } catch (com
.sun
.star
.uno
.RuntimeException e
) {
146 "Expected exception occurred during testing 'insertNewByName'");
148 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
149 log
.print("Can't remove sheet '" + NewSheet
+ "':");
150 e
.printStackTrace(log
);
152 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
153 log
.print("Can't remove sheet '" + NewSheet
+ "':");
154 e
.printStackTrace(log
);
158 tRes
.tested("insertNewByName()", result
);
159 } // finished _insertByName
162 * Method returns unique new name using passed prefix and unique number
163 * of the current test.
165 public String
newName(String prefix
) {
166 return prefix
+ uniqNumber
;
167 } // finished newName
170 * Method return bad name for a sheet using the name of the current thread.
172 public String
badName() {
174 } // finished badName
175 } //finish class _XSpreadsheets