merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / text / _XPagePrintable.java
blob73c77c36fb1c9907343c032dbfe61dbeb1ef04cd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XPagePrintable.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.text;
33 import lib.MultiMethodTest;
34 import util.utils;
36 import com.sun.star.beans.PropertyValue;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.text.XPagePrintable;
40 /**
41 * Testing <code>com.sun.star.text.XPagePrintable</code>
42 * interface methods :
43 * <ul>
44 * <li><code> getPagePrintSettings()</code></li>
45 * <li><code> setPagePrintSettings()</code></li>
46 * <li><code> printPages()</code></li>
47 * </ul> <p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.text.XPagePrintable
51 public class _XPagePrintable extends MultiMethodTest {
53 public static XPagePrintable oObj = null;
54 public PropertyValue[] PrintSettings = new PropertyValue[0];
56 /**
57 * Types of print settings properties by order they returned by
58 * <code>getPagePrintSettings()</code>.
60 public String[] types = new String[]{"Short","Short","Integer","Integer",
61 "Integer","Integer","Integer","Integer","Boolean"};
63 /**
64 * Calls the method and examines the returned array of properties. <p>
66 * Has <b>OK</b> status if all properties' types are correspond
67 * to their expected values of the <code>types</code> array.
69 * @see #types
71 public void _getPagePrintSettings() {
72 boolean res = true;
73 PrintSettings = oObj.getPagePrintSettings();
75 for (int i=0;i<PrintSettings.length;i++) {
76 String the_type = PrintSettings[i].Value.getClass().toString();
77 if (!the_type.endsWith(types[i])) {
78 log.println("Name: "+PrintSettings[i].Name);
79 log.println("Value: "+PrintSettings[i].Value);
80 log.println("Type"+the_type);
81 log.println("Expected: java.lang."+types[i]);
82 res = false;
86 tRes.tested("getPagePrintSettings()",res);
89 /**
90 * Changes a property 'IsLandscape' in existsing print settings,
91 * and sets these settings back. <p>
93 * Has <b>OK</b> status if settings gotten again has the changed
94 * 'IsLandscape' property value. <p>
96 * The following method tests are to be completed successfully before :
97 * <ul>
98 * <li> <code> getPagePrintSettings() </code> : to have existing
99 * print settings. </li>
100 * </ul>
102 public void _setPagePrintSettings() {
103 requiredMethod("getPagePrintSettings()");
104 boolean res = true;
106 Boolean landscape = (Boolean) PrintSettings[8].Value;
107 Boolean newlandscape = new Boolean(!landscape.booleanValue());
108 PrintSettings[8].Value = newlandscape;
109 oObj.setPagePrintSettings(PrintSettings);
110 res = (oObj.getPagePrintSettings()[8].Value.equals(newlandscape));
112 tRes.tested("setPagePrintSettings()",res);
116 * Creates print options for printing into file situated in the SOffice
117 * temporary directory. If the file already exists it is deleted.
118 * Then calls the method. <p>
120 * Has <b>OK</b> status if the file to which printing must be performed
121 * is exists.
123 public void _printPages() {
124 boolean res = true;
126 try {
127 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
129 String printFile = utils.getOfficeTemp(xMSF) + "XPagePrintable.prt";
130 log.println("Printing to : "+ printFile);
132 PropertyValue[] PrintOptions = new PropertyValue[1];
133 PropertyValue firstProp = new PropertyValue();
134 firstProp.Name = "FileName";
136 firstProp.Value = printFile;
137 firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE;
138 PrintOptions[0] = firstProp;
140 if (! util.utils.deleteFile(xMSF, printFile)){
141 log.println("ERROR: could not remove '" + printFile + "'");
142 res = false;
145 oObj.printPages(PrintOptions);
147 util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT));
149 if (! util.utils.fileExists(xMSF, printFile)){
150 log.println("ERROR: could not find '" + printFile + "'");
151 res = false;
154 } catch (com.sun.star.lang.IllegalArgumentException ex) {
155 log.println("Exception while checking 'printPages'");
156 res = false;
157 ex.printStackTrace(log);
160 tRes.tested("printPages()",res);
163 } // finish class _XPagePrintable