Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XHierarchicalPropertySet.java
blobc7cc8faf71ebc1f00982226040e5e048b5665155
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.XHierarchicalPropertySet;
26 import com.sun.star.beans.XHierarchicalPropertySetInfo;
29 public class _XHierarchicalPropertySet extends MultiMethodTest {
30 public XHierarchicalPropertySet 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("getHierarchicalPropertySetInfo()", res);
48 public void _getHierarchicalPropertyValue() {
49 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
50 String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes");
51 boolean res = true;
53 for (int i = 0; i < pNames.length; i++) {
54 try {
55 log.print("Property " + pNames[i]);
57 Object getting = oObj.getHierarchicalPropertyValue(pNames[i]);
58 log.println(" has Value " + getting.toString());
59 res &= checkType(pNames[i], pTypes[i], getting);
60 } catch (com.sun.star.beans.UnknownPropertyException e) {
61 log.println(" is unknown");
62 } catch (com.sun.star.lang.IllegalArgumentException e) {
63 log.println(" is illegal");
64 } catch (com.sun.star.lang.WrappedTargetException e) {
65 log.println(" throws exception " + e.getMessage());
69 tRes.tested("getHierarchicalPropertyValue()", res);
72 public void _setHierarchicalPropertyValue() {
73 String ro = (String) tEnv.getObjRelation("allReadOnly");
75 if (ro != null) {
76 log.println(ro);
77 tRes.tested("setHierarchicalPropertyValue()", Status.skipped(true));
79 return;
82 boolean res = true;
84 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
86 for (int k = 0; k < pNames.length; k++) {
87 try {
88 Object oldValue = oObj.getHierarchicalPropertyValue(pNames[k]);
89 Object newValue = ValueChanger.changePValue(oldValue);
90 oObj.setHierarchicalPropertyValue(pNames[k], newValue);
92 Object getValue = oObj.getHierarchicalPropertyValue(pNames[k]);
93 boolean localRes = ValueComparer.equalValue(getValue, newValue);
95 if (!localRes) {
96 log.println("Expected " + newValue.toString());
97 log.println("Gained " + getValue.toString());
101 //reset Value
102 oObj.setHierarchicalPropertyValue(pNames[k], oldValue);
104 res &= localRes;
105 } catch (com.sun.star.beans.UnknownPropertyException e) {
106 log.println("Property is unknown");
107 } catch (com.sun.star.lang.IllegalArgumentException e) {
108 log.println("IllegalArgument "+e.getMessage());
109 } catch (com.sun.star.beans.PropertyVetoException e) {
110 log.println("VetoException "+e.getMessage());
111 } catch (com.sun.star.lang.WrappedTargetException e) {
112 log.println("WrappedTarget "+e.getMessage());
117 tRes.tested("setHierarchicalPropertyValue()", res);
120 protected boolean checkType(String name, String type, Object value) {
121 boolean result = true;
123 if (type.equals("Boolean")) {
124 result = (value instanceof Boolean);
126 if (!result) {
127 log.println("Wrong Type for property " + name);
128 log.println("Expected " + type);
129 log.println("getting " + value.getClass());
131 } else if (type.equals("Short")) {
132 result = (value instanceof Short);
134 if (!result) {
135 log.println("Wrong Type for property " + name);
136 log.println("Expected " + type);
137 log.println("getting " + value.getClass());
141 return result;