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 ************************************************************************/
30 import lib
.MultiMethodTest
;
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
;
41 * Testing <code>com.sun.star.text.XMailMergeBroadcaster</code>
44 * <li><code> addMailMergeEventListener() </code></li>
45 * <li><code> removeMailMergeEventListener() </code></li>
47 * This test needs the following object relations :
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>
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;
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");
73 protected XMailMergeListener listener
= new MyMailMergeEventListener();
76 * Tries to query the tested component for object relation
77 * <code>executeArgs</code> [<code>NamedValue</code>] and <code>Job</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") ;
88 throw new StatusException(Status
.failed
89 ("'Job' relation not found ")) ;
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");
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
)) ;
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()");
128 oObj
.removeMailMergeEventListener( listener
);
130 NamedValue
[] executeArgs
= (NamedValue
[]) tEnv
.getObjRelation("executeArgs");
131 XJob Job
= (XJob
) tEnv
.getObjRelation("Job");
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
)) ;
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() {
155 } catch (InterruptedException e
) {
156 log
.println("While waiting :" + e
) ;
161 } // finished class _XMailMergeBroadcaster