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 .
20 import com
.sun
.star
.beans
.PropertyValue
;
21 import com
.sun
.star
.uno
.UnoRuntime
;
22 import com
.sun
.star
.view
.PrintJobEvent
;
23 import com
.sun
.star
.view
.XPrintJobBroadcaster
;
24 import com
.sun
.star
.view
.XPrintJobListener
;
25 import com
.sun
.star
.view
.XPrintable
;
27 import lib
.MultiMethodTest
;
29 import lib
.StatusException
;
32 * Test the XPrintJobBroadcaster interface
34 public class _XPrintJobBroadcaster
extends MultiMethodTest
{
35 public XPrintJobBroadcaster oObj
= null;
36 MyPrintJobListener listenerImpl
= null;
39 * Get an object implementation of the _XPrintJobListener interface from the
42 public void before() {
43 listenerImpl
= (MyPrintJobListener
)tEnv
.getObjRelation("XPrintJobBroadcaster.XPrintJobListener");
44 if (listenerImpl
== null) {
45 throw new StatusException(Status
.failed(" No test possible. The XPrintJobListener interface has to be implemented."));
50 * add the listener, see if it's called.
52 public void _addPrintJobListener() {
53 oObj
.addPrintJobListener(listenerImpl
);
54 listenerImpl
.fireEvent();
55 util
.utils
.shortWait(1000);
56 tRes
.tested("addPrintJobListener()", listenerImpl
.actionTriggered());
60 * remove the listener, see if it's still caleed.
62 public void _removePrintJobListener() {
63 requiredMethod("addPrintJobListener");
64 oObj
.removePrintJobListener(listenerImpl
);
66 util
.utils
.shortWait(5000);
69 listenerImpl
.fireEvent();
70 tRes
.tested("removePrintJobListener()", !listenerImpl
.actionTriggered());
74 * Implementation for testing the XPrintJobBroadcaster interface:
77 public static class MyPrintJobListener
implements XPrintJobListener
{
78 boolean eventCalled
= false;
79 // object to trigger the event
80 XPrintable xPrintable
= null;
81 PropertyValue
[]printProps
= null;
82 String printFileName
= null;
86 * @param printable An object that can be cast to an XPrintable.
88 public MyPrintJobListener(Object printable
, String printFileName
) {
89 this.printFileName
= printFileName
;
90 xPrintable
= UnoRuntime
.queryInterface(XPrintable
.class, printable
);
91 printProps
= new PropertyValue
[2];
92 printProps
[0] = new PropertyValue();
93 printProps
[0].Name
= "FileName";
94 printProps
[0].Value
= printFileName
;
95 printProps
[0].State
= com
.sun
.star
.beans
.PropertyState
.DEFAULT_VALUE
;
96 printProps
[1] = new PropertyValue();
97 printProps
[1].Name
= "Wait";
98 printProps
[1].Value
= new Boolean(true);
102 * Has the action been triggered?
103 * @return True if "printJobEvent" has been called.
105 public boolean actionTriggered() {
110 * Fire the event that calls the printJobEvent
112 public void fireEvent() {
114 xPrintable
.print(printProps
);
116 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
120 public void reset() {
121 File f
= new File(printFileName
);
128 * The print job event: has to be called when the action is triggered.
130 public void printJobEvent(PrintJobEvent printJobEvent
) {
135 * Disposing event: ignore.
137 public void disposing(com
.sun
.star
.lang
.EventObject eventObject
) {