1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.view; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir import lib.Status; 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir import util.utils; 30cdf0e10cSrcweir 31cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 32cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 33cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess; 34cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 35cdf0e10cSrcweir import com.sun.star.view.PaperOrientation; 36cdf0e10cSrcweir import com.sun.star.view.XPrintable; 37cdf0e10cSrcweir 38cdf0e10cSrcweir /** 39cdf0e10cSrcweir * Testing <code>com.sun.star.view.XPrintable</code> 40cdf0e10cSrcweir * interface methods : 41cdf0e10cSrcweir * <ul> 42cdf0e10cSrcweir * <li><code> getPrinter()</code></li> 43cdf0e10cSrcweir * <li><code> setPrinter()</code></li> 44cdf0e10cSrcweir * <li><code> print()</code></li> 45cdf0e10cSrcweir * </ul> <p> 46cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 47cdf0e10cSrcweir * @see com.sun.star.view.XPrintable 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir public class _XPrintable extends MultiMethodTest { 50cdf0e10cSrcweir 51cdf0e10cSrcweir public XPrintable oObj = null; 52cdf0e10cSrcweir public PropertyValue[] the_printer = null; 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** 55cdf0e10cSrcweir * Test calls the method and stores returned value. <p> 56cdf0e10cSrcweir * Has <b> OK </b> status if the method returns not 57cdf0e10cSrcweir * <code>null</code> value. 58cdf0e10cSrcweir */ _getPrinter()59cdf0e10cSrcweir public void _getPrinter(){ 60cdf0e10cSrcweir 61cdf0e10cSrcweir the_printer = oObj.getPrinter(); 62cdf0e10cSrcweir tRes.tested("getPrinter()",the_printer != null); 63cdf0e10cSrcweir } // finish _getPrinter 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** 66cdf0e10cSrcweir * Changes <code>PaperOrientation</code> property in the old 67cdf0e10cSrcweir * printer configuration and sets changed value as a new printer.<p> 68cdf0e10cSrcweir * 69cdf0e10cSrcweir * Has <b> OK </b> status if the <code>getPrinter</code> method 70cdf0e10cSrcweir * retursn printer with changed property. <p> 71cdf0e10cSrcweir * 72cdf0e10cSrcweir * The following method tests are to be completed successfully before : 73cdf0e10cSrcweir * <ul> 74cdf0e10cSrcweir * <li> <code> getPrinter() </code> : to change one property 75cdf0e10cSrcweir * in existing printer configuration. </li> 76cdf0e10cSrcweir * </ul> 77cdf0e10cSrcweir */ _setPrinter()78cdf0e10cSrcweir public void _setPrinter(){ 79cdf0e10cSrcweir requiredMethod("getPrinter()"); 80cdf0e10cSrcweir int propIdx = 0 ; 81cdf0e10cSrcweir while (!"PaperOrientation".equals(the_printer[propIdx].Name)) { 82cdf0e10cSrcweir propIdx++ ; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir PaperOrientation newVal = null ; 85cdf0e10cSrcweir if (the_printer[propIdx].Value == PaperOrientation.PORTRAIT) 86cdf0e10cSrcweir newVal = PaperOrientation.LANDSCAPE ; 87cdf0e10cSrcweir else 88cdf0e10cSrcweir newVal = PaperOrientation.PORTRAIT ; 89cdf0e10cSrcweir 90cdf0e10cSrcweir the_printer[propIdx].Value = newVal ; 91cdf0e10cSrcweir 92cdf0e10cSrcweir try { 93cdf0e10cSrcweir oObj.setPrinter(the_printer); 94cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException ex) { 95cdf0e10cSrcweir log.println("couldn't set printer"); 96cdf0e10cSrcweir ex.printStackTrace(log); 97cdf0e10cSrcweir tRes.tested("setPrinter()",false); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir //oObj.setPrinter(the_printer); 101cdf0e10cSrcweir the_printer = oObj.getPrinter() ; 102cdf0e10cSrcweir 103cdf0e10cSrcweir propIdx = 0 ; 104cdf0e10cSrcweir while (!"PaperOrientation".equals(the_printer[propIdx].Name)) { 105cdf0e10cSrcweir propIdx++ ; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir boolean the_same = the_printer[propIdx].Value == newVal; 109cdf0e10cSrcweir tRes.tested("setPrinter()", the_same); 110cdf0e10cSrcweir 111cdf0e10cSrcweir } // finish _setPrinter 112cdf0e10cSrcweir 113cdf0e10cSrcweir /** 114cdf0e10cSrcweir * Printing performed into file in SOffice temp directory. 115cdf0e10cSrcweir * First this file is deleted if it already exist (using 116cdf0e10cSrcweir * <code>com.sun.star.ucb.SimpleFileAccess</code> service. 117cdf0e10cSrcweir * After that the method with appropriate parameter is 118cdf0e10cSrcweir * called.<p> 119cdf0e10cSrcweir * 120cdf0e10cSrcweir * Has <b> OK </b> status if the file to which printing is made 121cdf0e10cSrcweir * exists. <p> 122cdf0e10cSrcweir * 123cdf0e10cSrcweir * @throws StatusException if service 124cdf0e10cSrcweir * <code>com.sun.star.ucb.SimpleFileAccess</code> cann't be 125cdf0e10cSrcweir * created. 126cdf0e10cSrcweir */ _print()127cdf0e10cSrcweir public void _print(){ 128cdf0e10cSrcweir boolean result = true ; 129cdf0e10cSrcweir 130cdf0e10cSrcweir final String file = "XPrintable.prt" ; 131cdf0e10cSrcweir final String fileName = utils.getOfficeTempDirSys((XMultiServiceFactory)tParam.getMSF())+file ; 132cdf0e10cSrcweir final String fileURL = utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) + file ; 133cdf0e10cSrcweir 134cdf0e10cSrcweir XSimpleFileAccess fAcc = null ; 135cdf0e10cSrcweir try { 136cdf0e10cSrcweir Object oFAcc = 137cdf0e10cSrcweir ((XMultiServiceFactory)tParam.getMSF()).createInstance 138cdf0e10cSrcweir ("com.sun.star.ucb.SimpleFileAccess") ; 139cdf0e10cSrcweir fAcc = (XSimpleFileAccess) UnoRuntime.queryInterface 140cdf0e10cSrcweir (XSimpleFileAccess.class, oFAcc) ; 141cdf0e10cSrcweir if (fAcc == null) throw new StatusException 142cdf0e10cSrcweir (Status.failed("Can't create SimpleFileAccess service")) ; 143cdf0e10cSrcweir if (fAcc.exists(fileURL)) { 144cdf0e10cSrcweir log.println("Old file exists and will be deleted"); 145cdf0e10cSrcweir fAcc.kill(fileURL); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 148cdf0e10cSrcweir log.println("Error accessing file '" + fileURL + "'"); 149cdf0e10cSrcweir e.printStackTrace(log); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir try { 153cdf0e10cSrcweir PropertyValue[] PrintOptions = new PropertyValue[2]; 154cdf0e10cSrcweir PropertyValue firstProp = new PropertyValue(); 155cdf0e10cSrcweir firstProp.Name = "FileName"; 156cdf0e10cSrcweir log.println("Printing to :"+fileName); 157cdf0e10cSrcweir firstProp.Value = fileName; 158cdf0e10cSrcweir firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE; 159cdf0e10cSrcweir PrintOptions[0] = firstProp; 160cdf0e10cSrcweir PrintOptions[1] = new PropertyValue(); 161cdf0e10cSrcweir PrintOptions[1].Name = "Wait"; 162cdf0e10cSrcweir PrintOptions[1].Value = new Boolean(true); 163cdf0e10cSrcweir oObj.print(PrintOptions); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir catch (com.sun.star.lang.IllegalArgumentException ex) { 166cdf0e10cSrcweir log.println("couldn't print"); 167cdf0e10cSrcweir ex.printStackTrace(log); 168cdf0e10cSrcweir result = false ; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir try { 172cdf0e10cSrcweir boolean fileExists = fAcc.exists(fileURL); 173cdf0e10cSrcweir 174cdf0e10cSrcweir log.println("File "+fileName+" exists = "+fileExists); 175cdf0e10cSrcweir 176cdf0e10cSrcweir if (result) { 177cdf0e10cSrcweir result &= fileExists ; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 180cdf0e10cSrcweir log.println("Error while while checking file '" + 181cdf0e10cSrcweir fileURL + "': "); 182cdf0e10cSrcweir e.printStackTrace(log); 183cdf0e10cSrcweir result = false ; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir tRes.tested("print()", result) ; 187cdf0e10cSrcweir 188cdf0e10cSrcweir } // finish _print 189cdf0e10cSrcweir 190cdf0e10cSrcweir } // finish class _XPrintable 191cdf0e10cSrcweir 192cdf0e10cSrcweir 193