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.text; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiMethodTest; 31*cdf0e10cSrcweir import util.utils; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 34*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 35*cdf0e10cSrcweir import com.sun.star.text.XPagePrintable; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir /** 38*cdf0e10cSrcweir * Testing <code>com.sun.star.text.XPagePrintable</code> 39*cdf0e10cSrcweir * interface methods : 40*cdf0e10cSrcweir * <ul> 41*cdf0e10cSrcweir * <li><code> getPagePrintSettings()</code></li> 42*cdf0e10cSrcweir * <li><code> setPagePrintSettings()</code></li> 43*cdf0e10cSrcweir * <li><code> printPages()</code></li> 44*cdf0e10cSrcweir * </ul> <p> 45*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 46*cdf0e10cSrcweir * @see com.sun.star.text.XPagePrintable 47*cdf0e10cSrcweir */ 48*cdf0e10cSrcweir public class _XPagePrintable extends MultiMethodTest { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir public static XPagePrintable oObj = null; 51*cdf0e10cSrcweir public PropertyValue[] PrintSettings = new PropertyValue[0]; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir /** 54*cdf0e10cSrcweir * Types of print settings properties by order they returned by 55*cdf0e10cSrcweir * <code>getPagePrintSettings()</code>. 56*cdf0e10cSrcweir */ 57*cdf0e10cSrcweir public String[] types = new String[]{"Short","Short","Integer","Integer", 58*cdf0e10cSrcweir "Integer","Integer","Integer","Integer","Boolean"}; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /** 61*cdf0e10cSrcweir * Calls the method and examines the returned array of properties. <p> 62*cdf0e10cSrcweir * 63*cdf0e10cSrcweir * Has <b>OK</b> status if all properties' types are correspond 64*cdf0e10cSrcweir * to their expected values of the <code>types</code> array. 65*cdf0e10cSrcweir * 66*cdf0e10cSrcweir * @see #types 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir public void _getPagePrintSettings() { 69*cdf0e10cSrcweir boolean res = true; 70*cdf0e10cSrcweir PrintSettings = oObj.getPagePrintSettings(); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir for (int i=0;i<PrintSettings.length;i++) { 73*cdf0e10cSrcweir String the_type = PrintSettings[i].Value.getClass().toString(); 74*cdf0e10cSrcweir if (!the_type.endsWith(types[i])) { 75*cdf0e10cSrcweir log.println("Name: "+PrintSettings[i].Name); 76*cdf0e10cSrcweir log.println("Value: "+PrintSettings[i].Value); 77*cdf0e10cSrcweir log.println("Type"+the_type); 78*cdf0e10cSrcweir log.println("Expected: java.lang."+types[i]); 79*cdf0e10cSrcweir res = false; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir tRes.tested("getPagePrintSettings()",res); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir /** 87*cdf0e10cSrcweir * Changes a property 'IsLandscape' in existsing print settings, 88*cdf0e10cSrcweir * and sets these settings back. <p> 89*cdf0e10cSrcweir * 90*cdf0e10cSrcweir * Has <b>OK</b> status if settings gotten again has the changed 91*cdf0e10cSrcweir * 'IsLandscape' property value. <p> 92*cdf0e10cSrcweir * 93*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 94*cdf0e10cSrcweir * <ul> 95*cdf0e10cSrcweir * <li> <code> getPagePrintSettings() </code> : to have existing 96*cdf0e10cSrcweir * print settings. </li> 97*cdf0e10cSrcweir * </ul> 98*cdf0e10cSrcweir */ 99*cdf0e10cSrcweir public void _setPagePrintSettings() { 100*cdf0e10cSrcweir requiredMethod("getPagePrintSettings()"); 101*cdf0e10cSrcweir boolean res = true; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir Boolean landscape = (Boolean) PrintSettings[8].Value; 104*cdf0e10cSrcweir Boolean newlandscape = new Boolean(!landscape.booleanValue()); 105*cdf0e10cSrcweir PrintSettings[8].Value = newlandscape; 106*cdf0e10cSrcweir oObj.setPagePrintSettings(PrintSettings); 107*cdf0e10cSrcweir res = (oObj.getPagePrintSettings()[8].Value.equals(newlandscape)); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir tRes.tested("setPagePrintSettings()",res); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir /** 113*cdf0e10cSrcweir * Creates print options for printing into file situated in the SOffice 114*cdf0e10cSrcweir * temporary directory. If the file already exists it is deleted. 115*cdf0e10cSrcweir * Then calls the method. <p> 116*cdf0e10cSrcweir * 117*cdf0e10cSrcweir * Has <b>OK</b> status if the file to which printing must be performed 118*cdf0e10cSrcweir * is exists. 119*cdf0e10cSrcweir */ 120*cdf0e10cSrcweir public void _printPages() { 121*cdf0e10cSrcweir boolean res = true; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir try { 124*cdf0e10cSrcweir XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir String printFile = utils.getOfficeTemp(xMSF) + "XPagePrintable.prt"; 127*cdf0e10cSrcweir log.println("Printing to : "+ printFile); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir PropertyValue[] PrintOptions = new PropertyValue[1]; 130*cdf0e10cSrcweir PropertyValue firstProp = new PropertyValue(); 131*cdf0e10cSrcweir firstProp.Name = "FileName"; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir firstProp.Value = printFile; 134*cdf0e10cSrcweir firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE; 135*cdf0e10cSrcweir PrintOptions[0] = firstProp; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir if (! util.utils.deleteFile(xMSF, printFile)){ 138*cdf0e10cSrcweir log.println("ERROR: could not remove '" + printFile + "'"); 139*cdf0e10cSrcweir res = false; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir oObj.printPages(PrintOptions); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT)); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir if (! util.utils.fileExists(xMSF, printFile)){ 147*cdf0e10cSrcweir log.println("ERROR: could not find '" + printFile + "'"); 148*cdf0e10cSrcweir res = false; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException ex) { 152*cdf0e10cSrcweir log.println("Exception while checking 'printPages'"); 153*cdf0e10cSrcweir res = false; 154*cdf0e10cSrcweir ex.printStackTrace(log); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir tRes.tested("printPages()",res); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir } // finish class _XPagePrintable 161*cdf0e10cSrcweir 162