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");
86 for (int i
= 0; i
< iNumber
- 1; i
++)
87 for (int j
= i
+ 1; j
< iNumber
; j
++) {
88 bResult
&= (IDs
[i
] != IDs
[j
]);
92 tRes
.tested("getRecentFunctionIds()", bResult
);
96 * Test gets the set of available functions, sets empty list of recent
97 * functions, sets list of maximum size. <p>
98 * Has <b> OK </b> status if length of recent function list is equal to zero
99 * after list was set to empty, if length of list is equal to maximum size
100 * after list was set to its maximum size and no exception were thrown. <p>
101 * The following method tests are to be completed successfully before :
103 * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number
104 * of recent functions </li>
107 public void _setRecentFunctionIds() {
108 requiredMethod("getMaxRecentFunctions()");
110 boolean bResult
= true;
111 int[] IDs
= new int[0];
112 XNameAccess functionList
= null;
114 log
.println("First, get the set of available functions.");
115 functionList
= (XNameAccess
)tEnv
.getObjRelation("FUNCTIONLIST");
116 if (functionList
== null) throw new StatusException(Status
.failed
117 ("Relation 'FUNCTIONLIST' not found"));
119 log
.println("Now trying to set empty list.");
120 oObj
.setRecentFunctionIds(IDs
);
121 bResult
&= (oObj
.getRecentFunctionIds().length
== 0);
123 log
.println("Now trying to set list of maximum size.");
124 String
[] names
= functionList
.getElementNames();
125 Random rnd
= new Random();
127 IDs
= new int[iMaxNumber
];
128 int startIdx
= rnd
.nextInt(names
.length
- iMaxNumber
- 1) + 1;
131 for (int i
= startIdx
; i
< startIdx
+ iMaxNumber
; i
++) {
132 PropertyValue
[] propVals
= (PropertyValue
[])
133 functionList
.getByName(names
[i
]);
134 for (int j
= 0; j
< propVals
.length
; j
++) {
135 String propName
= propVals
[j
].Name
;
136 if (propName
.equals("Id")) {
138 ((Integer
)propVals
[j
].Value
).intValue();
143 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
144 e
.printStackTrace(log
);
146 } catch(com
.sun
.star
.container
.NoSuchElementException e
) {
147 e
.printStackTrace(log
);
151 oObj
.setRecentFunctionIds(IDs
);
152 bResult
&= (oObj
.getRecentFunctionIds().length
== iMaxNumber
);
154 tRes
.tested("setRecentFunctionIds()", bResult
);