Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XMailMergeBroadcaster.java
blob5ac586b43013bdad0422e73fdbde8cd442248b6a
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 compliant. <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 @Override
73 public void before() {
74 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs") ;
75 if (executeArgs == null)
76 throw new StatusException(Status.failed
77 ("'executeArgs' relation not found ")) ;
78 XJob Job = (XJob) tEnv.getObjRelation("Job") ;
79 if (Job == null)
80 throw new StatusException(Status.failed
81 ("'Job' relation not found ")) ;
84 /**
85 * Test executes mail merge process<p>
86 * Has <b> OK </b> status if listener was called
88 public void _addMailMergeEventListener() {
89 log.println("Testing addMailMergeEventListener ...");
91 oObj.addMailMergeEventListener( listener );
93 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs");
94 XJob Job = (XJob) tEnv.getObjRelation("Job");
96 try {
97 Job.execute(executeArgs);
98 } catch ( com.sun.star.lang.IllegalArgumentException e) {
99 throw new StatusException(Status.failed
100 ("'could not fire event: " + e)) ;
101 } catch ( com.sun.star.uno.Exception e) {
102 throw new StatusException(Status.failed
103 ("'could not fire event: " + e)) ;
106 tRes.tested("addMailMergeEventListener()", changed);
110 * Test executes mail merge process<p>
111 * Has <b> OK </b> status if listener was not called
113 public void _removeMailMergeEventListener() {
114 log.println("Testing removeMailMergeEventListener ...");
115 requiredMethod("addMailMergeEventListener()");
116 changed = false;
118 oObj.removeMailMergeEventListener( listener );
120 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs");
121 XJob Job = (XJob) tEnv.getObjRelation("Job");
123 try {
124 Job.execute(executeArgs);
125 } catch ( com.sun.star.lang.IllegalArgumentException e) {
126 throw new StatusException(Status.failed
127 ("'could not fire event: " + e)) ;
128 } catch ( com.sun.star.uno.Exception e) {
129 throw new StatusException(Status.failed
130 ("'could not fire event: " + e)) ;
133 waitForEventIdle();
135 tRes.tested("removeMailMergeEventListener()", !changed);
139 } // finished class _XMailMergeBroadcaster