Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / text / _XMailMergeBroadcaster.java
blobd45fb02c00db8aa0c86e335ab6e1078de7be7896
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XMailMergeBroadcaster.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.text;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
37 import com.sun.star.beans.NamedValue;
38 import com.sun.star.task.XJob;
39 import com.sun.star.text.MailMergeEvent;
40 import com.sun.star.text.XMailMergeBroadcaster;
41 import com.sun.star.text.XMailMergeListener;
43 /**
44 * Testing <code>com.sun.star.text.XMailMergeBroadcaster</code>
45 * interface methods:
46 * <ul>
47 * <li><code> addMailMergeEventListener() </code></li>
48 * <li><code> removeMailMergeEventListener() </code></li>
49 * </ul><p>
50 * This test needs the following object relations :
51 * <ul>
52 * <li> <code>'Job'</code> (of type <code>XJob</code>):
53 * used to fire MailMergeEvent</li>
54 * <li> <code>'executeArgs'</code> (of type <code>NamedValue[]</code>):
55 * used as parameter for <code>'Job'</code> </li>
56 * </ul> <p>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * @see com.sun.star.text.XMailMergeBroadcaster
61 public class _XMailMergeBroadcaster extends MultiMethodTest {
62 public static XMailMergeBroadcaster oObj = null;
63 protected boolean changed = false;
66 /**
67 * Class we need to test methods
69 protected class MyMailMergeEventListener implements XMailMergeListener {
70 public void notifyMailMergeEvent ( MailMergeEvent oEvent ) {
71 System.out.println("Listener called");
72 changed = true;
76 protected XMailMergeListener listener = new MyMailMergeEventListener();
78 /**
79 * Tries to query the tested component for object relation
80 * <code>executeArgs</code> [<code>NamedValue</code>] and <code>Job</code>
81 * [<code>XJob</code>]
82 * @throw StatusException If relations are not found
84 public void before() {
85 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs") ;
86 if (executeArgs == null)
87 throw new StatusException(Status.failed
88 ("'executeArgs' relation not found ")) ;
89 XJob Job = (XJob) tEnv.getObjRelation("Job") ;
90 if (Job == null)
91 throw new StatusException(Status.failed
92 ("'Job' relation not found ")) ;
95 /**
96 * Test executes mail merge process<p>
97 * Has <b> OK </b> status if listener was called
99 public void _addMailMergeEventListener() {
100 log.println("Testing addMailMergeEventListener ...");
102 oObj.addMailMergeEventListener( listener );
104 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs");
105 XJob Job = (XJob) tEnv.getObjRelation("Job");
107 try {
108 Job.execute(executeArgs);
109 } catch ( com.sun.star.lang.IllegalArgumentException e) {
110 throw new StatusException(Status.failed
111 ("'could not fire event: " + e)) ;
112 } catch ( com.sun.star.uno.Exception e) {
113 throw new StatusException(Status.failed
114 ("'could not fire event: " + e)) ;
117 shortWait();
119 tRes.tested("addMailMergeEventListener()", changed);
123 * Test executes mail merge process<p>
124 * Has <b> OK </b> status if listener was not called
126 public void _removeMailMergeEventListener() {
127 log.println("Testing removeMailMergeEventListener ...");
128 requiredMethod("addMailMergeEventListener()");
129 changed = false;
131 oObj.removeMailMergeEventListener( listener );
133 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs");
134 XJob Job = (XJob) tEnv.getObjRelation("Job");
136 try {
137 Job.execute(executeArgs);
138 } catch ( com.sun.star.lang.IllegalArgumentException e) {
139 throw new StatusException(Status.failed
140 ("'could not fire event: " + e)) ;
141 } catch ( com.sun.star.uno.Exception e) {
142 throw new StatusException(Status.failed
143 ("'could not fire event: " + e)) ;
146 shortWait();
148 tRes.tested("removeMailMergeEventListener()", !changed);
152 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
153 * execute</code> call.
155 private void shortWait() {
156 try {
157 Thread.sleep(200) ;
158 } catch (InterruptedException e) {
159 log.println("While waiting :" + e) ;
164 } // finished class _XMailMergeBroadcaster