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 compliant. <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.
45 protected synchronized void before() {
46 uniqNumber
= uniqCount
++;
50 * Test inserts new sheet using the name returned by the method
51 * <code>newName</code>, copies inserted sheet with the new name,
52 * checks existence of the sheet with this name in collection and removes
53 * the both sheets from the collection. <p>
54 * Has <b> OK </b> status if the sheet with the name of the copy exists
55 * in the collection and no exceptions were thrown. <p>
57 public void _copyByName() {
58 boolean result
= true;
60 //first insert one that should be copied
61 String iS
= newName("copyFrom");
62 log
.println("Inserting sheet '" + iS
+ "'");
63 oObj
.insertNewByName(iS
, (short) 0);
65 String
[] eNames
= oObj
.getElementNames();
66 String NewSheet
= newName("copyTo");
67 log
.println("Try to copy " + eNames
[0] + " to " + NewSheet
);
68 oObj
.copyByName(eNames
[0], NewSheet
, (short) 0);
69 result
= oObj
.hasByName(NewSheet
);
71 //remove all inserted sheets
73 oObj
.removeByName(NewSheet
);
74 oObj
.removeByName(iS
);
75 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
76 log
.print("Can't remove sheet by name");
77 e
.printStackTrace(log
);
79 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
80 log
.print("Can't remove sheet by name");
81 e
.printStackTrace(log
);
85 tRes
.tested("copyByName()", result
);
86 } // finished _copyByName
89 * Test inserts new sheet using the name returned by the method
90 * <code>newName</code>, moves the inserted sheet to the new position
91 * in collection, gets all element names in collection and checks the name
92 * of the sheet in the new position. <p>
93 * Has <b> OK </b> status if the sheet name in the new position is equal to
94 * the name of the sheet that was moved. <p>
96 public void _moveByName() {
97 //first insert one that should be moved
98 String iS
= newName("move");
99 oObj
.insertNewByName(iS
, (short) 0);
101 String
[] eNames
= oObj
.getElementNames();
102 String sheetToMove
= eNames
[0];
103 log
.println("Try to move " + sheetToMove
);
104 oObj
.moveByName(sheetToMove
, (short) 2);
105 eNames
= oObj
.getElementNames();
106 tRes
.tested("moveByName()", sheetToMove
.equals(eNames
[1]));
107 } // finished _moveByName
110 * Test inserts new sheet using the name returned by the method
111 * <code>newName</code>, checks the existence of the inserted sheet in
112 * the collection, removes the sheet, tries to insert the sheet with the
113 * bad name returned by method <code>badName()</code>. <p>
114 * Has <b> OK </b> status if the inserted sheet exists in the collection
115 * after first method call and if exception occurred during the second call. <p>
117 public void _insertNewByName() {
118 boolean result
= false;
120 String NewSheet
= newName("insert");
121 log
.println("Try to insert " + NewSheet
);
122 oObj
.insertNewByName(NewSheet
, (short) 0);
123 result
= oObj
.hasByName(NewSheet
);
126 oObj
.removeByName(NewSheet
);
127 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
128 log
.print("Can't remove sheet '" + NewSheet
+ "':");
129 e
.printStackTrace(log
);
131 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
132 log
.print("Can't remove sheet '" + NewSheet
+ "':");
133 e
.printStackTrace(log
);
138 NewSheet
= badName();
139 log
.println("Try to insert " + NewSheet
);
140 oObj
.insertNewByName(NewSheet
, (short) 0);
142 "No Exception thrown while inserting sheet with invalid name");
144 oObj
.removeByName(NewSheet
);
145 } catch (com
.sun
.star
.uno
.RuntimeException e
) {
147 "Expected exception occurred during testing 'insertNewByName'");
149 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
150 log
.print("Can't remove sheet '" + NewSheet
+ "':");
151 e
.printStackTrace(log
);
153 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
154 log
.print("Can't remove sheet '" + NewSheet
+ "':");
155 e
.printStackTrace(log
);
159 tRes
.tested("insertNewByName()", result
);
160 } // finished _insertByName
163 * Method returns unique new name using passed prefix and unique number
164 * of the current test.
166 public String
newName(String prefix
) {
167 return prefix
+ uniqNumber
;
168 } // finished newName
171 * Method return bad name for a sheet using the name of the current thread.
173 public String
badName() {
175 } // finished badName
176 } //finish class _XSpreadsheets