1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.sheet; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import lib.MultiMethodTest; 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** 31cdf0e10cSrcweir * Testing <code>com.sun.star.sheet.XSpreadsheets</code> 32cdf0e10cSrcweir * interface methods : 33cdf0e10cSrcweir * <ul> 34cdf0e10cSrcweir * <li><code> insertNewByName()</code></li> 35cdf0e10cSrcweir * <li><code> moveByName()</code></li> 36cdf0e10cSrcweir * <li><code> copyByName()</code></li> 37cdf0e10cSrcweir * </ul> <p> 38cdf0e10cSrcweir * Test is multithread compilant. <p> 39cdf0e10cSrcweir * @see com.sun.star.sheet.XSpreadsheets 40cdf0e10cSrcweir */ 41cdf0e10cSrcweir public class _XSpreadsheets extends MultiMethodTest { 42cdf0e10cSrcweir protected static int uniqCount = 0; 43cdf0e10cSrcweir public XSpreadsheets oObj = null; 44cdf0e10cSrcweir protected int uniqNumber = 0; 45cdf0e10cSrcweir 46cdf0e10cSrcweir /** 47cdf0e10cSrcweir * Sets the unique number for the current test. 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir protected synchronized void before() { 50cdf0e10cSrcweir uniqNumber = uniqCount++; 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir /** 54cdf0e10cSrcweir * Test inserts new sheet using the name returned by the method 55cdf0e10cSrcweir * <code>newName</code>, copies inserted sheet with the new name, 56cdf0e10cSrcweir * checks existence of the sheet with this name in collection and removes 57cdf0e10cSrcweir * the both sheets from the collection. <p> 58cdf0e10cSrcweir * Has <b> OK </b> status if the sheet with the name of the copy exists 59cdf0e10cSrcweir * in the collection and no exceptions were thrown. <p> 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir public void _copyByName() { 62cdf0e10cSrcweir boolean result = true; 63cdf0e10cSrcweir 64cdf0e10cSrcweir //first insert one that should be copied 65cdf0e10cSrcweir String iS = newName("copyFrom"); 66cdf0e10cSrcweir log.println("Inserting sheet '" + iS + "'"); 67cdf0e10cSrcweir oObj.insertNewByName(iS, (short) 0); 68cdf0e10cSrcweir 69cdf0e10cSrcweir String[] eNames = oObj.getElementNames(); 70cdf0e10cSrcweir String NewSheet = newName("copyTo"); 71cdf0e10cSrcweir log.println("Try to copy " + eNames[0] + " to " + NewSheet); 72cdf0e10cSrcweir oObj.copyByName(eNames[0], NewSheet, (short) 0); 73cdf0e10cSrcweir result = oObj.hasByName(NewSheet); 74cdf0e10cSrcweir 75cdf0e10cSrcweir //remove all inserted sheets 76cdf0e10cSrcweir try { 77cdf0e10cSrcweir oObj.removeByName(NewSheet); 78cdf0e10cSrcweir oObj.removeByName(iS); 79cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 80cdf0e10cSrcweir log.print("Can't remove sheet by name"); 81cdf0e10cSrcweir e.printStackTrace(log); 82cdf0e10cSrcweir result = false; 83cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 84cdf0e10cSrcweir log.print("Can't remove sheet by name"); 85cdf0e10cSrcweir e.printStackTrace(log); 86cdf0e10cSrcweir result = false; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir tRes.tested("copyByName()", result); 90cdf0e10cSrcweir } // finished _copyByName 91cdf0e10cSrcweir 92cdf0e10cSrcweir /** 93cdf0e10cSrcweir * Test inserts new sheet using the name returned by the method 94cdf0e10cSrcweir * <code>newName</code>, moves the inserted sheet to the new position 95cdf0e10cSrcweir * in collection, gets all element names in collection and checks the name 96cdf0e10cSrcweir * of the sheet in the new position. <p> 97cdf0e10cSrcweir * Has <b> OK </b> status if the sheet name in the new position is equal to 98cdf0e10cSrcweir * the name of the sheet that was moved. <p> 99cdf0e10cSrcweir */ 100cdf0e10cSrcweir public void _moveByName() { 101cdf0e10cSrcweir //first insert one that should be moved 102cdf0e10cSrcweir String iS = newName("move"); 103cdf0e10cSrcweir oObj.insertNewByName(iS, (short) 0); 104cdf0e10cSrcweir 105cdf0e10cSrcweir String[] eNames = oObj.getElementNames(); 106cdf0e10cSrcweir String sheetToMove = eNames[0]; 107cdf0e10cSrcweir log.println("Try to move " + sheetToMove); 108cdf0e10cSrcweir oObj.moveByName(sheetToMove, (short) 2); 109cdf0e10cSrcweir eNames = oObj.getElementNames(); 110cdf0e10cSrcweir tRes.tested("moveByName()", sheetToMove.equals(eNames[1])); 111cdf0e10cSrcweir } // finished _moveByName 112cdf0e10cSrcweir 113cdf0e10cSrcweir /** 114cdf0e10cSrcweir * Test inserts new sheet using the name returned by the method 115cdf0e10cSrcweir * <code>newName</code>, checks the existence of the inserted sheet in 116cdf0e10cSrcweir * the collection, removes the sheet, tries to insert the sheet with the 117cdf0e10cSrcweir * bad name returned by method <code>badName()</code>. <p> 118cdf0e10cSrcweir * Has <b> OK </b> status if the inserted sheet exists in the collection 119cdf0e10cSrcweir * after first method call and if exception occured during the second call. <p> 120cdf0e10cSrcweir */ 121cdf0e10cSrcweir public void _insertNewByName() { 122cdf0e10cSrcweir boolean result = false; 123cdf0e10cSrcweir 124cdf0e10cSrcweir String NewSheet = newName("insert"); 125cdf0e10cSrcweir log.println("Try to insert " + NewSheet); 126cdf0e10cSrcweir oObj.insertNewByName(NewSheet, (short) 0); 127cdf0e10cSrcweir result = oObj.hasByName(NewSheet); 128cdf0e10cSrcweir 129cdf0e10cSrcweir try { 130cdf0e10cSrcweir oObj.removeByName(NewSheet); 131cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 132cdf0e10cSrcweir log.print("Can't remove sheet '" + NewSheet + "':"); 133cdf0e10cSrcweir e.printStackTrace(log); 134cdf0e10cSrcweir result = false; 135cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 136cdf0e10cSrcweir log.print("Can't remove sheet '" + NewSheet + "':"); 137cdf0e10cSrcweir e.printStackTrace(log); 138cdf0e10cSrcweir result = false; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir try { 142cdf0e10cSrcweir NewSheet = badName(); 143cdf0e10cSrcweir log.println("Try to insert " + NewSheet); 144cdf0e10cSrcweir oObj.insertNewByName(NewSheet, (short) 0); 145cdf0e10cSrcweir log.println( 146cdf0e10cSrcweir "No Exception thrown while inserting sheet with invalid name"); 147cdf0e10cSrcweir result &= false; 148cdf0e10cSrcweir oObj.removeByName(NewSheet); 149cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 150cdf0e10cSrcweir log.println( 151cdf0e10cSrcweir "Expected exception occured during testing 'insertNewByName'"); 152cdf0e10cSrcweir result &= true; 153cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 154cdf0e10cSrcweir log.print("Can't remove sheet '" + NewSheet + "':"); 155cdf0e10cSrcweir e.printStackTrace(log); 156cdf0e10cSrcweir result = false; 157cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 158cdf0e10cSrcweir log.print("Can't remove sheet '" + NewSheet + "':"); 159cdf0e10cSrcweir e.printStackTrace(log); 160cdf0e10cSrcweir result = false; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir tRes.tested("insertNewByName()", result); 164cdf0e10cSrcweir } // finished _insertByName 165cdf0e10cSrcweir 166cdf0e10cSrcweir /** 167cdf0e10cSrcweir * Method returns unique new name using passed prefix and unique number 168cdf0e10cSrcweir * of the current test. 169cdf0e10cSrcweir */ 170cdf0e10cSrcweir public String newName(String prefix) { 171cdf0e10cSrcweir return prefix + uniqNumber; 172cdf0e10cSrcweir } // finished newName 173cdf0e10cSrcweir 174cdf0e10cSrcweir /** 175cdf0e10cSrcweir * Method return bad name for a sheet using the name of the current thread. 176cdf0e10cSrcweir */ 177cdf0e10cSrcweir public String badName() { 178cdf0e10cSrcweir return "$%#/?\\"; 179cdf0e10cSrcweir } // finished badName 180cdf0e10cSrcweir } //finish class _XSpreadsheets 181