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 package ifc.view; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 27cdf0e10cSrcweir import com.sun.star.view.PrintJobEvent; 28cdf0e10cSrcweir import com.sun.star.view.XPrintJobBroadcaster; 29cdf0e10cSrcweir import com.sun.star.view.XPrintJobListener; 30cdf0e10cSrcweir import com.sun.star.view.XPrintable; 31cdf0e10cSrcweir import java.io.File; 32cdf0e10cSrcweir import lib.MultiMethodTest; 33cdf0e10cSrcweir import lib.Status; 34cdf0e10cSrcweir import lib.StatusException; 35cdf0e10cSrcweir 36cdf0e10cSrcweir /** 37cdf0e10cSrcweir * Test the XPrintJobBroadcaster interface 38cdf0e10cSrcweir */ 39cdf0e10cSrcweir public class _XPrintJobBroadcaster extends MultiMethodTest { 40cdf0e10cSrcweir public XPrintJobBroadcaster oObj = null; 41cdf0e10cSrcweir MyPrintJobListener listenerImpl = null; 42cdf0e10cSrcweir 43cdf0e10cSrcweir /** 44cdf0e10cSrcweir * Get an object implementation of the _XPrintJobListener interface from the 45cdf0e10cSrcweir * test environment. 46cdf0e10cSrcweir */ 47cdf0e10cSrcweir public void before() { 48cdf0e10cSrcweir listenerImpl = (MyPrintJobListener)tEnv.getObjRelation("XPrintJobBroadcaster.XPrintJobListener"); 49cdf0e10cSrcweir if (listenerImpl == null) { 50cdf0e10cSrcweir throw new StatusException(Status.failed(" No test possible. The XPrintJobListener interface has to be implemented.")); 51cdf0e10cSrcweir } 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** 55cdf0e10cSrcweir * add the listener, see if it's called. 56cdf0e10cSrcweir */ 57cdf0e10cSrcweir public void _addPrintJobListener() { 58cdf0e10cSrcweir oObj.addPrintJobListener(listenerImpl); 59cdf0e10cSrcweir listenerImpl.fireEvent(); 60cdf0e10cSrcweir util.utils.shortWait(1000); 61cdf0e10cSrcweir tRes.tested("addPrintJobListener()", listenerImpl.actionTriggered()); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir /** 65cdf0e10cSrcweir * remove the listener, see if it's still caleed. 66cdf0e10cSrcweir */ 67cdf0e10cSrcweir public void _removePrintJobListener() { 68cdf0e10cSrcweir requiredMethod("addPrintJobListener"); 69cdf0e10cSrcweir oObj.removePrintJobListener(listenerImpl); 70cdf0e10cSrcweir 71cdf0e10cSrcweir util.utils.shortWait(5000); 72cdf0e10cSrcweir 73cdf0e10cSrcweir listenerImpl.reset(); 74cdf0e10cSrcweir listenerImpl.fireEvent(); 75cdf0e10cSrcweir tRes.tested("removePrintJobListener()", !listenerImpl.actionTriggered()); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir /** 79cdf0e10cSrcweir * Implementation for testing the XPrintJobBroadcaster interface: 80cdf0e10cSrcweir * a listener to add. 81cdf0e10cSrcweir */ 82cdf0e10cSrcweir public static class MyPrintJobListener implements XPrintJobListener { 83cdf0e10cSrcweir boolean eventCalled = false; 84cdf0e10cSrcweir // object to trigger the event 85cdf0e10cSrcweir XPrintable xPrintable = null; 86cdf0e10cSrcweir PropertyValue[]printProps = null; 87cdf0e10cSrcweir String printFileName = null; 88cdf0e10cSrcweir 89cdf0e10cSrcweir /** 90cdf0e10cSrcweir * Constructor 91cdf0e10cSrcweir * @param An object that can be cast to an XPrintable. 92cdf0e10cSrcweir */ 93cdf0e10cSrcweir public MyPrintJobListener(Object printable, String printFileName) { 94cdf0e10cSrcweir this.printFileName = printFileName; 95cdf0e10cSrcweir xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, printable); 96cdf0e10cSrcweir printProps = new PropertyValue[2]; 97cdf0e10cSrcweir printProps[0] = new PropertyValue(); 98cdf0e10cSrcweir printProps[0].Name = "FileName"; 99cdf0e10cSrcweir printProps[0].Value = printFileName; 100cdf0e10cSrcweir printProps[0].State = com.sun.star.beans.PropertyState.DEFAULT_VALUE; 101cdf0e10cSrcweir printProps[1] = new PropertyValue(); 102cdf0e10cSrcweir printProps[1].Name = "Wait"; 103cdf0e10cSrcweir printProps[1].Value = new Boolean(true); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir /** 107cdf0e10cSrcweir * Has the action been triggered? 108cdf0e10cSrcweir * @return True if "printJobEvent" has been called. 109cdf0e10cSrcweir */ 110cdf0e10cSrcweir public boolean actionTriggered() { 111cdf0e10cSrcweir return eventCalled; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir /** 115cdf0e10cSrcweir * Fire the event that calls the printJobEvent 116cdf0e10cSrcweir */ 117cdf0e10cSrcweir public void fireEvent() { 118cdf0e10cSrcweir try { 119cdf0e10cSrcweir xPrintable.print(printProps); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir public void reset() { 126cdf0e10cSrcweir File f = new File(printFileName); 127cdf0e10cSrcweir if (f.exists()) 128cdf0e10cSrcweir f.delete(); 129cdf0e10cSrcweir eventCalled = false; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir /** 133cdf0e10cSrcweir * The print job event: has to be called when the action is triggered. 134cdf0e10cSrcweir */ 135cdf0e10cSrcweir public void printJobEvent(PrintJobEvent printJobEvent) { 136cdf0e10cSrcweir eventCalled = true; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir /** 140cdf0e10cSrcweir * Disposing event: ignore. 141cdf0e10cSrcweir */ 142cdf0e10cSrcweir public void disposing(com.sun.star.lang.EventObject eventObject) { 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir } 147