bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XMailMergeBroadcaster.java
blob679266d915aba824a1a025228c0ad94a53d6ec8a
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 .
19 package ifc.text;
21 import lib.MultiMethodTest;
22 import lib.Status;
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;
31 /**
32 * Testing <code>com.sun.star.text.XMailMergeBroadcaster</code>
33 * interface methods:
34 * <ul>
35 * <li><code> addMailMergeEventListener() </code></li>
36 * <li><code> removeMailMergeEventListener() </code></li>
37 * </ul><p>
38 * This test needs the following object relations :
39 * <ul>
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>
44 * </ul> <p>
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;
54 /**
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");
60 changed = true;
64 protected XMailMergeListener listener = new MyMailMergeEventListener();
66 /**
67 * Tries to query the tested component for object relation
68 * <code>executeArgs</code> [<code>NamedValue</code>] and <code>Job</code>
69 * [<code>XJob</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") ;
78 if (Job == null)
79 throw new StatusException(Status.failed
80 ("'Job' relation not found ")) ;
83 /**
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");
95 try {
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)) ;
105 shortWait();
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()");
117 changed = false;
119 oObj.removeMailMergeEventListener( listener );
121 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs");
122 XJob Job = (XJob) tEnv.getObjRelation("Job");
124 try {
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)) ;
134 shortWait();
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() {
144 try {
145 Thread.sleep(200) ;
146 } catch (InterruptedException e) {
147 log.println("While waiting :" + e) ;
152 } // finished class _XMailMergeBroadcaster