1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XFunctionDescriptions.java,v $
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 ************************************************************************/
33 import java
.util
.Random
;
35 import lib
.MultiMethodTest
;
37 import com
.sun
.star
.beans
.PropertyValue
;
38 import com
.sun
.star
.sheet
.XFunctionDescriptions
;
41 * Testing <code>com.sun.star.sheet.XFunctionDescriptions</code>
44 * <li><code> getById()</code></li>
46 * @see com.sun.star.sheet.XFunctionDescriptions
48 public class _XFunctionDescriptions
extends MultiMethodTest
{
50 public XFunctionDescriptions oObj
= null;
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();
66 Random rnd
= new Random();
67 int nr
= rnd
.nextInt(count
);
69 PropertyValue
[] PVals
= null;
71 PVals
= (PropertyValue
[])oObj
.getByIndex(nr
);
72 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
73 e
.printStackTrace(log
);
74 tRes
.tested("getById()", false);
76 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
77 e
.printStackTrace(log
);
78 tRes
.tested("getById()", false);
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;
96 PVals2
= oObj
.getById(FId
.intValue());
97 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
98 e
.printStackTrace(log
);
99 tRes
.tested("getById()", false);
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
);
122 log
.println("Now trying to get description with wrong id ... ");
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