Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XRecentFunctions.java
blob3ca88e281f68926efefce6e4785c22f368e1c38a
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 if (bResult) {
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);
95 /**
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 :
102 * <ul>
103 * <li> <code> getMaxRecentFunctions() </code> : to have the maximum number
104 * of recent functions </li>
105 * </ul>
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;
130 try {
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")) {
137 IDs[i - startIdx] =
138 ((Integer)propVals[j].Value).intValue();
139 break;
143 } catch(com.sun.star.lang.WrappedTargetException e) {
144 e.printStackTrace(log);
145 bResult = false;
146 } catch(com.sun.star.container.NoSuchElementException e) {
147 e.printStackTrace(log);
148 bResult = false;
151 oObj.setRecentFunctionIds(IDs);
152 bResult &= (oObj.getRecentFunctionIds().length == iMaxNumber);
154 tRes.tested("setRecentFunctionIds()", bResult);