Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / document / _XDocumentInfo.java
blobc7b7ec582d1c7d83cb7cf9b15c5b9413fe42bc2e
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 ************************************************************************/
28 package ifc.document;
30 import lib.MultiMethodTest;
32 import com.sun.star.document.XDocumentInfo;
33 import com.sun.star.lang.ArrayIndexOutOfBoundsException;
35 /**
36 * Testing <code>com.sun.star.document.XDocumentInfo</code>
37 * interface methods :
38 * <ul>
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>
44 * </ul> <p>
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;
52 short fieldCount;
54 /**
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);
63 String[] oldNames;
64 String[] oldValues;
66 /**
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 :
71 * <ul>
72 * <li> <code> getUserFieldCount() </code> : to obtain number of
73 * fields </li>
74 * </ul>
76 public void _getUserFieldName() {
77 requiredMethod("getUserFieldCount()");
79 oldNames = new String[fieldCount];
81 for (short i = 0; i < fieldCount; i++) {
82 try {
83 oldNames[i] = oObj.getUserFieldName(i);
84 if (oldNames[i] == null) {
85 tRes.tested("getUserFieldName()", false);
86 return;
88 } catch (ArrayIndexOutOfBoundsException e) {
89 log.println("Couldn't get an user field name at " + i);
90 tRes.tested("getUserFieldName()", false);
91 return;
95 tRes.tested("getUserFieldName()", true);
98 /**
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 :
103 * <ul>
104 * <li> <code> getUserFieldName() </code> : to retrieve old names </li>
105 * </ul>
107 public void _setUserFieldName() {
108 requiredMethod("getUserFieldName()");
110 for (short i = 0; i < fieldCount; i++) {
111 String newName = oldNames[i] + "_new";
113 try {
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);
118 return;
121 try {
122 if (!newName.equals(oObj.getUserFieldName(i))) {
123 tRes.tested("setUserFieldName()", false);
124 return;
126 } catch (ArrayIndexOutOfBoundsException e) {
127 log.println("Couldn't set an user field name at " + i);
128 tRes.tested("setUserFieldName()", false);
129 return;
130 } finally {
131 try {
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);
136 return;
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 :
150 * <ul>
151 * <li> <code> getUserFieldCount() </code> : to obtain number of
152 * fields </li>
153 * </ul>
155 public void _getUserFieldValue() {
156 requiredMethod("getUserFieldCount()");
158 oldValues = new String[fieldCount];
160 for (short i = 0; i < fieldCount; i++) {
161 try {
162 oldValues[i] = oObj.getUserFieldValue(i);
163 if (oldValues[i] == null) {
164 tRes.tested("getUserFieldValue()", false);
165 return;
167 } catch (ArrayIndexOutOfBoundsException e) {
168 log.println("Couldn't get an user field value at " + i);
169 tRes.tested("getUserFieldValue()", false);
170 return;
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 :
182 * <ul>
183 * <li> <code> getUserFieldValue() </code> : to retrieve old values. </li>
184 * </ul>
186 public void _setUserFieldValue() {
187 requiredMethod("getUserFieldValue()");
189 for (short i = 0; i < fieldCount; i++) {
190 String newValue = oldValues[i] + "_new";
192 try {
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);
197 return;
200 try {
201 if (!newValue.equals(oObj.getUserFieldValue(i))) {
202 tRes.tested("setUserFieldValue()", false);
203 return;
205 } catch (ArrayIndexOutOfBoundsException e) {
206 log.println("Couldn't set an user field value at " + i);
207 tRes.tested("setUserFieldValue()", false);
208 return;
209 } finally {
210 try {
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);
215 return;
220 tRes.tested("setUserFieldValue()", true);
223 } // finish class _XDocumentInfo