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: _XRecentFunctions.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 lib
.StatusException
;
39 import com
.sun
.star
.beans
.PropertyValue
;
40 import com
.sun
.star
.container
.XNameAccess
;
41 import com
.sun
.star
.sheet
.XRecentFunctions
;
44 * Testing <code>com.sun.star.sheet.XRecentFunctions</code>
47 * <li><code> getRecentFunctionIds()</code></li>
48 * <li><code> setRecentFunctionIds()</code></li>
49 * <li><code> getMaxRecentFunctions()</code></li>
51 * This test needs the following object relations :
53 * <li> <code>'FUNCTIONLIST'</code> (of type <code>XNameAccess</code>):
54 * to have the set of available functions </li>
56 * @see com.sun.star.sheet.XRecentFunctions
58 public class _XRecentFunctions
extends MultiMethodTest
{
60 public XRecentFunctions oObj
= null;
64 * Test calls the method, checks returned value and stores it. <p>
65 * Has <b> OK </b> status if returned value isn't equal to zero. <p>
67 public void _getMaxRecentFunctions() {
69 iMaxNumber
= oObj
.getMaxRecentFunctions();
70 log
.println("Maximum recent functions : " + iMaxNumber
);
72 tRes
.tested("getMaxRecentFunctions()", iMaxNumber
!= 0);
76 * Test calls the method and checks returned value. <p>
77 * Has <b> OK </b> status if returned value isn't null, if length of returned
78 * array is equal or less to the maximum number of functions and obtained
79 * array doesn't contain equal functions. <p>
80 * The following method tests are to be completed successfully before :
82 * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number
83 * of recent functions </li>
86 public void _getRecentFunctionIds() {
87 requiredMethod("getMaxRecentFunctions()");
89 boolean bResult
= true;
93 IDs
= oObj
.getRecentFunctionIds();
95 bResult
&= (iNumber
<= iMaxNumber
);
96 log
.println("Now there are " + iNumber
+ " recent functions");
97 bResult
&= (IDs
!= null);
99 for (int i
= 0; i
< iNumber
- 1; i
++)
100 for (int j
= i
+ 1; j
< iNumber
; j
++) {
101 bResult
&= (IDs
[i
] != IDs
[j
]);
105 tRes
.tested("getRecentFunctionIds()", bResult
);
109 * Test gets the set of available functions, sets empty list of recent
110 * functions, sets list of maximum size. <p>
111 * Has <b> OK </b> status if length of recent function list is equal to zero
112 * after list was set to empty, if length of list is equal to maximum size
113 * after list was set to it's maximum size and no exception were thrown. <p>
114 * The following method tests are to be completed successfully before :
116 * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number
117 * of recent functions </li>
120 public void _setRecentFunctionIds() {
121 requiredMethod("getMaxRecentFunctions()");
123 boolean bResult
= true;
124 int[] IDs
= new int[0];
125 XNameAccess functionList
= null;
127 log
.println("First, get the set of available functions.");
128 functionList
= (XNameAccess
)tEnv
.getObjRelation("FUNCTIONLIST");
129 if (functionList
== null) throw new StatusException(Status
.failed
130 ("Relation 'FUNCTIONLIST' not found"));
132 log
.println("Now trying to set empty list.");
133 oObj
.setRecentFunctionIds(IDs
);
134 bResult
&= (oObj
.getRecentFunctionIds().length
== 0);
136 log
.println("Now trying to set list of maximum size.");
137 String
[] names
= functionList
.getElementNames();
138 Random rnd
= new Random();
140 IDs
= new int[iMaxNumber
];
141 int startIdx
= rnd
.nextInt(names
.length
- iMaxNumber
- 1) + 1;
144 for (int i
= startIdx
; i
< startIdx
+ iMaxNumber
; i
++) {
145 PropertyValue
[] propVals
= (PropertyValue
[])
146 functionList
.getByName(names
[i
]);
147 for (int j
= 0; j
< propVals
.length
; j
++) {
148 String propName
= (String
)propVals
[j
].Name
;
149 if (propName
.equals("Id")) {
151 ((Integer
)propVals
[j
].Value
).intValue();
156 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
157 e
.printStackTrace(log
);
159 } catch(com
.sun
.star
.container
.NoSuchElementException e
) {
160 e
.printStackTrace(log
);
164 oObj
.setRecentFunctionIds(IDs
);
165 bResult
&= (oObj
.getRecentFunctionIds().length
== iMaxNumber
);
167 tRes
.tested("setRecentFunctionIds()", bResult
);