1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDocumentInfo.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.document
.XDocumentInfo
;
36 import com
.sun
.star
.lang
.ArrayIndexOutOfBoundsException
;
39 * Testing <code>com.sun.star.document.XDocumentInfo</code>
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>
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;
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);
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 :
75 * <li> <code> getUserFieldCount() </code> : to obtain number of
79 public void _getUserFieldName() {
80 requiredMethod("getUserFieldCount()");
82 oldNames
= new String
[fieldCount
];
84 for (short i
= 0; i
< fieldCount
; i
++) {
86 oldNames
[i
] = oObj
.getUserFieldName(i
);
87 if (oldNames
[i
] == null) {
88 tRes
.tested("getUserFieldName()", false);
91 } catch (ArrayIndexOutOfBoundsException e
) {
92 log
.println("Couldn't get an user field name at " + i
);
93 tRes
.tested("getUserFieldName()", false);
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 :
107 * <li> <code> getUserFieldName() </code> : to retrieve old names </li>
110 public void _setUserFieldName() {
111 requiredMethod("getUserFieldName()");
113 for (short i
= 0; i
< fieldCount
; i
++) {
114 String newName
= oldNames
[i
] + "_new";
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);
125 if (!newName
.equals(oObj
.getUserFieldName(i
))) {
126 tRes
.tested("setUserFieldName()", false);
129 } catch (ArrayIndexOutOfBoundsException e
) {
130 log
.println("Couldn't set an user field name at " + i
);
131 tRes
.tested("setUserFieldName()", false);
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);
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 :
154 * <li> <code> getUserFieldCount() </code> : to obtain number of
158 public void _getUserFieldValue() {
159 requiredMethod("getUserFieldCount()");
161 oldValues
= new String
[fieldCount
];
163 for (short i
= 0; i
< fieldCount
; i
++) {
165 oldValues
[i
] = oObj
.getUserFieldValue(i
);
166 if (oldValues
[i
] == null) {
167 tRes
.tested("getUserFieldValue()", false);
170 } catch (ArrayIndexOutOfBoundsException e
) {
171 log
.println("Couldn't get an user field value at " + i
);
172 tRes
.tested("getUserFieldValue()", false);
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 :
186 * <li> <code> getUserFieldValue() </code> : to retrieve old values. </li>
189 public void _setUserFieldValue() {
190 requiredMethod("getUserFieldValue()");
192 for (short i
= 0; i
< fieldCount
; i
++) {
193 String newValue
= oldValues
[i
] + "_new";
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);
204 if (!newValue
.equals(oObj
.getUserFieldValue(i
))) {
205 tRes
.tested("setUserFieldValue()", false);
208 } catch (ArrayIndexOutOfBoundsException e
) {
209 log
.println("Couldn't set an user field value at " + i
);
210 tRes
.tested("setUserFieldValue()", false);
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);
223 tRes
.tested("setUserFieldValue()", true);
226 } // finish class _XDocumentInfo