Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XHierarchicalPropertySet.java
blobdd19cf8f52a48cd468b9f9d9e1aa08bda5b0c5ec
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 } else {
38 log.println(
39 "The component doesn't provide HierarchicalPropertySetInfo");
40 tRes.tested("getHierarchicalPropertySetInfo()",
41 Status.skipped(true));
43 return;
46 tRes.tested("getHierarchicalPropertySetInfo()", res);
49 public void _getHierarchicalPropertyValue() {
50 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
51 String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes");
52 boolean res = true;
54 for (int i = 0; i < pNames.length; i++) {
55 try {
56 log.print("Property " + pNames[i]);
58 Object getting = oObj.getHierarchicalPropertyValue(pNames[i]);
59 log.println(" has Value " + getting.toString());
60 res &= checkType(pNames[i], pTypes[i], getting);
61 } catch (com.sun.star.beans.UnknownPropertyException e) {
62 log.println(" is unknown");
63 } catch (com.sun.star.lang.IllegalArgumentException e) {
64 log.println(" is illegal");
65 } catch (com.sun.star.lang.WrappedTargetException e) {
66 log.println(" throws expeption " + e.getMessage());
70 tRes.tested("getHierarchicalPropertyValue()", res);
73 public void _setHierarchicalPropertyValue() {
74 String ro = (String) tEnv.getObjRelation("allReadOnly");
76 if (ro != null) {
77 log.println(ro);
78 tRes.tested("setHierarchicalPropertyValue()", Status.skipped(true));
80 return;
83 boolean res = true;
85 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
87 for (int k = 0; k < pNames.length; k++) {
88 try {
89 Object oldValue = oObj.getHierarchicalPropertyValue(pNames[k]);
90 Object newValue = ValueChanger.changePValue(oldValue);
91 oObj.setHierarchicalPropertyValue(pNames[k], newValue);
93 Object getValue = oObj.getHierarchicalPropertyValue(pNames[k]);
94 boolean localRes = ValueComparer.equalValue(getValue, newValue);
96 if (!localRes) {
97 log.println("Expected " + newValue.toString());
98 log.println("Gained " + getValue.toString());
102 //reset Value
103 oObj.setHierarchicalPropertyValue(pNames[k], oldValue);
105 res &= localRes;
106 } catch (com.sun.star.beans.UnknownPropertyException e) {
107 log.println("Property is unknown");
108 } catch (com.sun.star.lang.IllegalArgumentException e) {
109 log.println("IllegalArgument "+e.getMessage());
110 } catch (com.sun.star.beans.PropertyVetoException e) {
111 log.println("VetoException "+e.getMessage());
112 } catch (com.sun.star.lang.WrappedTargetException e) {
113 log.println("WrappedTarget "+e.getMessage());
118 tRes.tested("setHierarchicalPropertyValue()", res);
121 protected boolean checkType(String name, String type, Object value) {
122 boolean result = true;
124 if (type.equals("Boolean")) {
125 result = (value instanceof Boolean);
127 if (!result) {
128 log.println("Wrong Type for property " + name);
129 log.println("Expected " + type);
130 log.println("getting " + value.getClass());
132 } else if (type.equals("Short")) {
133 result = (value instanceof Short);
135 if (!result) {
136 log.println("Wrong Type for property " + name);
137 log.println("Expected " + type);
138 log.println("getting " + value.getClass());
142 return result;