bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XRecentFunctions.java
blob856cb61d8668ef97400749e386d6d9c16e21d88d
1 /*
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 .
19 package ifc.sheet;
21 import java.util.Random;
23 import lib.MultiMethodTest;
24 import lib.Status;
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;
31 /**
32 * Testing <code>com.sun.star.sheet.XRecentFunctions</code>
33 * interface methods :
34 * <ul>
35 * <li><code> getRecentFunctionIds()</code></li>
36 * <li><code> setRecentFunctionIds()</code></li>
37 * <li><code> getMaxRecentFunctions()</code></li>
38 * </ul> <p>
39 * This test needs the following object relations :
40 * <ul>
41 * <li> <code>'FUNCTIONLIST'</code> (of type <code>XNameAccess</code>):
42 * to have the set of available functions </li>
43 * <ul> <p>
44 * @see com.sun.star.sheet.XRecentFunctions
46 public class _XRecentFunctions extends MultiMethodTest {
48 public XRecentFunctions oObj = null;
49 int iMaxNumber = 0;
51 /**
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);
63 /**
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 :
69 * <ul>
70 * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number
71 * of recent functions </li>
72 * </ul>
74 public void _getRecentFunctionIds() {
75 requiredMethod("getMaxRecentFunctions()");
77 boolean bResult = true;
78 int[] IDs = null;
79 int iNumber = 0;
81 IDs = oObj.getRecentFunctionIds();
82 iNumber = IDs.length;
83 bResult &= (iNumber <= iMaxNumber);
84 log.println("Now there are " + iNumber + " recent functions");
85 bResult &= (IDs != null);
86 if (bResult) {
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);
96 /**
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 :
103 * <ul>
104 * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number
105 * of recent functions </li>
106 * </ul>
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;
131 try {
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")) {
138 IDs[i - startIdx] =
139 ((Integer)propVals[j].Value).intValue();
140 break;
144 } catch(com.sun.star.lang.WrappedTargetException e) {
145 e.printStackTrace(log);
146 bResult = false;
147 } catch(com.sun.star.container.NoSuchElementException e) {
148 e.printStackTrace(log);
149 bResult = false;
152 oObj.setRecentFunctionIds(IDs);
153 bResult &= (oObj.getRecentFunctionIds().length == iMaxNumber);
155 tRes.tested("setRecentFunctionIds()", bResult);