1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package ifc.sheet; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir import lib.MultiMethodTest; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir /** 35*cdf0e10cSrcweir * Testing <code>com.sun.star.sheet.XSpreadsheets</code> 36*cdf0e10cSrcweir * interface methods : 37*cdf0e10cSrcweir * <ul> 38*cdf0e10cSrcweir * <li><code> insertNewByName()</code></li> 39*cdf0e10cSrcweir * <li><code> moveByName()</code></li> 40*cdf0e10cSrcweir * <li><code> copyByName()</code></li> 41*cdf0e10cSrcweir * </ul> <p> 42*cdf0e10cSrcweir * Test is multithread compilant. <p> 43*cdf0e10cSrcweir * @see com.sun.star.sheet.XSpreadsheets 44*cdf0e10cSrcweir */ 45*cdf0e10cSrcweir public class _XSpreadsheets extends MultiMethodTest { 46*cdf0e10cSrcweir protected static int uniqCount = 0; 47*cdf0e10cSrcweir public XSpreadsheets oObj = null; 48*cdf0e10cSrcweir protected int uniqNumber = 0; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir /** 51*cdf0e10cSrcweir * Sets the unique number for the current test. 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir protected synchronized void before() { 54*cdf0e10cSrcweir uniqNumber = uniqCount++; 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir /** 58*cdf0e10cSrcweir * Test inserts new sheet using the name returned by the method 59*cdf0e10cSrcweir * <code>newName</code>, copies inserted sheet with the new name, 60*cdf0e10cSrcweir * checks existence of the sheet with this name in collection and removes 61*cdf0e10cSrcweir * the both sheets from the collection. <p> 62*cdf0e10cSrcweir * Has <b> OK </b> status if the sheet with the name of the copy exists 63*cdf0e10cSrcweir * in the collection and no exceptions were thrown. <p> 64*cdf0e10cSrcweir */ 65*cdf0e10cSrcweir public void _copyByName() { 66*cdf0e10cSrcweir boolean result = true; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //first insert one that should be copied 69*cdf0e10cSrcweir String iS = newName("copyFrom"); 70*cdf0e10cSrcweir log.println("Inserting sheet '" + iS + "'"); 71*cdf0e10cSrcweir oObj.insertNewByName(iS, (short) 0); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir String[] eNames = oObj.getElementNames(); 74*cdf0e10cSrcweir String NewSheet = newName("copyTo"); 75*cdf0e10cSrcweir log.println("Try to copy " + eNames[0] + " to " + NewSheet); 76*cdf0e10cSrcweir oObj.copyByName(eNames[0], NewSheet, (short) 0); 77*cdf0e10cSrcweir result = oObj.hasByName(NewSheet); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //remove all inserted sheets 80*cdf0e10cSrcweir try { 81*cdf0e10cSrcweir oObj.removeByName(NewSheet); 82*cdf0e10cSrcweir oObj.removeByName(iS); 83*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 84*cdf0e10cSrcweir log.print("Can't remove sheet by name"); 85*cdf0e10cSrcweir e.printStackTrace(log); 86*cdf0e10cSrcweir result = false; 87*cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 88*cdf0e10cSrcweir log.print("Can't remove sheet by name"); 89*cdf0e10cSrcweir e.printStackTrace(log); 90*cdf0e10cSrcweir result = false; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir tRes.tested("copyByName()", result); 94*cdf0e10cSrcweir } // finished _copyByName 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir /** 97*cdf0e10cSrcweir * Test inserts new sheet using the name returned by the method 98*cdf0e10cSrcweir * <code>newName</code>, moves the inserted sheet to the new position 99*cdf0e10cSrcweir * in collection, gets all element names in collection and checks the name 100*cdf0e10cSrcweir * of the sheet in the new position. <p> 101*cdf0e10cSrcweir * Has <b> OK </b> status if the sheet name in the new position is equal to 102*cdf0e10cSrcweir * the name of the sheet that was moved. <p> 103*cdf0e10cSrcweir */ 104*cdf0e10cSrcweir public void _moveByName() { 105*cdf0e10cSrcweir //first insert one that should be moved 106*cdf0e10cSrcweir String iS = newName("move"); 107*cdf0e10cSrcweir oObj.insertNewByName(iS, (short) 0); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir String[] eNames = oObj.getElementNames(); 110*cdf0e10cSrcweir String sheetToMove = eNames[0]; 111*cdf0e10cSrcweir log.println("Try to move " + sheetToMove); 112*cdf0e10cSrcweir oObj.moveByName(sheetToMove, (short) 2); 113*cdf0e10cSrcweir eNames = oObj.getElementNames(); 114*cdf0e10cSrcweir tRes.tested("moveByName()", sheetToMove.equals(eNames[1])); 115*cdf0e10cSrcweir } // finished _moveByName 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir /** 118*cdf0e10cSrcweir * Test inserts new sheet using the name returned by the method 119*cdf0e10cSrcweir * <code>newName</code>, checks the existence of the inserted sheet in 120*cdf0e10cSrcweir * the collection, removes the sheet, tries to insert the sheet with the 121*cdf0e10cSrcweir * bad name returned by method <code>badName()</code>. <p> 122*cdf0e10cSrcweir * Has <b> OK </b> status if the inserted sheet exists in the collection 123*cdf0e10cSrcweir * after first method call and if exception occured during the second call. <p> 124*cdf0e10cSrcweir */ 125*cdf0e10cSrcweir public void _insertNewByName() { 126*cdf0e10cSrcweir boolean result = false; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir String NewSheet = newName("insert"); 129*cdf0e10cSrcweir log.println("Try to insert " + NewSheet); 130*cdf0e10cSrcweir oObj.insertNewByName(NewSheet, (short) 0); 131*cdf0e10cSrcweir result = oObj.hasByName(NewSheet); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir try { 134*cdf0e10cSrcweir oObj.removeByName(NewSheet); 135*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 136*cdf0e10cSrcweir log.print("Can't remove sheet '" + NewSheet + "':"); 137*cdf0e10cSrcweir e.printStackTrace(log); 138*cdf0e10cSrcweir result = false; 139*cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 140*cdf0e10cSrcweir log.print("Can't remove sheet '" + NewSheet + "':"); 141*cdf0e10cSrcweir e.printStackTrace(log); 142*cdf0e10cSrcweir result = false; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir try { 146*cdf0e10cSrcweir NewSheet = badName(); 147*cdf0e10cSrcweir log.println("Try to insert " + NewSheet); 148*cdf0e10cSrcweir oObj.insertNewByName(NewSheet, (short) 0); 149*cdf0e10cSrcweir log.println( 150*cdf0e10cSrcweir "No Exception thrown while inserting sheet with invalid name"); 151*cdf0e10cSrcweir result &= false; 152*cdf0e10cSrcweir oObj.removeByName(NewSheet); 153*cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 154*cdf0e10cSrcweir log.println( 155*cdf0e10cSrcweir "Expected exception occured during testing 'insertNewByName'"); 156*cdf0e10cSrcweir result &= true; 157*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 158*cdf0e10cSrcweir log.print("Can't remove sheet '" + NewSheet + "':"); 159*cdf0e10cSrcweir e.printStackTrace(log); 160*cdf0e10cSrcweir result = false; 161*cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 162*cdf0e10cSrcweir log.print("Can't remove sheet '" + NewSheet + "':"); 163*cdf0e10cSrcweir e.printStackTrace(log); 164*cdf0e10cSrcweir result = false; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir tRes.tested("insertNewByName()", result); 168*cdf0e10cSrcweir } // finished _insertByName 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir /** 171*cdf0e10cSrcweir * Method returns unique new name using passed prefix and unique number 172*cdf0e10cSrcweir * of the current test. 173*cdf0e10cSrcweir */ 174*cdf0e10cSrcweir public String newName(String prefix) { 175*cdf0e10cSrcweir return prefix + uniqNumber; 176*cdf0e10cSrcweir } // finished newName 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir /** 179*cdf0e10cSrcweir * Method return bad name for a sheet using the name of the current thread. 180*cdf0e10cSrcweir */ 181*cdf0e10cSrcweir public String badName() { 182*cdf0e10cSrcweir return "$%#/?\\"; 183*cdf0e10cSrcweir } // finished badName 184*cdf0e10cSrcweir } //finish class _XSpreadsheets 185