merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / view / _XPrintable.java
blob902c4c76f9844e33159b999cd7155b7d3299f640
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: _XPrintable.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.view;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
36 import util.utils;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.ucb.XSimpleFileAccess;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.view.PaperOrientation;
43 import com.sun.star.view.XPrintable;
45 /**
46 * Testing <code>com.sun.star.view.XPrintable</code>
47 * interface methods :
48 * <ul>
49 * <li><code> getPrinter()</code></li>
50 * <li><code> setPrinter()</code></li>
51 * <li><code> print()</code></li>
52 * </ul> <p>
53 * Test is <b> NOT </b> multithread compilant. <p>
54 * @see com.sun.star.view.XPrintable
56 public class _XPrintable extends MultiMethodTest {
58 public XPrintable oObj = null;
59 public PropertyValue[] the_printer = null;
61 /**
62 * Test calls the method and stores returned value. <p>
63 * Has <b> OK </b> status if the method returns not
64 * <code>null</code> value.
66 public void _getPrinter(){
68 the_printer = oObj.getPrinter();
69 tRes.tested("getPrinter()",the_printer != null);
70 } // finish _getPrinter
72 /**
73 * Changes <code>PaperOrientation</code> property in the old
74 * printer configuration and sets changed value as a new printer.<p>
76 * Has <b> OK </b> status if the <code>getPrinter</code> method
77 * retursn printer with changed property. <p>
79 * The following method tests are to be completed successfully before :
80 * <ul>
81 * <li> <code> getPrinter() </code> : to change one property
82 * in existing printer configuration. </li>
83 * </ul>
85 public void _setPrinter(){
86 requiredMethod("getPrinter()");
87 int propIdx = 0 ;
88 while (!"PaperOrientation".equals(the_printer[propIdx].Name)) {
89 propIdx++ ;
91 PaperOrientation newVal = null ;
92 if (the_printer[propIdx].Value == PaperOrientation.PORTRAIT)
93 newVal = PaperOrientation.LANDSCAPE ;
94 else
95 newVal = PaperOrientation.PORTRAIT ;
97 the_printer[propIdx].Value = newVal ;
99 try {
100 oObj.setPrinter(the_printer);
101 } catch (com.sun.star.lang.IllegalArgumentException ex) {
102 log.println("couldn't set printer");
103 ex.printStackTrace(log);
104 tRes.tested("setPrinter()",false);
107 //oObj.setPrinter(the_printer);
108 the_printer = oObj.getPrinter() ;
110 propIdx = 0 ;
111 while (!"PaperOrientation".equals(the_printer[propIdx].Name)) {
112 propIdx++ ;
115 boolean the_same = the_printer[propIdx].Value == newVal;
116 tRes.tested("setPrinter()", the_same);
118 } // finish _setPrinter
121 * Printing performed into file in SOffice temp directory.
122 * First this file is deleted if it already exist (using
123 * <code>com.sun.star.ucb.SimpleFileAccess</code> service.
124 * After that the method with appropriate parameter is
125 * called.<p>
127 * Has <b> OK </b> status if the file to which printing is made
128 * exists. <p>
130 * @throws StatusException if service
131 * <code>com.sun.star.ucb.SimpleFileAccess</code> cann't be
132 * created.
134 public void _print(){
135 boolean result = true ;
137 final String file = "XPrintable.prt" ;
138 final String fileName = utils.getOfficeTempDirSys((XMultiServiceFactory)tParam.getMSF())+file ;
139 final String fileURL = utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) + file ;
141 XSimpleFileAccess fAcc = null ;
142 try {
143 Object oFAcc =
144 ((XMultiServiceFactory)tParam.getMSF()).createInstance
145 ("com.sun.star.ucb.SimpleFileAccess") ;
146 fAcc = (XSimpleFileAccess) UnoRuntime.queryInterface
147 (XSimpleFileAccess.class, oFAcc) ;
148 if (fAcc == null) throw new StatusException
149 (Status.failed("Can't create SimpleFileAccess service")) ;
150 if (fAcc.exists(fileURL)) {
151 log.println("Old file exists and will be deleted");
152 fAcc.kill(fileURL);
154 } catch (com.sun.star.uno.Exception e) {
155 log.println("Error accessing file '" + fileURL + "'");
156 e.printStackTrace(log);
159 try {
160 PropertyValue[] PrintOptions = new PropertyValue[2];
161 PropertyValue firstProp = new PropertyValue();
162 firstProp.Name = "FileName";
163 log.println("Printing to :"+fileName);
164 firstProp.Value = fileName;
165 firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE;
166 PrintOptions[0] = firstProp;
167 PrintOptions[1] = new PropertyValue();
168 PrintOptions[1].Name = "Wait";
169 PrintOptions[1].Value = new Boolean(true);
170 oObj.print(PrintOptions);
172 catch (com.sun.star.lang.IllegalArgumentException ex) {
173 log.println("couldn't print");
174 ex.printStackTrace(log);
175 result = false ;
178 try {
179 boolean fileExists = fAcc.exists(fileURL);
181 log.println("File "+fileName+" exists = "+fileExists);
183 if (result) {
184 result &= fileExists ;
186 } catch (com.sun.star.uno.Exception e) {
187 log.println("Error while while checking file '" +
188 fileURL + "': ");
189 e.printStackTrace(log);
190 result = false ;
193 tRes.tested("print()", result) ;
195 } // finish _print
197 } // finish class _XPrintable