Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XMultiHierarchicalPropertySet.java
blob10b1c8ce99377bd4f12245d17c6905aa886a3155
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 .
18 package ifc.beans;
20 import lib.MultiMethodTest;
21 import lib.Status;
22 import util.ValueChanger;
23 import util.ValueComparer;
25 import com.sun.star.beans.XHierarchicalPropertySetInfo;
26 import com.sun.star.beans.XMultiHierarchicalPropertySet;
29 public class _XMultiHierarchicalPropertySet extends MultiMethodTest {
30 public XMultiHierarchicalPropertySet oObj;
32 public void _getHierarchicalPropertySetInfo() {
33 XHierarchicalPropertySetInfo hpsi = oObj.getHierarchicalPropertySetInfo();
34 boolean res = true;
36 if (hpsi == null) {
37 log.println(
38 "The component doesn't provide HierarchicalPropertySetInfo");
39 tRes.tested("getHierarchicalPropertySetInfo()",
40 Status.skipped(true));
42 return;
45 tRes.tested("getMultiHierarchicalPropertySetInfo()", res);
48 public void _getHierarchicalPropertyValues() {
49 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
50 String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes");
51 boolean res = true;
53 try {
54 Object[] getting = oObj.getHierarchicalPropertyValues(pNames);
55 res &= checkType(pNames, pTypes, getting);
56 } catch (com.sun.star.lang.IllegalArgumentException e) {
57 log.println("Exception " + e.getMessage());
58 } catch (com.sun.star.lang.WrappedTargetException e) {
59 log.println("Exception " + e.getMessage());
62 tRes.tested("getHierarchicalPropertyValues()", res);
65 public void _setHierarchicalPropertyValues() {
66 String ro = (String) tEnv.getObjRelation("allReadOnly");
68 if (ro != null) {
69 log.println(ro);
70 tRes.tested("setHierarchicalPropertyValues()",
71 Status.skipped(true));
73 return;
76 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
77 boolean res = true;
79 try {
80 Object[] oldValues = oObj.getHierarchicalPropertyValues(pNames);
81 Object[] newValues = new Object[oldValues.length];
83 for (int k = 0; k < oldValues.length; k++) {
84 newValues[k] = ValueChanger.changePValue(oldValues[k]);
87 oObj.setHierarchicalPropertyValues(pNames, newValues);
89 Object[] getValues = oObj.getHierarchicalPropertyValues(pNames);
91 for (int k = 0; k < pNames.length; k++) {
92 boolean localRes = ValueComparer.equalValue(getValues[k],
93 newValues[k]);
95 if (!localRes) {
96 log.println("didn't work for " + pNames[k]);
97 log.println("Expected " + newValues[k].toString());
98 log.println("Getting " + getValues[k].toString());
100 //reset properties
101 oObj.setHierarchicalPropertyValues(pNames, oldValues);
103 } catch (com.sun.star.lang.IllegalArgumentException e) {
104 log.println("IllegalArgument " + e.getMessage());
105 } catch (com.sun.star.beans.PropertyVetoException e) {
106 log.println("VetoException " + e.getMessage());
107 } catch (com.sun.star.lang.WrappedTargetException e) {
108 log.println("WrappedTarget " + e.getMessage());
111 tRes.tested("setHierarchicalPropertyValues()", res);
114 protected boolean checkType(String[] name, String[] type, Object[] value) {
115 boolean result = true;
117 for (int k = 0; k < name.length; k++) {
118 if (type[k].equals("Boolean")) {
119 result &= (value[k] instanceof Boolean);
121 if (!(value[k] instanceof Boolean)) {
122 log.println("Wrong Type for property " + name[k]);
123 log.println("Expected " + type[k]);
124 log.println("getting " + value[k].getClass());
126 } else if (type[k].equals("Short")) {
127 result &= (value[k] instanceof Short);
129 if (!(value[k] instanceof Short)) {
130 log.println("Wrong Type for property " + name[k]);
131 log.println("Expected " + type[k]);
132 log.println("getting " + value[k].getClass());
137 return result;