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 28*cdf0e10cSrcweir package ifc.sheet; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import java.util.Random; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import lib.MultiMethodTest; 33*cdf0e10cSrcweir import lib.Status; 34*cdf0e10cSrcweir import lib.StatusException; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 37*cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 38*cdf0e10cSrcweir import com.sun.star.sheet.XRecentFunctions; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir /** 41*cdf0e10cSrcweir * Testing <code>com.sun.star.sheet.XRecentFunctions</code> 42*cdf0e10cSrcweir * interface methods : 43*cdf0e10cSrcweir * <ul> 44*cdf0e10cSrcweir * <li><code> getRecentFunctionIds()</code></li> 45*cdf0e10cSrcweir * <li><code> setRecentFunctionIds()</code></li> 46*cdf0e10cSrcweir * <li><code> getMaxRecentFunctions()</code></li> 47*cdf0e10cSrcweir * </ul> <p> 48*cdf0e10cSrcweir * This test needs the following object relations : 49*cdf0e10cSrcweir * <ul> 50*cdf0e10cSrcweir * <li> <code>'FUNCTIONLIST'</code> (of type <code>XNameAccess</code>): 51*cdf0e10cSrcweir * to have the set of available functions </li> 52*cdf0e10cSrcweir * <ul> <p> 53*cdf0e10cSrcweir * @see com.sun.star.sheet.XRecentFunctions 54*cdf0e10cSrcweir */ 55*cdf0e10cSrcweir public class _XRecentFunctions extends MultiMethodTest { 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir public XRecentFunctions oObj = null; 58*cdf0e10cSrcweir int iMaxNumber = 0; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /** 61*cdf0e10cSrcweir * Test calls the method, checks returned value and stores it. <p> 62*cdf0e10cSrcweir * Has <b> OK </b> status if returned value isn't equal to zero. <p> 63*cdf0e10cSrcweir */ 64*cdf0e10cSrcweir public void _getMaxRecentFunctions() { 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir iMaxNumber = oObj.getMaxRecentFunctions(); 67*cdf0e10cSrcweir log.println("Maximum recent functions : " + iMaxNumber); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir tRes.tested("getMaxRecentFunctions()", iMaxNumber != 0); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /** 73*cdf0e10cSrcweir * Test calls the method and checks returned value. <p> 74*cdf0e10cSrcweir * Has <b> OK </b> status if returned value isn't null, if length of returned 75*cdf0e10cSrcweir * array is equal or less to the maximum number of functions and obtained 76*cdf0e10cSrcweir * array doesn't contain equal functions. <p> 77*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 78*cdf0e10cSrcweir * <ul> 79*cdf0e10cSrcweir * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number 80*cdf0e10cSrcweir * of recent functions </li> 81*cdf0e10cSrcweir * </ul> 82*cdf0e10cSrcweir */ 83*cdf0e10cSrcweir public void _getRecentFunctionIds() { 84*cdf0e10cSrcweir requiredMethod("getMaxRecentFunctions()"); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir boolean bResult = true; 87*cdf0e10cSrcweir int[] IDs = null; 88*cdf0e10cSrcweir int iNumber = 0; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir IDs = oObj.getRecentFunctionIds(); 91*cdf0e10cSrcweir iNumber = IDs.length; 92*cdf0e10cSrcweir bResult &= (iNumber <= iMaxNumber); 93*cdf0e10cSrcweir log.println("Now there are " + iNumber + " recent functions"); 94*cdf0e10cSrcweir bResult &= (IDs != null); 95*cdf0e10cSrcweir if (bResult) { 96*cdf0e10cSrcweir for (int i = 0; i < iNumber - 1; i++) 97*cdf0e10cSrcweir for (int j = i + 1; j < iNumber; j++) { 98*cdf0e10cSrcweir bResult &= (IDs[i] != IDs[j]); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir tRes.tested("getRecentFunctionIds()", bResult); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir /** 106*cdf0e10cSrcweir * Test gets the set of available functions, sets empty list of recent 107*cdf0e10cSrcweir * functions, sets list of maximum size. <p> 108*cdf0e10cSrcweir * Has <b> OK </b> status if length of recent function list is equal to zero 109*cdf0e10cSrcweir * after list was set to empty, if length of list is equal to maximum size 110*cdf0e10cSrcweir * after list was set to it's maximum size and no exception were thrown. <p> 111*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 112*cdf0e10cSrcweir * <ul> 113*cdf0e10cSrcweir * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number 114*cdf0e10cSrcweir * of recent functions </li> 115*cdf0e10cSrcweir * </ul> 116*cdf0e10cSrcweir */ 117*cdf0e10cSrcweir public void _setRecentFunctionIds() { 118*cdf0e10cSrcweir requiredMethod("getMaxRecentFunctions()"); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir boolean bResult = true; 121*cdf0e10cSrcweir int[] IDs = new int[0]; 122*cdf0e10cSrcweir XNameAccess functionList = null; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir log.println("First, get the set of available functions."); 125*cdf0e10cSrcweir functionList = (XNameAccess)tEnv.getObjRelation("FUNCTIONLIST"); 126*cdf0e10cSrcweir if (functionList == null) throw new StatusException(Status.failed 127*cdf0e10cSrcweir ("Relation 'FUNCTIONLIST' not found")); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir log.println("Now trying to set empty list."); 130*cdf0e10cSrcweir oObj.setRecentFunctionIds(IDs); 131*cdf0e10cSrcweir bResult &= (oObj.getRecentFunctionIds().length == 0); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir log.println("Now trying to set list of maximum size."); 134*cdf0e10cSrcweir String[] names = functionList.getElementNames(); 135*cdf0e10cSrcweir Random rnd = new Random(); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir IDs = new int[iMaxNumber]; 138*cdf0e10cSrcweir int startIdx = rnd.nextInt(names.length - iMaxNumber - 1) + 1; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir try { 141*cdf0e10cSrcweir for (int i = startIdx; i < startIdx + iMaxNumber; i++) { 142*cdf0e10cSrcweir PropertyValue[] propVals = (PropertyValue[]) 143*cdf0e10cSrcweir functionList.getByName(names[i]); 144*cdf0e10cSrcweir for (int j = 0; j < propVals.length; j++) { 145*cdf0e10cSrcweir String propName = (String)propVals[j].Name; 146*cdf0e10cSrcweir if (propName.equals("Id")) { 147*cdf0e10cSrcweir IDs[i - startIdx] = 148*cdf0e10cSrcweir ((Integer)propVals[j].Value).intValue(); 149*cdf0e10cSrcweir break; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e) { 154*cdf0e10cSrcweir e.printStackTrace(log); 155*cdf0e10cSrcweir bResult = false; 156*cdf0e10cSrcweir } catch(com.sun.star.container.NoSuchElementException e) { 157*cdf0e10cSrcweir e.printStackTrace(log); 158*cdf0e10cSrcweir bResult = false; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir oObj.setRecentFunctionIds(IDs); 162*cdf0e10cSrcweir bResult &= (oObj.getRecentFunctionIds().length == iMaxNumber); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir tRes.tested("setRecentFunctionIds()", bResult); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169