tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / view / _XPrintJobBroadcaster.java
blob99d30f9946f0847e64de0b0b670657bef093ae04
1 /*
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 .
18 package ifc.view;
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;
26 import java.io.File;
27 import lib.MultiMethodTest;
28 import lib.Status;
29 import lib.StatusException;
31 /**
32 * Test the XPrintJobBroadcaster interface
34 public class _XPrintJobBroadcaster extends MultiMethodTest {
35 public XPrintJobBroadcaster oObj = null;
36 MyPrintJobListener listenerImpl = null;
38 /**
39 * Get an object implementation of the _XPrintJobListener interface from the
40 * test environment.
42 @Override
43 public void before() {
44 listenerImpl = (MyPrintJobListener)tEnv.getObjRelation("XPrintJobBroadcaster.XPrintJobListener");
45 if (listenerImpl == null) {
46 throw new StatusException(Status.failed(" No test possible. The XPrintJobListener interface has to be implemented."));
50 /**
51 * add the listener, see if it's called.
53 public void _addPrintJobListener() {
54 oObj.addPrintJobListener(listenerImpl);
55 listenerImpl.fireEvent();
56 waitForEventIdle();
57 tRes.tested("addPrintJobListener()", listenerImpl.actionTriggered());
60 /**
61 * remove the listener, see if it's still called.
63 public void _removePrintJobListener() {
64 requiredMethod("addPrintJobListener");
65 oObj.removePrintJobListener(listenerImpl);
67 waitForEventIdle();
69 listenerImpl.reset();
70 listenerImpl.fireEvent();
71 tRes.tested("removePrintJobListener()", !listenerImpl.actionTriggered());
74 /**
75 * Implementation for testing the XPrintJobBroadcaster interface:
76 * a listener to add.
78 public static class MyPrintJobListener implements XPrintJobListener {
79 boolean eventCalled = false;
80 // object to trigger the event
81 XPrintable xPrintable = null;
82 PropertyValue[]printProps = null;
83 String printFileName = null;
85 /**
86 * Constructor
87 * @param printable An object that can be cast to an XPrintable.
89 public MyPrintJobListener(Object printable, String printFileName) {
90 this.printFileName = printFileName;
91 xPrintable = UnoRuntime.queryInterface(XPrintable.class, printable);
92 printProps = new PropertyValue[2];
93 printProps[0] = new PropertyValue();
94 printProps[0].Name = "FileName";
95 printProps[0].Value = printFileName;
96 printProps[0].State = com.sun.star.beans.PropertyState.DEFAULT_VALUE;
97 printProps[1] = new PropertyValue();
98 printProps[1].Name = "Wait";
99 printProps[1].Value = Boolean.TRUE;
103 * Has the action been triggered?
104 * @return True if "printJobEvent" has been called.
106 public boolean actionTriggered() {
107 return eventCalled;
111 * Fire the event that calls the printJobEvent
113 public void fireEvent() {
114 try {
115 xPrintable.print(printProps);
117 catch(com.sun.star.lang.IllegalArgumentException e) {
121 public void reset() {
122 File f = new File(printFileName);
123 if (f.exists()) {
124 boolean bDeleteOk = f.delete();
125 if (!bDeleteOk) {
126 System.out.println("delete failed");
129 eventCalled = false;
133 * The print job event: has to be called when the action is triggered.
135 public void printJobEvent(PrintJobEvent printJobEvent) {
136 eventCalled = true;
140 * Disposing event: ignore.
142 public void disposing(com.sun.star.lang.EventObject eventObject) {