Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / ui / dialogs / _XControlInformation.java
blob1da743110aca6cd5f37b45dc94d6f4e55113f064
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.ui.dialogs;
21 import lib.MultiMethodTest;
23 import com.sun.star.ui.dialogs.XControlInformation;
25 /**
26 * Testing <code>com.sun.star.ui.XControlInformation</code>
27 * interface methods :
28 * <ul>
29 * <li><code> getSupportedControls()</code></li>
30 * <li><code> isControlSupported()</code></li>
31 * <li><code> getSupportedControlProperties()</code></li>
32 * <li><code> isControlPropertySupported()</code></li>
33 * </ul> <p>
35 * @see com.sun.star.ui.XFolderPicker
37 public class _XControlInformation extends MultiMethodTest {
39 public XControlInformation oObj = null;
40 private String[] supControls = null ;
41 private String[][] supProperties = null ;
43 /**
44 * Gets supported controls and stores them. <p>
45 * Has <b>OK</b> status if not <code>null</code> returned.
47 public void _getSupportedControls() {
48 supControls = oObj.getSupportedControls();
50 tRes.tested("getSupportedControls()", supControls != null) ;
53 /**
54 * For every available control check if it is supported.
55 * Also wrong control name (non-existent and empty) are checked.<p>
57 * Has <b>OK</b> status if <code>true</code> returned for valid
58 * control names and <code>false</code> for invalid.<p>
60 * The following method tests are to be completed successfully before :
61 * <ul>
62 * <li> <code> getSupportedControls </code> to have
63 * valid control names</li>
64 * </ul>
66 public void _isControlSupported() {
67 requiredMethod("getSupportedControls()") ;
69 boolean result = true ;
71 log.println("Supported controls :");
72 for (int i = 0; i < supControls.length; i++) {
73 log.println(" " + supControls[i]);
74 result &= oObj.isControlSupported(supControls[i]) ;
77 result &= !oObj.isControlSupported("SuchNameMustNotExist");
78 result &= !oObj.isControlSupported("");
80 tRes.tested("isControlSupported()", result) ;
83 /**
84 * For each control obtains its properties and stores them. Then tries to
85 * obtain properties for control with invalid name. <p>
87 * Has <b>OK</b> status if properties arrays are not null and exception
88 * thrown or null returned for control with invalid name <p>
90 * The following method tests are to be completed successfully before :
91 * <ul>
92 * <li> <code> getSupportedControls </code> to have
93 * valid control names</li>
94 * </ul>
96 public void _getSupportedControlProperties() {
97 requiredMethod("getSupportedControls()") ;
99 supProperties = new String[supControls.length][];
100 for (int i = 0; i < supControls.length; i++) {
101 log.println("Getting properties for control: " + supControls[i]);
102 try {
103 supProperties[i] =
104 oObj.getSupportedControlProperties(supControls[i]);
105 } catch (com.sun.star.lang.IllegalArgumentException e) {
106 log.println("Unexpected exception:" + e);
110 try {
111 oObj.getSupportedControlProperties("NoSuchControl");
112 } catch (com.sun.star.lang.IllegalArgumentException e) {
113 log.println("Expected exception getting properties " +
114 "for wrong control:" + e);
117 tRes.tested("getSupportedControlProperties()", true) ;
121 * <ul>
122 * <li>For each property of each control checks if it is supported.</li>
123 * <li>For each control checks if non-existent property
124 * (with wrong name and with empty name) supported.</li>
125 * <li>Tries to check the property of non-existent control </li>
126 * </ul>
127 * <p>
128 * Has <b>OK</b> status if <code>true</code> returned for the first case,
129 * <code>false</code> for the second, and <code>false</code> or exception
130 * for the third.<p>
132 * The following method tests are to be completed successfully before :
133 * <ul>
134 * <li> <code> getSupportedControlProperties </code> to have a set of
135 * valid properties </li>
136 * </ul>
138 public void _isControlPropertySupported() {
139 requiredMethod("getSupportedControlProperties()") ;
141 boolean result = true;
143 for (int i = 0; i < supControls.length; i++) {
144 log.println("Checking properties for control " + supControls[i]);
145 for (int j = 0; j < supProperties[i].length; j++) {
146 log.println(" " + supProperties[i][j]);
147 try {
148 result &= oObj.isControlPropertySupported
149 (supControls[i], supProperties[i][j]) ;
150 } catch (com.sun.star.lang.IllegalArgumentException e) {
151 log.println("Unexpected exception:" + e);
152 result = false ;
156 try {
157 result &= !oObj.isControlPropertySupported
158 (supControls[i], "NoSuchPropertyForThisControl") ;
159 result &= !oObj.isControlPropertySupported
160 (supControls[i], "") ;
161 } catch (com.sun.star.lang.IllegalArgumentException e) {
162 log.println
163 ("Unexpected exception (just false must be returned):" + e);
164 result = false ;
168 try {
169 result &= !oObj.isControlPropertySupported("NoSuchControl", "") ;
170 } catch (com.sun.star.lang.IllegalArgumentException e) {
171 log.println("Expected exception: " + e);
174 tRes.tested("isControlPropertySupported()", result) ;