2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
26 import com
.sun
.star
.beans
.PropertyValue
;
27 import com
.sun
.star
.ucb
.XSimpleFileAccess
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
29 import com
.sun
.star
.view
.PaperOrientation
;
30 import com
.sun
.star
.view
.XPrintable
;
33 * Testing <code>com.sun.star.view.XPrintable</code>
36 * <li><code> getPrinter()</code></li>
37 * <li><code> setPrinter()</code></li>
38 * <li><code> print()</code></li>
40 * Test is <b> NOT </b> multithread compliant. <p>
41 * @see com.sun.star.view.XPrintable
43 public class _XPrintable
extends MultiMethodTest
{
45 public XPrintable oObj
= null;
46 public PropertyValue
[] the_printer
= null;
49 * Test calls the method and stores returned value. <p>
50 * Has <b> OK </b> status if the method returns not
51 * <code>null</code> value.
53 public void _getPrinter(){
55 the_printer
= oObj
.getPrinter();
56 tRes
.tested("getPrinter()",the_printer
!= null);
57 } // finish _getPrinter
60 * Changes <code>PaperOrientation</code> property in the old
61 * printer configuration and sets changed value as a new printer.<p>
63 * Has <b> OK </b> status if the <code>getPrinter</code> method
64 * returns printer with changed property. <p>
66 * The following method tests are to be completed successfully before :
68 * <li> <code> getPrinter() </code> : to change one property
69 * in existing printer configuration. </li>
72 public void _setPrinter(){
73 requiredMethod("getPrinter()");
75 while (!"PaperOrientation".equals(the_printer
[propIdx
].Name
)) {
78 PaperOrientation newVal
= null ;
79 if (the_printer
[propIdx
].Value
== PaperOrientation
.PORTRAIT
)
80 newVal
= PaperOrientation
.LANDSCAPE
;
82 newVal
= PaperOrientation
.PORTRAIT
;
84 the_printer
[propIdx
].Value
= newVal
;
87 oObj
.setPrinter(the_printer
);
88 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
89 log
.println("couldn't set printer");
90 ex
.printStackTrace(log
);
91 tRes
.tested("setPrinter()",false);
94 the_printer
= oObj
.getPrinter() ;
97 while (!"PaperOrientation".equals(the_printer
[propIdx
].Name
)) {
101 boolean the_same
= the_printer
[propIdx
].Value
== newVal
;
102 tRes
.tested("setPrinter()", the_same
);
104 } // finish _setPrinter
107 * Printing performed into file in SOffice temp directory.
108 * First this file is deleted if it already exist (using
109 * <code>com.sun.star.ucb.SimpleFileAccess</code> service.
110 * After that the method with appropriate parameter is
113 * Has <b> OK </b> status if the file to which printing is made
116 * @throws StatusException if service
117 * <code>com.sun.star.ucb.SimpleFileAccess</code> can't be
120 public void _print() throws Exception
{
121 boolean result
= true ;
123 final String file
= "XPrintable.prt" ;
124 final String fileName
= utils
.getOfficeTempDirSys(tParam
.getMSF())+file
;
125 final String fileURL
= utils
.getOfficeTemp(tParam
.getMSF()) + file
;
128 tParam
.getMSF().createInstance
129 ("com.sun.star.ucb.SimpleFileAccess") ;
130 XSimpleFileAccess fAcc
= UnoRuntime
.queryInterface
131 (XSimpleFileAccess
.class, oFAcc
) ;
132 if (fAcc
== null) throw new StatusException
133 (Status
.failed("Can't create SimpleFileAccess service")) ;
134 if (fAcc
.exists(fileURL
)) {
135 log
.println("Old file exists and will be deleted");
140 PropertyValue
[] PrintOptions
= new PropertyValue
[2];
141 PropertyValue firstProp
= new PropertyValue();
142 firstProp
.Name
= "FileName";
143 log
.println("Printing to :"+fileName
);
144 firstProp
.Value
= fileName
;
145 firstProp
.State
= com
.sun
.star
.beans
.PropertyState
.DEFAULT_VALUE
;
146 PrintOptions
[0] = firstProp
;
147 PrintOptions
[1] = new PropertyValue();
148 PrintOptions
[1].Name
= "Wait";
149 PrintOptions
[1].Value
= Boolean
.TRUE
;
150 oObj
.print(PrintOptions
);
152 catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
153 log
.println("couldn't print");
154 ex
.printStackTrace(log
);
159 boolean fileExists
= fAcc
.exists(fileURL
);
161 log
.println("File "+fileName
+" exists = "+fileExists
);
164 result
&= fileExists
;
166 } catch (com
.sun
.star
.uno
.Exception e
) {
167 log
.println("Error while checking file '" +
169 e
.printStackTrace(log
);
173 tRes
.tested("print()", result
) ;
177 } // finish class _XPrintable