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