Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XMailMergeBroadcaster.java
blob07908c2ed628548f1fe0e99bd3134151bc3ba1ba
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.text;
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import lib.StatusException;
34 import com.sun.star.beans.NamedValue;
35 import com.sun.star.task.XJob;
36 import com.sun.star.text.MailMergeEvent;
37 import com.sun.star.text.XMailMergeBroadcaster;
38 import com.sun.star.text.XMailMergeListener;
40 /**
41 * Testing <code>com.sun.star.text.XMailMergeBroadcaster</code>
42 * interface methods:
43 * <ul>
44 * <li><code> addMailMergeEventListener() </code></li>
45 * <li><code> removeMailMergeEventListener() </code></li>
46 * </ul><p>
47 * This test needs the following object relations :
48 * <ul>
49 * <li> <code>'Job'</code> (of type <code>XJob</code>):
50 * used to fire MailMergeEvent</li>
51 * <li> <code>'executeArgs'</code> (of type <code>NamedValue[]</code>):
52 * used as parameter for <code>'Job'</code> </li>
53 * </ul> <p>
55 * Test is <b> NOT </b> multithread compilant. <p>
56 * @see com.sun.star.text.XMailMergeBroadcaster
58 public class _XMailMergeBroadcaster extends MultiMethodTest {
59 public static XMailMergeBroadcaster oObj = null;
60 protected boolean changed = false;
63 /**
64 * Class we need to test methods
66 protected class MyMailMergeEventListener implements XMailMergeListener {
67 public void notifyMailMergeEvent ( MailMergeEvent oEvent ) {
68 System.out.println("Listener called");
69 changed = true;
73 protected XMailMergeListener listener = new MyMailMergeEventListener();
75 /**
76 * Tries to query the tested component for object relation
77 * <code>executeArgs</code> [<code>NamedValue</code>] and <code>Job</code>
78 * [<code>XJob</code>]
79 * @throw StatusException If relations are not found
81 public void before() {
82 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs") ;
83 if (executeArgs == null)
84 throw new StatusException(Status.failed
85 ("'executeArgs' relation not found ")) ;
86 XJob Job = (XJob) tEnv.getObjRelation("Job") ;
87 if (Job == null)
88 throw new StatusException(Status.failed
89 ("'Job' relation not found ")) ;
92 /**
93 * Test executes mail merge process<p>
94 * Has <b> OK </b> status if listener was called
96 public void _addMailMergeEventListener() {
97 log.println("Testing addMailMergeEventListener ...");
99 oObj.addMailMergeEventListener( listener );
101 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs");
102 XJob Job = (XJob) tEnv.getObjRelation("Job");
104 try {
105 Job.execute(executeArgs);
106 } catch ( com.sun.star.lang.IllegalArgumentException e) {
107 throw new StatusException(Status.failed
108 ("'could not fire event: " + e)) ;
109 } catch ( com.sun.star.uno.Exception e) {
110 throw new StatusException(Status.failed
111 ("'could not fire event: " + e)) ;
114 shortWait();
116 tRes.tested("addMailMergeEventListener()", changed);
120 * Test executes mail merge process<p>
121 * Has <b> OK </b> status if listener was not called
123 public void _removeMailMergeEventListener() {
124 log.println("Testing removeMailMergeEventListener ...");
125 requiredMethod("addMailMergeEventListener()");
126 changed = false;
128 oObj.removeMailMergeEventListener( listener );
130 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs");
131 XJob Job = (XJob) tEnv.getObjRelation("Job");
133 try {
134 Job.execute(executeArgs);
135 } catch ( com.sun.star.lang.IllegalArgumentException e) {
136 throw new StatusException(Status.failed
137 ("'could not fire event: " + e)) ;
138 } catch ( com.sun.star.uno.Exception e) {
139 throw new StatusException(Status.failed
140 ("'could not fire event: " + e)) ;
143 shortWait();
145 tRes.tested("removeMailMergeEventListener()", !changed);
149 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
150 * execute</code> call.
152 private void shortWait() {
153 try {
154 Thread.sleep(200) ;
155 } catch (InterruptedException e) {
156 log.println("While waiting :" + e) ;
161 } // finished class _XMailMergeBroadcaster