Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XFunctionDescriptions.java
blob5f16c7640fec383536078c4a8ba63e14bcc5994b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.sheet;
30 import java.util.Random;
32 import lib.MultiMethodTest;
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.sheet.XFunctionDescriptions;
37 /**
38 * Testing <code>com.sun.star.sheet.XFunctionDescriptions</code>
39 * interface methods :
40 * <ul>
41 * <li><code> getById()</code></li>
42 * </ul> <p>
43 * @see com.sun.star.sheet.XFunctionDescriptions
45 public class _XFunctionDescriptions extends MultiMethodTest {
47 public XFunctionDescriptions oObj = null;
49 /**
50 * Test finds available id, calls method using this id, checks returned
51 * value and then tries to get description with wrong id. <p>
52 * Has <b>OK</b> status if returned value is equal to value obtained by the
53 * method <code>getByIndex()</code> in first call and exception
54 * <code>IllegalArgumentException</code> was thrown in second call.<p>
55 * @see com.sun.star.lang.IllegalArgumentException
57 public void _getById() {
58 boolean bResult = true;
59 // Finding available id...
61 int count = oObj.getCount();
62 if (count > 0) {
63 Random rnd = new Random();
64 int nr = rnd.nextInt(count);
66 PropertyValue[] PVals = null;
67 try {
68 PVals = (PropertyValue[])oObj.getByIndex(nr);
69 } catch(com.sun.star.lang.WrappedTargetException e) {
70 e.printStackTrace(log);
71 tRes.tested("getById()", false);
72 return;
73 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
74 e.printStackTrace(log);
75 tRes.tested("getById()", false);
76 return;
79 String FName = null;
80 Integer FId = null;
82 for (int i = 0; i < PVals.length; i++) {
83 if (PVals[i].Name.equals("Name"))
84 FName = (String)PVals[i].Value;
85 if (PVals[i].Name.equals("Id"))
86 FId = (Integer)PVals[i].Value;
89 log.println("The id of function '" + FName + "' is " + FId);
91 PropertyValue[] PVals2 = null;
92 try {
93 PVals2 = oObj.getById(FId.intValue());
94 } catch(com.sun.star.lang.IllegalArgumentException e) {
95 e.printStackTrace(log);
96 tRes.tested("getById()", false);
97 return;
100 String objFName = null;
101 Integer objFId = null;
102 for (int i = 0; i < PVals2.length; i++) {
103 if (PVals2[i].Name.equals("Name"))
104 objFName = (String)PVals[i].Value;
105 if (PVals2[i].Name.equals("Id"))
106 objFId = (Integer)PVals[i].Value;
109 log.println("The id of returned function '" +
110 objFName + "' is " + objFId);
112 bResult &= FName.equals(objFName);
113 bResult &= FId.equals(objFId);
116 log.println("OK.");
118 try {
119 log.println("Now trying to get description with wrong id ... ");
120 oObj.getById(-1);
121 bResult = false;
122 log.println("Exception expected! - FAILED");
123 } catch (com.sun.star.lang.IllegalArgumentException e) {
124 log.println("Expected exception " + e + " - OK!");
127 tRes.tested("getById()", bResult);
129 } // finish class _XFunctionDescriptions