Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XFunctionDescriptions.java
blob27c320c46e3766a6b75197f79ff647a87321d431
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;
25 import com.sun.star.beans.PropertyValue;
26 import com.sun.star.sheet.XFunctionDescriptions;
28 /**
29 * Testing <code>com.sun.star.sheet.XFunctionDescriptions</code>
30 * interface methods :
31 * <ul>
32 * <li><code> getById()</code></li>
33 * </ul> <p>
34 * @see com.sun.star.sheet.XFunctionDescriptions
36 public class _XFunctionDescriptions extends MultiMethodTest {
38 public XFunctionDescriptions oObj = null;
40 /**
41 * Test finds available id, calls method using this id, checks returned
42 * value and then tries to get description with wrong id. <p>
43 * Has <b>OK</b> status if returned value is equal to value obtained by the
44 * method <code>getByIndex()</code> in first call and exception
45 * <code>IllegalArgumentException</code> was thrown in second call.<p>
46 * @see com.sun.star.lang.IllegalArgumentException
48 public void _getById() {
49 boolean bResult = true;
50 // Finding available id...
52 int count = oObj.getCount();
53 if (count > 0) {
54 Random rnd = new Random();
55 int nr = rnd.nextInt(count);
57 PropertyValue[] PVals = null;
58 try {
59 PVals = (PropertyValue[])oObj.getByIndex(nr);
60 } catch(com.sun.star.lang.WrappedTargetException e) {
61 e.printStackTrace(log);
62 tRes.tested("getById()", false);
63 return;
64 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
65 e.printStackTrace(log);
66 tRes.tested("getById()", false);
67 return;
70 String FName = null;
71 Integer FId = null;
73 for (int i = 0; i < PVals.length; i++) {
74 if (PVals[i].Name.equals("Name"))
75 FName = (String)PVals[i].Value;
76 if (PVals[i].Name.equals("Id"))
77 FId = (Integer)PVals[i].Value;
80 log.println("The id of function '" + FName + "' is " + FId);
82 PropertyValue[] PVals2 = null;
83 try {
84 PVals2 = oObj.getById(FId.intValue());
85 } catch(com.sun.star.lang.IllegalArgumentException e) {
86 e.printStackTrace(log);
87 tRes.tested("getById()", false);
88 return;
91 String objFName = null;
92 Integer objFId = null;
93 for (int i = 0; i < PVals2.length; i++) {
94 if (PVals2[i].Name.equals("Name"))
95 objFName = (String)PVals[i].Value;
96 if (PVals2[i].Name.equals("Id"))
97 objFId = (Integer)PVals[i].Value;
100 log.println("The id of returned function '" +
101 objFName + "' is " + objFId);
103 bResult &= FName.equals(objFName);
104 bResult &= FId.equals(objFId);
107 log.println("OK.");
109 try {
110 log.println("Now trying to get description with wrong id ... ");
111 oObj.getById(-1);
112 bResult = false;
113 log.println("Exception expected! - FAILED");
114 } catch (com.sun.star.lang.IllegalArgumentException e) {
115 log.println("Expected exception " + e + " - OK!");
118 tRes.tested("getById()", bResult);
120 } // finish class _XFunctionDescriptions