1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import com
.sun
.star
.document
.XDocumentInfo
;
33 import com
.sun
.star
.lang
.ArrayIndexOutOfBoundsException
;
36 * Testing <code>com.sun.star.document.XDocumentInfo</code>
39 * <li><code> getUserFieldCount()</code></li>
40 * <li><code> getUserFieldName()</code></li>
41 * <li><code> setUserFieldName()</code></li>
42 * <li><code> getUserFieldValue()</code></li>
43 * <li><code> setUserFieldValue()</code></li>
45 * Test is <b> NOT </b> multithread compilant. <p>
46 * @see com.sun.star.document.XDocumentInfo
48 public class _XDocumentInfo
extends MultiMethodTest
{
50 public XDocumentInfo oObj
= null;
55 * Gets user field count. <p>
56 * Has <b> OK </b> status if count is positive.
58 public void _getUserFieldCount() {
59 fieldCount
= oObj
.getUserFieldCount();
60 tRes
.tested("getUserFieldCount()", fieldCount
>= 0);
67 * Retrieves all user field names and stores them. <p>
68 * Has <b> OK </b> status if no exceptions were thrown and
69 * names returned are not <code>null</code> values. <p>
70 * The following method tests are to be completed successfully before :
72 * <li> <code> getUserFieldCount() </code> : to obtain number of
76 public void _getUserFieldName() {
77 requiredMethod("getUserFieldCount()");
79 oldNames
= new String
[fieldCount
];
81 for (short i
= 0; i
< fieldCount
; i
++) {
83 oldNames
[i
] = oObj
.getUserFieldName(i
);
84 if (oldNames
[i
] == null) {
85 tRes
.tested("getUserFieldName()", false);
88 } catch (ArrayIndexOutOfBoundsException e
) {
89 log
.println("Couldn't get an user field name at " + i
);
90 tRes
.tested("getUserFieldName()", false);
95 tRes
.tested("getUserFieldName()", true);
99 * For each field its name changed and the checked if it's properly
100 * changed. Finally old names are restored.<p>
101 * Has <b> OK </b> status if names were properly changed. <p>
102 * The following method tests are to be completed successfully before :
104 * <li> <code> getUserFieldName() </code> : to retrieve old names </li>
107 public void _setUserFieldName() {
108 requiredMethod("getUserFieldName()");
110 for (short i
= 0; i
< fieldCount
; i
++) {
111 String newName
= oldNames
[i
] + "_new";
114 oObj
.setUserFieldName(i
, newName
);
115 } catch (ArrayIndexOutOfBoundsException e
) {
116 log
.println("Couldn't set an user field name at " + i
);
117 tRes
.tested("setUserFieldName()", false);
122 if (!newName
.equals(oObj
.getUserFieldName(i
))) {
123 tRes
.tested("setUserFieldName()", false);
126 } catch (ArrayIndexOutOfBoundsException e
) {
127 log
.println("Couldn't set an user field name at " + i
);
128 tRes
.tested("setUserFieldName()", false);
132 oObj
.setUserFieldName(i
, oldNames
[i
]);
133 } catch (ArrayIndexOutOfBoundsException e
) {
134 log
.println("Couldn't restore an user field name at " + i
);
135 tRes
.tested("setUserFieldName()", false);
141 tRes
.tested("setUserFieldName()", true);
146 * Retrieves all user field values and stores them. <p>
147 * Has <b> OK </b> status if no exceptions were thrown and
148 * values returned are not <code>null</code> values. <p>
149 * The following method tests are to be completed successfully before :
151 * <li> <code> getUserFieldCount() </code> : to obtain number of
155 public void _getUserFieldValue() {
156 requiredMethod("getUserFieldCount()");
158 oldValues
= new String
[fieldCount
];
160 for (short i
= 0; i
< fieldCount
; i
++) {
162 oldValues
[i
] = oObj
.getUserFieldValue(i
);
163 if (oldValues
[i
] == null) {
164 tRes
.tested("getUserFieldValue()", false);
167 } catch (ArrayIndexOutOfBoundsException e
) {
168 log
.println("Couldn't get an user field value at " + i
);
169 tRes
.tested("getUserFieldValue()", false);
174 tRes
.tested("getUserFieldValue()", true);
178 * For each field its value changed and the checked if it's properly
179 * changed. Finally old values are restored.<p>
180 * Has <b> OK </b> status if values were properly changed. <p>
181 * The following method tests are to be completed successfully before :
183 * <li> <code> getUserFieldValue() </code> : to retrieve old values. </li>
186 public void _setUserFieldValue() {
187 requiredMethod("getUserFieldValue()");
189 for (short i
= 0; i
< fieldCount
; i
++) {
190 String newValue
= oldValues
[i
] + "_new";
193 oObj
.setUserFieldValue(i
, newValue
);
194 } catch (ArrayIndexOutOfBoundsException e
) {
195 log
.println("Couldn't set an user field value at " + i
);
196 tRes
.tested("setUserFieldValue()", false);
201 if (!newValue
.equals(oObj
.getUserFieldValue(i
))) {
202 tRes
.tested("setUserFieldValue()", false);
205 } catch (ArrayIndexOutOfBoundsException e
) {
206 log
.println("Couldn't set an user field value at " + i
);
207 tRes
.tested("setUserFieldValue()", false);
211 oObj
.setUserFieldValue(i
, oldNames
[i
]);
212 } catch (ArrayIndexOutOfBoundsException e
) {
213 log
.println("Couldn't restore an user field value at " + i
);
214 tRes
.tested("setUserFieldValue()", false);
220 tRes
.tested("setUserFieldValue()", true);
223 } // finish class _XDocumentInfo