1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski package ifc.sheet; 25*b1cdbd2cSJim Jagielski 26*b1cdbd2cSJim Jagielski import java.util.Random; 27*b1cdbd2cSJim Jagielski 28*b1cdbd2cSJim Jagielski import lib.MultiMethodTest; 29*b1cdbd2cSJim Jagielski import lib.Status; 30*b1cdbd2cSJim Jagielski import lib.StatusException; 31*b1cdbd2cSJim Jagielski 32*b1cdbd2cSJim Jagielski import com.sun.star.beans.PropertyValue; 33*b1cdbd2cSJim Jagielski import com.sun.star.container.XNameAccess; 34*b1cdbd2cSJim Jagielski import com.sun.star.sheet.XRecentFunctions; 35*b1cdbd2cSJim Jagielski 36*b1cdbd2cSJim Jagielski /** 37*b1cdbd2cSJim Jagielski * Testing <code>com.sun.star.sheet.XRecentFunctions</code> 38*b1cdbd2cSJim Jagielski * interface methods : 39*b1cdbd2cSJim Jagielski * <ul> 40*b1cdbd2cSJim Jagielski * <li><code> getRecentFunctionIds()</code></li> 41*b1cdbd2cSJim Jagielski * <li><code> setRecentFunctionIds()</code></li> 42*b1cdbd2cSJim Jagielski * <li><code> getMaxRecentFunctions()</code></li> 43*b1cdbd2cSJim Jagielski * </ul> <p> 44*b1cdbd2cSJim Jagielski * This test needs the following object relations : 45*b1cdbd2cSJim Jagielski * <ul> 46*b1cdbd2cSJim Jagielski * <li> <code>'FUNCTIONLIST'</code> (of type <code>XNameAccess</code>): 47*b1cdbd2cSJim Jagielski * to have the set of available functions </li> 48*b1cdbd2cSJim Jagielski * <ul> <p> 49*b1cdbd2cSJim Jagielski * @see com.sun.star.sheet.XRecentFunctions 50*b1cdbd2cSJim Jagielski */ 51*b1cdbd2cSJim Jagielski public class _XRecentFunctions extends MultiMethodTest { 52*b1cdbd2cSJim Jagielski 53*b1cdbd2cSJim Jagielski public XRecentFunctions oObj = null; 54*b1cdbd2cSJim Jagielski int iMaxNumber = 0; 55*b1cdbd2cSJim Jagielski 56*b1cdbd2cSJim Jagielski /** 57*b1cdbd2cSJim Jagielski * Test calls the method, checks returned value and stores it. <p> 58*b1cdbd2cSJim Jagielski * Has <b> OK </b> status if returned value isn't equal to zero. <p> 59*b1cdbd2cSJim Jagielski */ _getMaxRecentFunctions()60*b1cdbd2cSJim Jagielski public void _getMaxRecentFunctions() { 61*b1cdbd2cSJim Jagielski 62*b1cdbd2cSJim Jagielski iMaxNumber = oObj.getMaxRecentFunctions(); 63*b1cdbd2cSJim Jagielski log.println("Maximum recent functions : " + iMaxNumber); 64*b1cdbd2cSJim Jagielski 65*b1cdbd2cSJim Jagielski tRes.tested("getMaxRecentFunctions()", iMaxNumber != 0); 66*b1cdbd2cSJim Jagielski } 67*b1cdbd2cSJim Jagielski 68*b1cdbd2cSJim Jagielski /** 69*b1cdbd2cSJim Jagielski * Test calls the method and checks returned value. <p> 70*b1cdbd2cSJim Jagielski * Has <b> OK </b> status if returned value isn't null, if length of returned 71*b1cdbd2cSJim Jagielski * array is equal or less to the maximum number of functions and obtained 72*b1cdbd2cSJim Jagielski * array doesn't contain equal functions. <p> 73*b1cdbd2cSJim Jagielski * The following method tests are to be completed successfully before : 74*b1cdbd2cSJim Jagielski * <ul> 75*b1cdbd2cSJim Jagielski * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number 76*b1cdbd2cSJim Jagielski * of recent functions </li> 77*b1cdbd2cSJim Jagielski * </ul> 78*b1cdbd2cSJim Jagielski */ _getRecentFunctionIds()79*b1cdbd2cSJim Jagielski public void _getRecentFunctionIds() { 80*b1cdbd2cSJim Jagielski requiredMethod("getMaxRecentFunctions()"); 81*b1cdbd2cSJim Jagielski 82*b1cdbd2cSJim Jagielski boolean bResult = true; 83*b1cdbd2cSJim Jagielski int[] IDs = null; 84*b1cdbd2cSJim Jagielski int iNumber = 0; 85*b1cdbd2cSJim Jagielski 86*b1cdbd2cSJim Jagielski IDs = oObj.getRecentFunctionIds(); 87*b1cdbd2cSJim Jagielski iNumber = IDs.length; 88*b1cdbd2cSJim Jagielski bResult &= (iNumber <= iMaxNumber); 89*b1cdbd2cSJim Jagielski log.println("Now there are " + iNumber + " recent functions"); 90*b1cdbd2cSJim Jagielski bResult &= (IDs != null); 91*b1cdbd2cSJim Jagielski if (bResult) { 92*b1cdbd2cSJim Jagielski for (int i = 0; i < iNumber - 1; i++) 93*b1cdbd2cSJim Jagielski for (int j = i + 1; j < iNumber; j++) { 94*b1cdbd2cSJim Jagielski bResult &= (IDs[i] != IDs[j]); 95*b1cdbd2cSJim Jagielski } 96*b1cdbd2cSJim Jagielski } 97*b1cdbd2cSJim Jagielski 98*b1cdbd2cSJim Jagielski tRes.tested("getRecentFunctionIds()", bResult); 99*b1cdbd2cSJim Jagielski } 100*b1cdbd2cSJim Jagielski 101*b1cdbd2cSJim Jagielski /** 102*b1cdbd2cSJim Jagielski * Test gets the set of available functions, sets empty list of recent 103*b1cdbd2cSJim Jagielski * functions, sets list of maximum size. <p> 104*b1cdbd2cSJim Jagielski * Has <b> OK </b> status if length of recent function list is equal to zero 105*b1cdbd2cSJim Jagielski * after list was set to empty, if length of list is equal to maximum size 106*b1cdbd2cSJim Jagielski * after list was set to it's maximum size and no exception were thrown. <p> 107*b1cdbd2cSJim Jagielski * The following method tests are to be completed successfully before : 108*b1cdbd2cSJim Jagielski * <ul> 109*b1cdbd2cSJim Jagielski * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number 110*b1cdbd2cSJim Jagielski * of recent functions </li> 111*b1cdbd2cSJim Jagielski * </ul> 112*b1cdbd2cSJim Jagielski */ _setRecentFunctionIds()113*b1cdbd2cSJim Jagielski public void _setRecentFunctionIds() { 114*b1cdbd2cSJim Jagielski requiredMethod("getMaxRecentFunctions()"); 115*b1cdbd2cSJim Jagielski 116*b1cdbd2cSJim Jagielski boolean bResult = true; 117*b1cdbd2cSJim Jagielski int[] IDs = new int[0]; 118*b1cdbd2cSJim Jagielski XNameAccess functionList = null; 119*b1cdbd2cSJim Jagielski 120*b1cdbd2cSJim Jagielski log.println("First, get the set of available functions."); 121*b1cdbd2cSJim Jagielski functionList = (XNameAccess)tEnv.getObjRelation("FUNCTIONLIST"); 122*b1cdbd2cSJim Jagielski if (functionList == null) throw new StatusException(Status.failed 123*b1cdbd2cSJim Jagielski ("Relation 'FUNCTIONLIST' not found")); 124*b1cdbd2cSJim Jagielski 125*b1cdbd2cSJim Jagielski log.println("Now trying to set empty list."); 126*b1cdbd2cSJim Jagielski oObj.setRecentFunctionIds(IDs); 127*b1cdbd2cSJim Jagielski bResult &= (oObj.getRecentFunctionIds().length == 0); 128*b1cdbd2cSJim Jagielski 129*b1cdbd2cSJim Jagielski log.println("Now trying to set list of maximum size."); 130*b1cdbd2cSJim Jagielski String[] names = functionList.getElementNames(); 131*b1cdbd2cSJim Jagielski Random rnd = new Random(); 132*b1cdbd2cSJim Jagielski 133*b1cdbd2cSJim Jagielski IDs = new int[iMaxNumber]; 134*b1cdbd2cSJim Jagielski int startIdx = rnd.nextInt(names.length - iMaxNumber - 1) + 1; 135*b1cdbd2cSJim Jagielski 136*b1cdbd2cSJim Jagielski try { 137*b1cdbd2cSJim Jagielski for (int i = startIdx; i < startIdx + iMaxNumber; i++) { 138*b1cdbd2cSJim Jagielski PropertyValue[] propVals = (PropertyValue[]) 139*b1cdbd2cSJim Jagielski functionList.getByName(names[i]); 140*b1cdbd2cSJim Jagielski for (int j = 0; j < propVals.length; j++) { 141*b1cdbd2cSJim Jagielski String propName = (String)propVals[j].Name; 142*b1cdbd2cSJim Jagielski if (propName.equals("Id")) { 143*b1cdbd2cSJim Jagielski IDs[i - startIdx] = 144*b1cdbd2cSJim Jagielski ((Integer)propVals[j].Value).intValue(); 145*b1cdbd2cSJim Jagielski break; 146*b1cdbd2cSJim Jagielski } 147*b1cdbd2cSJim Jagielski } 148*b1cdbd2cSJim Jagielski } 149*b1cdbd2cSJim Jagielski } catch(com.sun.star.lang.WrappedTargetException e) { 150*b1cdbd2cSJim Jagielski e.printStackTrace(log); 151*b1cdbd2cSJim Jagielski bResult = false; 152*b1cdbd2cSJim Jagielski } catch(com.sun.star.container.NoSuchElementException e) { 153*b1cdbd2cSJim Jagielski e.printStackTrace(log); 154*b1cdbd2cSJim Jagielski bResult = false; 155*b1cdbd2cSJim Jagielski } 156*b1cdbd2cSJim Jagielski 157*b1cdbd2cSJim Jagielski oObj.setRecentFunctionIds(IDs); 158*b1cdbd2cSJim Jagielski bResult &= (oObj.getRecentFunctionIds().length == iMaxNumber); 159*b1cdbd2cSJim Jagielski 160*b1cdbd2cSJim Jagielski tRes.tested("setRecentFunctionIds()", bResult); 161*b1cdbd2cSJim Jagielski } 162*b1cdbd2cSJim Jagielski 163*b1cdbd2cSJim Jagielski } 164*b1cdbd2cSJim Jagielski 165