bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / view / _XPrintable.java
blobeba0f695f719ca96928796a58720f9759e2a16f9
1 /*
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 .
19 package ifc.view;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
24 import util.utils;
26 import com.sun.star.beans.PropertyValue;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.ucb.XSimpleFileAccess;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.view.PaperOrientation;
31 import com.sun.star.view.XPrintable;
33 /**
34 * Testing <code>com.sun.star.view.XPrintable</code>
35 * interface methods :
36 * <ul>
37 * <li><code> getPrinter()</code></li>
38 * <li><code> setPrinter()</code></li>
39 * <li><code> print()</code></li>
40 * </ul> <p>
41 * Test is <b> NOT </b> multithread compilant. <p>
42 * @see com.sun.star.view.XPrintable
44 public class _XPrintable extends MultiMethodTest {
46 public XPrintable oObj = null;
47 public PropertyValue[] the_printer = null;
49 /**
50 * Test calls the method and stores returned value. <p>
51 * Has <b> OK </b> status if the method returns not
52 * <code>null</code> value.
54 public void _getPrinter(){
56 the_printer = oObj.getPrinter();
57 tRes.tested("getPrinter()",the_printer != null);
58 } // finish _getPrinter
60 /**
61 * Changes <code>PaperOrientation</code> property in the old
62 * printer configuration and sets changed value as a new printer.<p>
64 * Has <b> OK </b> status if the <code>getPrinter</code> method
65 * retursn printer with changed property. <p>
67 * The following method tests are to be completed successfully before :
68 * <ul>
69 * <li> <code> getPrinter() </code> : to change one property
70 * in existing printer configuration. </li>
71 * </ul>
73 public void _setPrinter(){
74 requiredMethod("getPrinter()");
75 int propIdx = 0 ;
76 while (!"PaperOrientation".equals(the_printer[propIdx].Name)) {
77 propIdx++ ;
79 PaperOrientation newVal = null ;
80 if (the_printer[propIdx].Value == PaperOrientation.PORTRAIT)
81 newVal = PaperOrientation.LANDSCAPE ;
82 else
83 newVal = PaperOrientation.PORTRAIT ;
85 the_printer[propIdx].Value = newVal ;
87 try {
88 oObj.setPrinter(the_printer);
89 } catch (com.sun.star.lang.IllegalArgumentException ex) {
90 log.println("couldn't set printer");
91 ex.printStackTrace(log);
92 tRes.tested("setPrinter()",false);
95 //oObj.setPrinter(the_printer);
96 the_printer = oObj.getPrinter() ;
98 propIdx = 0 ;
99 while (!"PaperOrientation".equals(the_printer[propIdx].Name)) {
100 propIdx++ ;
103 boolean the_same = the_printer[propIdx].Value == newVal;
104 tRes.tested("setPrinter()", the_same);
106 } // finish _setPrinter
109 * Printing performed into file in SOffice temp directory.
110 * First this file is deleted if it already exist (using
111 * <code>com.sun.star.ucb.SimpleFileAccess</code> service.
112 * After that the method with appropriate parameter is
113 * called.<p>
115 * Has <b> OK </b> status if the file to which printing is made
116 * exists. <p>
118 * @throws StatusException if service
119 * <code>com.sun.star.ucb.SimpleFileAccess</code> cann't be
120 * created.
122 public void _print(){
123 boolean result = true ;
125 final String file = "XPrintable.prt" ;
126 final String fileName = utils.getOfficeTempDirSys((XMultiServiceFactory)tParam.getMSF())+file ;
127 final String fileURL = utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) + file ;
129 XSimpleFileAccess fAcc = null ;
130 try {
131 Object oFAcc =
132 ((XMultiServiceFactory)tParam.getMSF()).createInstance
133 ("com.sun.star.ucb.SimpleFileAccess") ;
134 fAcc = UnoRuntime.queryInterface
135 (XSimpleFileAccess.class, oFAcc) ;
136 if (fAcc == null) throw new StatusException
137 (Status.failed("Can't create SimpleFileAccess service")) ;
138 if (fAcc.exists(fileURL)) {
139 log.println("Old file exists and will be deleted");
140 fAcc.kill(fileURL);
142 } catch (com.sun.star.uno.Exception e) {
143 log.println("Error accessing file '" + fileURL + "'");
144 e.printStackTrace(log);
147 try {
148 PropertyValue[] PrintOptions = new PropertyValue[2];
149 PropertyValue firstProp = new PropertyValue();
150 firstProp.Name = "FileName";
151 log.println("Printing to :"+fileName);
152 firstProp.Value = fileName;
153 firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE;
154 PrintOptions[0] = firstProp;
155 PrintOptions[1] = new PropertyValue();
156 PrintOptions[1].Name = "Wait";
157 PrintOptions[1].Value = new Boolean(true);
158 oObj.print(PrintOptions);
160 catch (com.sun.star.lang.IllegalArgumentException ex) {
161 log.println("couldn't print");
162 ex.printStackTrace(log);
163 result = false ;
166 try {
167 boolean fileExists = fAcc.exists(fileURL);
169 log.println("File "+fileName+" exists = "+fileExists);
171 if (result) {
172 result &= fileExists ;
174 } catch (com.sun.star.uno.Exception e) {
175 log.println("Error while while checking file '" +
176 fileURL + "': ");
177 e.printStackTrace(log);
178 result = false ;
181 tRes.tested("print()", result) ;
183 } // finish _print
185 } // finish class _XPrintable