Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XMultiHierarchicalPropertySet.java
blob9bcc3436e1c1c309e86c386eb5262ef939cec250
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 } else {
38 log.println(
39 "The component doesn't provide HierarchicalPropertySetInfo");
40 tRes.tested("getHierarchicalPropertySetInfo()",
41 Status.skipped(true));
43 return;
46 tRes.tested("getMultiHierarchicalPropertySetInfo()", res);
49 public void _getHierarchicalPropertyValues() {
50 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
51 String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes");
52 boolean res = true;
54 try {
55 Object[] getting = oObj.getHierarchicalPropertyValues(pNames);
56 res &= checkType(pNames, pTypes, getting);
57 } catch (com.sun.star.lang.IllegalArgumentException e) {
58 log.println("Exception " + e.getMessage());
59 } catch (com.sun.star.lang.WrappedTargetException e) {
60 log.println("Exception " + e.getMessage());
63 tRes.tested("getHierarchicalPropertyValues()", res);
66 public void _setHierarchicalPropertyValues() {
67 String ro = (String) tEnv.getObjRelation("allReadOnly");
69 if (ro != null) {
70 log.println(ro);
71 tRes.tested("setHierarchicalPropertyValues()",
72 Status.skipped(true));
74 return;
77 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
78 boolean res = true;
80 try {
81 Object[] oldValues = oObj.getHierarchicalPropertyValues(pNames);
82 Object[] newValues = new Object[oldValues.length];
84 for (int k = 0; k < oldValues.length; k++) {
85 newValues[k] = ValueChanger.changePValue(oldValues[k]);
88 oObj.setHierarchicalPropertyValues(pNames, newValues);
90 Object[] getValues = oObj.getHierarchicalPropertyValues(pNames);
92 for (int k = 0; k < pNames.length; k++) {
93 boolean localRes = ValueComparer.equalValue(getValues[k],
94 newValues[k]);
96 if (!localRes) {
97 log.println("didn't work for " + pNames[k]);
98 log.println("Expected " + newValues[k].toString());
99 log.println("Getting " + getValues[k].toString());
101 //reset properties
102 oObj.setHierarchicalPropertyValues(pNames, oldValues);
104 } catch (com.sun.star.lang.IllegalArgumentException e) {
105 log.println("IllegalArgument " + e.getMessage());
106 } catch (com.sun.star.beans.PropertyVetoException e) {
107 log.println("VetoException " + e.getMessage());
108 } catch (com.sun.star.lang.WrappedTargetException e) {
109 log.println("WrappedTarget " + e.getMessage());
112 tRes.tested("setHierarchicalPropertyValues()", res);
115 protected boolean checkType(String[] name, String[] type, Object[] value) {
116 boolean result = true;
118 for (int k = 0; k < name.length; k++) {
119 if (type[k].equals("Boolean")) {
120 result &= (value[k] instanceof Boolean);
122 if (!(value[k] instanceof Boolean)) {
123 log.println("Wrong Type for property " + name[k]);
124 log.println("Expected " + type[k]);
125 log.println("getting " + value[k].getClass());
127 } else if (type[k].equals("Short")) {
128 result &= (value[k] instanceof Short);
130 if (!(value[k] instanceof Short)) {
131 log.println("Wrong Type for property " + name[k]);
132 log.println("Expected " + type[k]);
133 log.println("getting " + value[k].getClass());
138 return result;