/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package ifc.view;
import lib.MultiMethodTest;
import lib.Status;
import lib.StatusException;
import util.utils;
import com.sun.star.beans.PropertyValue;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.view.PaperOrientation;
import com.sun.star.view.XPrintable;
/**
* Testing com.sun.star.view.XPrintable
* interface methods :
*
getPrinter()
setPrinter()
print()
* Test is NOT multithread compilant.
* @see com.sun.star.view.XPrintable */ public class _XPrintable extends MultiMethodTest { public XPrintable oObj = null; public PropertyValue[] the_printer = null; /** * Test calls the method and stores returned value.
* Has OK status if the method returns not
* null
value.
*/
public void _getPrinter(){
the_printer = oObj.getPrinter();
tRes.tested("getPrinter()",the_printer != null);
} // finish _getPrinter
/**
* Changes PaperOrientation
property in the old
* printer configuration and sets changed value as a new printer.
*
* Has OK status if the getPrinter
method
* retursn printer with changed property.
* * The following method tests are to be completed successfully before : *
getPrinter()
: to change one property
* in existing printer configuration. com.sun.star.ucb.SimpleFileAccess
service.
* After that the method with appropriate parameter is
* called.* * Has OK status if the file to which printing is made * exists.
*
* @throws StatusException if service
* com.sun.star.ucb.SimpleFileAccess
cann't be
* created.
*/
public void _print(){
boolean result = true ;
final String file = "XPrintable.prt" ;
final String fileName = utils.getOfficeTempDirSys((XMultiServiceFactory)tParam.getMSF())+file ;
final String fileURL = utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) + file ;
XSimpleFileAccess fAcc = null ;
try {
Object oFAcc =
((XMultiServiceFactory)tParam.getMSF()).createInstance
("com.sun.star.ucb.SimpleFileAccess") ;
fAcc = (XSimpleFileAccess) UnoRuntime.queryInterface
(XSimpleFileAccess.class, oFAcc) ;
if (fAcc == null) throw new StatusException
(Status.failed("Can't create SimpleFileAccess service")) ;
if (fAcc.exists(fileURL)) {
log.println("Old file exists and will be deleted");
fAcc.kill(fileURL);
}
} catch (com.sun.star.uno.Exception e) {
log.println("Error accessing file '" + fileURL + "'");
e.printStackTrace(log);
}
try {
PropertyValue[] PrintOptions = new PropertyValue[2];
PropertyValue firstProp = new PropertyValue();
firstProp.Name = "FileName";
log.println("Printing to :"+fileName);
firstProp.Value = fileName;
firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE;
PrintOptions[0] = firstProp;
PrintOptions[1] = new PropertyValue();
PrintOptions[1].Name = "Wait";
PrintOptions[1].Value = new Boolean(true);
oObj.print(PrintOptions);
}
catch (com.sun.star.lang.IllegalArgumentException ex) {
log.println("couldn't print");
ex.printStackTrace(log);
result = false ;
}
try {
boolean fileExists = fAcc.exists(fileURL);
log.println("File "+fileName+" exists = "+fileExists);
if (result) {
result &= fileExists ;
}
} catch (com.sun.star.uno.Exception e) {
log.println("Error while while checking file '" +
fileURL + "': ");
e.printStackTrace(log);
result = false ;
}
tRes.tested("print()", result) ;
} // finish _print
} // finish class _XPrintable