Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / ui / dialogs / _XControlAccess.java
blobe290ab4d91912c22588975798b9a2887c5db7ee2
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;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.ui.dialogs.XControlAccess;
26 import com.sun.star.ui.dialogs.XControlInformation;
27 import com.sun.star.uno.UnoRuntime;
29 /**
30 * Testing <code>com.sun.star.ui.XFilePicker</code>
31 * interface methods :
32 * <ul>
33 * <li><code> setControlProperty()</code></li>
34 * <li><code> getControlProperty()</code></li>
35 * </ul> <p>
37 * For testing this interface the component must implement
38 * <code>com.sun.star.ui.dialogs.XControlInformation</code>
39 * interface. <p>
41 * Test is <b> NOT </b> multithread compliant. <p>
42 * @see com.sun.star.ui.XFolderPicker
44 public class _XControlAccess extends MultiMethodTest {
46 public XControlAccess oObj = null;
47 private String[] supControls = null ;
48 private String[][] supProperties = null ;
50 /**
51 * Tries to query <code>com.sun.star.ui.dialogs.XControlInformation</code>
52 * interface, and obtain properties' names of each available
53 * control. <p>
55 * @throw StatusException if interface is not supported or
56 * properties couldn't be get.
58 @Override
59 protected void before() {
60 XControlInformation xCI = UnoRuntime.queryInterface
61 (XControlInformation.class, oObj);
63 if (xCI == null) throw new StatusException
64 (Status.failed("XControlInformation not supported")) ;
66 supControls = xCI.getSupportedControls();
67 supProperties = new String[supControls.length][];
68 for (int i = 0; i < supControls.length; i++) {
69 try {
70 supProperties[i] =
71 xCI.getSupportedControlProperties(supControls[i]);
72 } catch (com.sun.star.lang.IllegalArgumentException e) {
73 e.printStackTrace(log);
74 throw new StatusException
75 ("Exception while init.", e) ;
80 /**
81 * Tries to change each property of each control.
82 * Has <b>OK</b> status if values are properly changed.
84 public void _setControlProperty() {
85 boolean result = true ;
86 String error = "";
88 for (int i = 0; i < supControls.length; i++) {
89 log.println("Checking properties for control " + supControls[i]);
90 for (int j = 0; j < supProperties[i].length; j++) {
91 log.println("\t" + supProperties[i][j]);
92 try {
93 Object oldVal = oObj.getControlProperty(supControls[i],
94 supProperties[i][j]);
95 Object newVal = util.ValueChanger.changePValue(oldVal);
96 if (supProperties[i][j].startsWith("Help")) {
97 newVal = "HID:133";
99 oObj.setControlProperty
100 (supControls[i], supProperties[i][j], newVal) ;
101 Object resVal = oObj.getControlProperty(supControls[i],
102 supProperties[i][j]);
103 log.println("\t Old:" + oldVal + ",New:" + newVal
104 + ",Result:" + resVal);
105 if (!util.ValueComparer.equalValue(newVal, resVal)) {
106 error += "####Property '"+supProperties[i][j]+
107 " of "+supControls[i]+" didn't work\n\r"+
108 "\t Old:" + oldVal + ",New:" + newVal
109 + ",Result:" + resVal+ "\n\r";
111 result &= util.ValueComparer.equalValue(newVal, resVal);
112 } catch (com.sun.star.lang.IllegalArgumentException e) {
113 log.println("Unexpected exception:" );
114 e.printStackTrace(log);
115 result = false ;
120 log.println(error);
122 tRes.tested("setControlProperty()", result) ;
123 tRes.tested("getControlProperty()", result) ;
127 * Does nothing. Testing performed in <code>setControlProperty</code>
128 * method test.
130 public void _getControlProperty() {}