1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XPrintable.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
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
;
46 * Testing <code>com.sun.star.view.XPrintable</code>
49 * <li><code> getPrinter()</code></li>
50 * <li><code> setPrinter()</code></li>
51 * <li><code> print()</code></li>
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;
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
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 :
81 * <li> <code> getPrinter() </code> : to change one property
82 * in existing printer configuration. </li>
85 public void _setPrinter(){
86 requiredMethod("getPrinter()");
88 while (!"PaperOrientation".equals(the_printer
[propIdx
].Name
)) {
91 PaperOrientation newVal
= null ;
92 if (the_printer
[propIdx
].Value
== PaperOrientation
.PORTRAIT
)
93 newVal
= PaperOrientation
.LANDSCAPE
;
95 newVal
= PaperOrientation
.PORTRAIT
;
97 the_printer
[propIdx
].Value
= newVal
;
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() ;
111 while (!"PaperOrientation".equals(the_printer
[propIdx
].Name
)) {
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
127 * Has <b> OK </b> status if the file to which printing is made
130 * @throws StatusException if service
131 * <code>com.sun.star.ucb.SimpleFileAccess</code> cann't be
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 ;
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");
154 } catch (com
.sun
.star
.uno
.Exception e
) {
155 log
.println("Error accessing file '" + fileURL
+ "'");
156 e
.printStackTrace(log
);
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
);
179 boolean fileExists
= fAcc
.exists(fileURL
);
181 log
.println("File "+fileName
+" exists = "+fileExists
);
184 result
&= fileExists
;
186 } catch (com
.sun
.star
.uno
.Exception e
) {
187 log
.println("Error while while checking file '" +
189 e
.printStackTrace(log
);
193 tRes
.tested("print()", result
) ;
197 } // finish class _XPrintable