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