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 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.beans
.NamedValue
;
26 import com
.sun
.star
.task
.XJob
;
27 import com
.sun
.star
.text
.MailMergeEvent
;
28 import com
.sun
.star
.text
.XMailMergeBroadcaster
;
29 import com
.sun
.star
.text
.XMailMergeListener
;
32 * Testing <code>com.sun.star.text.XMailMergeBroadcaster</code>
35 * <li><code> addMailMergeEventListener() </code></li>
36 * <li><code> removeMailMergeEventListener() </code></li>
38 * This test needs the following object relations :
40 * <li> <code>'Job'</code> (of type <code>XJob</code>):
41 * used to fire MailMergeEvent</li>
42 * <li> <code>'executeArgs'</code> (of type <code>NamedValue[]</code>):
43 * used as parameter for <code>'Job'</code> </li>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.text.XMailMergeBroadcaster
49 public class _XMailMergeBroadcaster
extends MultiMethodTest
{
50 public static XMailMergeBroadcaster oObj
= null;
51 protected boolean changed
= false;
55 * Class we need to test methods
57 protected class MyMailMergeEventListener
implements XMailMergeListener
{
58 public void notifyMailMergeEvent ( MailMergeEvent oEvent
) {
59 System
.out
.println("Listener called");
64 protected XMailMergeListener listener
= new MyMailMergeEventListener();
67 * Tries to query the tested component for object relation
68 * <code>executeArgs</code> [<code>NamedValue</code>] and <code>Job</code>
70 * @throw StatusException If relations are not found
72 public void before() {
73 NamedValue
[] executeArgs
= (NamedValue
[]) tEnv
.getObjRelation("executeArgs") ;
74 if (executeArgs
== null)
75 throw new StatusException(Status
.failed
76 ("'executeArgs' relation not found ")) ;
77 XJob Job
= (XJob
) tEnv
.getObjRelation("Job") ;
79 throw new StatusException(Status
.failed
80 ("'Job' relation not found ")) ;
84 * Test executes mail merge process<p>
85 * Has <b> OK </b> status if listener was called
87 public void _addMailMergeEventListener() {
88 log
.println("Testing addMailMergeEventListener ...");
90 oObj
.addMailMergeEventListener( listener
);
92 NamedValue
[] executeArgs
= (NamedValue
[]) tEnv
.getObjRelation("executeArgs");
93 XJob Job
= (XJob
) tEnv
.getObjRelation("Job");
96 Job
.execute(executeArgs
);
97 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
98 throw new StatusException(Status
.failed
99 ("'could not fire event: " + e
)) ;
100 } catch ( com
.sun
.star
.uno
.Exception e
) {
101 throw new StatusException(Status
.failed
102 ("'could not fire event: " + e
)) ;
107 tRes
.tested("addMailMergeEventListener()", changed
);
111 * Test executes mail merge process<p>
112 * Has <b> OK </b> status if listener was not called
114 public void _removeMailMergeEventListener() {
115 log
.println("Testing removeMailMergeEventListener ...");
116 requiredMethod("addMailMergeEventListener()");
119 oObj
.removeMailMergeEventListener( listener
);
121 NamedValue
[] executeArgs
= (NamedValue
[]) tEnv
.getObjRelation("executeArgs");
122 XJob Job
= (XJob
) tEnv
.getObjRelation("Job");
125 Job
.execute(executeArgs
);
126 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
127 throw new StatusException(Status
.failed
128 ("'could not fire event: " + e
)) ;
129 } catch ( com
.sun
.star
.uno
.Exception e
) {
130 throw new StatusException(Status
.failed
131 ("'could not fire event: " + e
)) ;
136 tRes
.tested("removeMailMergeEventListener()", !changed
);
140 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
141 * execute</code> call.
143 private void shortWait() {
146 } catch (InterruptedException e
) {
147 log
.println("While waiting :" + e
) ;
152 } // finished class _XMailMergeBroadcaster