1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.text; 25 26 import lib.MultiMethodTest; 27 import util.utils; 28 29 import com.sun.star.beans.PropertyValue; 30 import com.sun.star.lang.XMultiServiceFactory; 31 import com.sun.star.text.XPagePrintable; 32 33 /** 34 * Testing <code>com.sun.star.text.XPagePrintable</code> 35 * interface methods : 36 * <ul> 37 * <li><code> getPagePrintSettings()</code></li> 38 * <li><code> setPagePrintSettings()</code></li> 39 * <li><code> printPages()</code></li> 40 * </ul> <p> 41 * Test is <b> NOT </b> multithread compilant. <p> 42 * @see com.sun.star.text.XPagePrintable 43 */ 44 public class _XPagePrintable extends MultiMethodTest { 45 46 public static XPagePrintable oObj = null; 47 public PropertyValue[] PrintSettings = new PropertyValue[0]; 48 49 /** 50 * Types of print settings properties by order they returned by 51 * <code>getPagePrintSettings()</code>. 52 */ 53 public String[] types = new String[]{"Short","Short","Integer","Integer", 54 "Integer","Integer","Integer","Integer","Boolean"}; 55 56 /** 57 * Calls the method and examines the returned array of properties. <p> 58 * 59 * Has <b>OK</b> status if all properties' types are correspond 60 * to their expected values of the <code>types</code> array. 61 * 62 * @see #types 63 */ _getPagePrintSettings()64 public void _getPagePrintSettings() { 65 boolean res = true; 66 PrintSettings = oObj.getPagePrintSettings(); 67 68 for (int i=0;i<PrintSettings.length;i++) { 69 String the_type = PrintSettings[i].Value.getClass().toString(); 70 if (!the_type.endsWith(types[i])) { 71 log.println("Name: "+PrintSettings[i].Name); 72 log.println("Value: "+PrintSettings[i].Value); 73 log.println("Type"+the_type); 74 log.println("Expected: java.lang."+types[i]); 75 res = false; 76 } 77 } 78 79 tRes.tested("getPagePrintSettings()",res); 80 } 81 82 /** 83 * Changes a property 'IsLandscape' in existsing print settings, 84 * and sets these settings back. <p> 85 * 86 * Has <b>OK</b> status if settings gotten again has the changed 87 * 'IsLandscape' property value. <p> 88 * 89 * The following method tests are to be completed successfully before : 90 * <ul> 91 * <li> <code> getPagePrintSettings() </code> : to have existing 92 * print settings. </li> 93 * </ul> 94 */ _setPagePrintSettings()95 public void _setPagePrintSettings() { 96 requiredMethod("getPagePrintSettings()"); 97 boolean res = true; 98 99 Boolean landscape = (Boolean) PrintSettings[8].Value; 100 Boolean newlandscape = new Boolean(!landscape.booleanValue()); 101 PrintSettings[8].Value = newlandscape; 102 oObj.setPagePrintSettings(PrintSettings); 103 res = (oObj.getPagePrintSettings()[8].Value.equals(newlandscape)); 104 105 tRes.tested("setPagePrintSettings()",res); 106 } 107 108 /** 109 * Creates print options for printing into file situated in the SOffice 110 * temporary directory. If the file already exists it is deleted. 111 * Then calls the method. <p> 112 * 113 * Has <b>OK</b> status if the file to which printing must be performed 114 * is exists. 115 */ _printPages()116 public void _printPages() { 117 boolean res = true; 118 119 try { 120 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 121 122 String printFile = utils.getOfficeTemp(xMSF) + "XPagePrintable.prt"; 123 log.println("Printing to : "+ printFile); 124 125 PropertyValue[] PrintOptions = new PropertyValue[1]; 126 PropertyValue firstProp = new PropertyValue(); 127 firstProp.Name = "FileName"; 128 129 firstProp.Value = printFile; 130 firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE; 131 PrintOptions[0] = firstProp; 132 133 if (! util.utils.deleteFile(xMSF, printFile)){ 134 log.println("ERROR: could not remove '" + printFile + "'"); 135 res = false; 136 } 137 138 oObj.printPages(PrintOptions); 139 140 util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT)); 141 142 if (! util.utils.fileExists(xMSF, printFile)){ 143 log.println("ERROR: could not find '" + printFile + "'"); 144 res = false; 145 } 146 147 } catch (com.sun.star.lang.IllegalArgumentException ex) { 148 log.println("Exception while checking 'printPages'"); 149 res = false; 150 ex.printStackTrace(log); 151 } 152 153 tRes.tested("printPages()",res); 154 } 155 156 } // finish class _XPagePrintable 157 158