merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / document / _XDocumentInfo.java
blob4638ebd29dbfffcc253ebacd6cace3e390d9b74b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDocumentInfo.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.document;
33 import lib.MultiMethodTest;
35 import com.sun.star.document.XDocumentInfo;
36 import com.sun.star.lang.ArrayIndexOutOfBoundsException;
38 /**
39 * Testing <code>com.sun.star.document.XDocumentInfo</code>
40 * interface methods :
41 * <ul>
42 * <li><code> getUserFieldCount()</code></li>
43 * <li><code> getUserFieldName()</code></li>
44 * <li><code> setUserFieldName()</code></li>
45 * <li><code> getUserFieldValue()</code></li>
46 * <li><code> setUserFieldValue()</code></li>
47 * </ul> <p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.document.XDocumentInfo
51 public class _XDocumentInfo extends MultiMethodTest {
53 public XDocumentInfo oObj = null;
55 short fieldCount;
57 /**
58 * Gets user field count. <p>
59 * Has <b> OK </b> status if count is positive.
61 public void _getUserFieldCount() {
62 fieldCount = oObj.getUserFieldCount();
63 tRes.tested("getUserFieldCount()", fieldCount >= 0);
66 String[] oldNames;
67 String[] oldValues;
69 /**
70 * Retrieves all user field names and stores them. <p>
71 * Has <b> OK </b> status if no exceptions were thrown and
72 * names returned are not <code>null</code> values. <p>
73 * The following method tests are to be completed successfully before :
74 * <ul>
75 * <li> <code> getUserFieldCount() </code> : to obtain number of
76 * fields </li>
77 * </ul>
79 public void _getUserFieldName() {
80 requiredMethod("getUserFieldCount()");
82 oldNames = new String[fieldCount];
84 for (short i = 0; i < fieldCount; i++) {
85 try {
86 oldNames[i] = oObj.getUserFieldName(i);
87 if (oldNames[i] == null) {
88 tRes.tested("getUserFieldName()", false);
89 return;
91 } catch (ArrayIndexOutOfBoundsException e) {
92 log.println("Couldn't get an user field name at " + i);
93 tRes.tested("getUserFieldName()", false);
94 return;
98 tRes.tested("getUserFieldName()", true);
102 * For each field its name changed and the checked if it's properly
103 * changed. Finally old names are restored.<p>
104 * Has <b> OK </b> status if names were properly changed. <p>
105 * The following method tests are to be completed successfully before :
106 * <ul>
107 * <li> <code> getUserFieldName() </code> : to retrieve old names </li>
108 * </ul>
110 public void _setUserFieldName() {
111 requiredMethod("getUserFieldName()");
113 for (short i = 0; i < fieldCount; i++) {
114 String newName = oldNames[i] + "_new";
116 try {
117 oObj.setUserFieldName(i, newName);
118 } catch (ArrayIndexOutOfBoundsException e) {
119 log.println("Couldn't set an user field name at " + i);
120 tRes.tested("setUserFieldName()", false);
121 return;
124 try {
125 if (!newName.equals(oObj.getUserFieldName(i))) {
126 tRes.tested("setUserFieldName()", false);
127 return;
129 } catch (ArrayIndexOutOfBoundsException e) {
130 log.println("Couldn't set an user field name at " + i);
131 tRes.tested("setUserFieldName()", false);
132 return;
133 } finally {
134 try {
135 oObj.setUserFieldName(i, oldNames[i]);
136 } catch (ArrayIndexOutOfBoundsException e) {
137 log.println("Couldn't restore an user field name at " + i);
138 tRes.tested("setUserFieldName()", false);
139 return;
144 tRes.tested("setUserFieldName()", true);
149 * Retrieves all user field values and stores them. <p>
150 * Has <b> OK </b> status if no exceptions were thrown and
151 * values returned are not <code>null</code> values. <p>
152 * The following method tests are to be completed successfully before :
153 * <ul>
154 * <li> <code> getUserFieldCount() </code> : to obtain number of
155 * fields </li>
156 * </ul>
158 public void _getUserFieldValue() {
159 requiredMethod("getUserFieldCount()");
161 oldValues = new String[fieldCount];
163 for (short i = 0; i < fieldCount; i++) {
164 try {
165 oldValues[i] = oObj.getUserFieldValue(i);
166 if (oldValues[i] == null) {
167 tRes.tested("getUserFieldValue()", false);
168 return;
170 } catch (ArrayIndexOutOfBoundsException e) {
171 log.println("Couldn't get an user field value at " + i);
172 tRes.tested("getUserFieldValue()", false);
173 return;
177 tRes.tested("getUserFieldValue()", true);
181 * For each field its value changed and the checked if it's properly
182 * changed. Finally old values are restored.<p>
183 * Has <b> OK </b> status if values were properly changed. <p>
184 * The following method tests are to be completed successfully before :
185 * <ul>
186 * <li> <code> getUserFieldValue() </code> : to retrieve old values. </li>
187 * </ul>
189 public void _setUserFieldValue() {
190 requiredMethod("getUserFieldValue()");
192 for (short i = 0; i < fieldCount; i++) {
193 String newValue = oldValues[i] + "_new";
195 try {
196 oObj.setUserFieldValue(i, newValue);
197 } catch (ArrayIndexOutOfBoundsException e) {
198 log.println("Couldn't set an user field value at " + i);
199 tRes.tested("setUserFieldValue()", false);
200 return;
203 try {
204 if (!newValue.equals(oObj.getUserFieldValue(i))) {
205 tRes.tested("setUserFieldValue()", false);
206 return;
208 } catch (ArrayIndexOutOfBoundsException e) {
209 log.println("Couldn't set an user field value at " + i);
210 tRes.tested("setUserFieldValue()", false);
211 return;
212 } finally {
213 try {
214 oObj.setUserFieldValue(i, oldNames[i]);
215 } catch (ArrayIndexOutOfBoundsException e) {
216 log.println("Couldn't restore an user field value at " + i);
217 tRes.tested("setUserFieldValue()", false);
218 return;
223 tRes.tested("setUserFieldValue()", true);
226 } // finish class _XDocumentInfo