1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.document;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.document.XDocumentInfo;
29 import com.sun.star.lang.ArrayIndexOutOfBoundsException;
30 
31 /**
32 * Testing <code>com.sun.star.document.XDocumentInfo</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> getUserFieldCount()</code></li>
36 *  <li><code> getUserFieldName()</code></li>
37 *  <li><code> setUserFieldName()</code></li>
38 *  <li><code> getUserFieldValue()</code></li>
39 *  <li><code> setUserFieldValue()</code></li>
40 * </ul> <p>
41 * Test is <b> NOT </b> multithread compilant. <p>
42 * @see com.sun.star.document.XDocumentInfo
43 */
44 public class _XDocumentInfo extends MultiMethodTest {
45 
46     public XDocumentInfo oObj = null;
47 
48     short fieldCount;
49 
50     /**
51     * Gets user field count. <p>
52     * Has <b> OK </b> status if count is positive.
53     */
_getUserFieldCount()54     public void _getUserFieldCount() {
55         fieldCount = oObj.getUserFieldCount();
56         tRes.tested("getUserFieldCount()", fieldCount >= 0);
57     }
58 
59     String[] oldNames;
60     String[] oldValues;
61 
62     /**
63     * Retrieves all user field names and stores them. <p>
64     * Has <b> OK </b> status if no exceptions were thrown and
65     * names returned are not <code>null</code> values. <p>
66     * The following method tests are to be completed successfully before :
67     * <ul>
68     *  <li> <code> getUserFieldCount() </code> : to obtain number of
69     *    fields </li>
70     * </ul>
71     */
_getUserFieldName()72     public void _getUserFieldName() {
73         requiredMethod("getUserFieldCount()");
74 
75         oldNames = new String[fieldCount];
76 
77         for (short i = 0; i < fieldCount; i++) {
78             try {
79                 oldNames[i] = oObj.getUserFieldName(i);
80                 if (oldNames[i] == null) {
81                     tRes.tested("getUserFieldName()", false);
82                     return;
83                 }
84             } catch (ArrayIndexOutOfBoundsException e) {
85                 log.println("Couldn't get an user field name at " + i);
86                 tRes.tested("getUserFieldName()", false);
87                 return;
88             }
89         }
90 
91         tRes.tested("getUserFieldName()", true);
92     }
93 
94     /**
95     * For each field its name changed and the checked if it's properly
96     * changed. Finally old names are restored.<p>
97     * Has <b> OK </b> status if names were properly changed. <p>
98     * The following method tests are to be completed successfully before :
99     * <ul>
100     *  <li> <code> getUserFieldName() </code> : to retrieve old names </li>
101     * </ul>
102     */
_setUserFieldName()103     public void _setUserFieldName() {
104         requiredMethod("getUserFieldName()");
105 
106         for (short i = 0; i < fieldCount; i++) {
107             String newName = oldNames[i] + "_new";
108 
109             try {
110                 oObj.setUserFieldName(i, newName);
111             } catch (ArrayIndexOutOfBoundsException e) {
112                 log.println("Couldn't set an user field name at " + i);
113                 tRes.tested("setUserFieldName()", false);
114                 return;
115             }
116 
117             try {
118                 if (!newName.equals(oObj.getUserFieldName(i))) {
119                     tRes.tested("setUserFieldName()", false);
120                     return;
121                 }
122             } catch (ArrayIndexOutOfBoundsException e) {
123                 log.println("Couldn't set an user field name at " + i);
124                 tRes.tested("setUserFieldName()", false);
125                 return;
126             } finally {
127                 try {
128                     oObj.setUserFieldName(i, oldNames[i]);
129                 } catch (ArrayIndexOutOfBoundsException e) {
130                     log.println("Couldn't restore an user field name at " + i);
131                     tRes.tested("setUserFieldName()", false);
132                     return;
133                 }
134             }
135         }
136 
137         tRes.tested("setUserFieldName()", true);
138     }
139 
140 
141     /**
142     * Retrieves all user field values and stores them. <p>
143     * Has <b> OK </b> status if no exceptions were thrown and
144     * values returned are not <code>null</code> values. <p>
145     * The following method tests are to be completed successfully before :
146     * <ul>
147     *  <li> <code> getUserFieldCount() </code> : to obtain number of
148     *    fields </li>
149     * </ul>
150     */
_getUserFieldValue()151     public void _getUserFieldValue() {
152         requiredMethod("getUserFieldCount()");
153 
154         oldValues = new String[fieldCount];
155 
156         for (short i = 0; i < fieldCount; i++) {
157             try {
158                 oldValues[i] = oObj.getUserFieldValue(i);
159                 if (oldValues[i] == null) {
160                     tRes.tested("getUserFieldValue()", false);
161                     return;
162                 }
163             } catch (ArrayIndexOutOfBoundsException e) {
164                 log.println("Couldn't get an user field value at " + i);
165                 tRes.tested("getUserFieldValue()", false);
166                 return;
167             }
168         }
169 
170         tRes.tested("getUserFieldValue()", true);
171     }
172 
173     /**
174     * For each field its value changed and the checked if it's properly
175     * changed. Finally old values are restored.<p>
176     * Has <b> OK </b> status if values were properly changed. <p>
177     * The following method tests are to be completed successfully before :
178     * <ul>
179     *  <li> <code> getUserFieldValue() </code> : to retrieve old values. </li>
180     * </ul>
181     */
_setUserFieldValue()182     public void _setUserFieldValue() {
183         requiredMethod("getUserFieldValue()");
184 
185         for (short i = 0; i < fieldCount; i++) {
186             String newValue = oldValues[i] + "_new";
187 
188             try {
189                 oObj.setUserFieldValue(i, newValue);
190             } catch (ArrayIndexOutOfBoundsException e) {
191                 log.println("Couldn't set an user field value at " + i);
192                 tRes.tested("setUserFieldValue()", false);
193                 return;
194             }
195 
196             try {
197                 if (!newValue.equals(oObj.getUserFieldValue(i))) {
198                     tRes.tested("setUserFieldValue()", false);
199                     return;
200                 }
201             } catch (ArrayIndexOutOfBoundsException e) {
202                 log.println("Couldn't set an user field value at " + i);
203                 tRes.tested("setUserFieldValue()", false);
204                 return;
205             } finally {
206                 try {
207                     oObj.setUserFieldValue(i, oldNames[i]);
208                 } catch (ArrayIndexOutOfBoundsException e) {
209                     log.println("Couldn't restore an user field value at " + i);
210                     tRes.tested("setUserFieldValue()", false);
211                     return;
212                 }
213             }
214         }
215 
216         tRes.tested("setUserFieldValue()", true);
217     }
218 
219 }  // finish class _XDocumentInfo
220 
221