1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.sheet; 29 30 import java.util.Random; 31 32 import lib.MultiMethodTest; 33 34 import com.sun.star.beans.PropertyValue; 35 import com.sun.star.sheet.XFunctionDescriptions; 36 37 /** 38 * Testing <code>com.sun.star.sheet.XFunctionDescriptions</code> 39 * interface methods : 40 * <ul> 41 * <li><code> getById()</code></li> 42 * </ul> <p> 43 * @see com.sun.star.sheet.XFunctionDescriptions 44 */ 45 public class _XFunctionDescriptions extends MultiMethodTest { 46 47 public XFunctionDescriptions oObj = null; 48 49 /** 50 * Test finds available id, calls method using this id, checks returned 51 * value and then tries to get description with wrong id. <p> 52 * Has <b>OK</b> status if returned value is equal to value obtained by the 53 * method <code>getByIndex()</code> in first call and exception 54 * <code>IllegalArgumentException</code> was thrown in second call.<p> 55 * @see com.sun.star.lang.IllegalArgumentException 56 */ 57 public void _getById() { 58 boolean bResult = true; 59 // Finding available id... 60 61 int count = oObj.getCount(); 62 if (count > 0) { 63 Random rnd = new Random(); 64 int nr = rnd.nextInt(count); 65 66 PropertyValue[] PVals = null; 67 try { 68 PVals = (PropertyValue[])oObj.getByIndex(nr); 69 } catch(com.sun.star.lang.WrappedTargetException e) { 70 e.printStackTrace(log); 71 tRes.tested("getById()", false); 72 return; 73 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 74 e.printStackTrace(log); 75 tRes.tested("getById()", false); 76 return; 77 } 78 79 String FName = null; 80 Integer FId = null; 81 82 for (int i = 0; i < PVals.length; i++) { 83 if (PVals[i].Name.equals("Name")) 84 FName = (String)PVals[i].Value; 85 if (PVals[i].Name.equals("Id")) 86 FId = (Integer)PVals[i].Value; 87 } 88 89 log.println("The id of function '" + FName + "' is " + FId); 90 91 PropertyValue[] PVals2 = null; 92 try { 93 PVals2 = oObj.getById(FId.intValue()); 94 } catch(com.sun.star.lang.IllegalArgumentException e) { 95 e.printStackTrace(log); 96 tRes.tested("getById()", false); 97 return; 98 } 99 100 String objFName = null; 101 Integer objFId = null; 102 for (int i = 0; i < PVals2.length; i++) { 103 if (PVals2[i].Name.equals("Name")) 104 objFName = (String)PVals[i].Value; 105 if (PVals2[i].Name.equals("Id")) 106 objFId = (Integer)PVals[i].Value; 107 } 108 109 log.println("The id of returned function '" + 110 objFName + "' is " + objFId); 111 112 bResult &= FName.equals(objFName); 113 bResult &= FId.equals(objFId); 114 } 115 116 log.println("OK."); 117 118 try { 119 log.println("Now trying to get description with wrong id ... "); 120 oObj.getById(-1); 121 bResult = false; 122 log.println("Exception expected! - FAILED"); 123 } catch (com.sun.star.lang.IllegalArgumentException e) { 124 log.println("Expected exception " + e + " - OK!"); 125 } 126 127 tRes.tested("getById()", bResult); 128 } 129 } // finish class _XFunctionDescriptions 130 131 132