2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.util
.Random
;
23 import lib
.MultiMethodTest
;
25 import lib
.StatusException
;
27 import com
.sun
.star
.beans
.PropertyValue
;
28 import com
.sun
.star
.container
.XNameAccess
;
29 import com
.sun
.star
.sheet
.XRecentFunctions
;
32 * Testing <code>com.sun.star.sheet.XRecentFunctions</code>
35 * <li><code> getRecentFunctionIds()</code></li>
36 * <li><code> setRecentFunctionIds()</code></li>
37 * <li><code> getMaxRecentFunctions()</code></li>
39 * This test needs the following object relations :
41 * <li> <code>'FUNCTIONLIST'</code> (of type <code>XNameAccess</code>):
42 * to have the set of available functions </li>
44 * @see com.sun.star.sheet.XRecentFunctions
46 public class _XRecentFunctions
extends MultiMethodTest
{
48 public XRecentFunctions oObj
= null;
52 * Test calls the method, checks returned value and stores it. <p>
53 * Has <b> OK </b> status if returned value isn't equal to zero. <p>
55 public void _getMaxRecentFunctions() {
57 iMaxNumber
= oObj
.getMaxRecentFunctions();
58 log
.println("Maximum recent functions : " + iMaxNumber
);
60 tRes
.tested("getMaxRecentFunctions()", iMaxNumber
!= 0);
64 * Test calls the method and checks returned value. <p>
65 * Has <b> OK </b> status if returned value isn't null, if length of returned
66 * array is equal or less to the maximum number of functions and obtained
67 * array doesn't contain equal functions. <p>
68 * The following method tests are to be completed successfully before :
70 * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number
71 * of recent functions </li>
74 public void _getRecentFunctionIds() {
75 requiredMethod("getMaxRecentFunctions()");
77 boolean bResult
= true;
81 IDs
= oObj
.getRecentFunctionIds();
83 bResult
&= (iNumber
<= iMaxNumber
);
84 log
.println("Now there are " + iNumber
+ " recent functions");
85 bResult
&= (IDs
!= null);
87 for (int i
= 0; i
< iNumber
- 1; i
++)
88 for (int j
= i
+ 1; j
< iNumber
; j
++) {
89 bResult
&= (IDs
[i
] != IDs
[j
]);
93 tRes
.tested("getRecentFunctionIds()", bResult
);
97 * Test gets the set of available functions, sets empty list of recent
98 * functions, sets list of maximum size. <p>
99 * Has <b> OK </b> status if length of recent function list is equal to zero
100 * after list was set to empty, if length of list is equal to maximum size
101 * after list was set to it's maximum size and no exception were thrown. <p>
102 * The following method tests are to be completed successfully before :
104 * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number
105 * of recent functions </li>
108 public void _setRecentFunctionIds() {
109 requiredMethod("getMaxRecentFunctions()");
111 boolean bResult
= true;
112 int[] IDs
= new int[0];
113 XNameAccess functionList
= null;
115 log
.println("First, get the set of available functions.");
116 functionList
= (XNameAccess
)tEnv
.getObjRelation("FUNCTIONLIST");
117 if (functionList
== null) throw new StatusException(Status
.failed
118 ("Relation 'FUNCTIONLIST' not found"));
120 log
.println("Now trying to set empty list.");
121 oObj
.setRecentFunctionIds(IDs
);
122 bResult
&= (oObj
.getRecentFunctionIds().length
== 0);
124 log
.println("Now trying to set list of maximum size.");
125 String
[] names
= functionList
.getElementNames();
126 Random rnd
= new Random();
128 IDs
= new int[iMaxNumber
];
129 int startIdx
= rnd
.nextInt(names
.length
- iMaxNumber
- 1) + 1;
132 for (int i
= startIdx
; i
< startIdx
+ iMaxNumber
; i
++) {
133 PropertyValue
[] propVals
= (PropertyValue
[])
134 functionList
.getByName(names
[i
]);
135 for (int j
= 0; j
< propVals
.length
; j
++) {
136 String propName
= propVals
[j
].Name
;
137 if (propName
.equals("Id")) {
139 ((Integer
)propVals
[j
].Value
).intValue();
144 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
145 e
.printStackTrace(log
);
147 } catch(com
.sun
.star
.container
.NoSuchElementException e
) {
148 e
.printStackTrace(log
);
152 oObj
.setRecentFunctionIds(IDs
);
153 bResult
&= (oObj
.getRecentFunctionIds().length
== iMaxNumber
);
155 tRes
.tested("setRecentFunctionIds()", bResult
);