1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.text; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 30 import com.sun.star.beans.NamedValue; 31 import com.sun.star.task.XJob; 32 import com.sun.star.text.MailMergeEvent; 33 import com.sun.star.text.XMailMergeBroadcaster; 34 import com.sun.star.text.XMailMergeListener; 35 36 /** 37 * Testing <code>com.sun.star.text.XMailMergeBroadcaster</code> 38 * interface methods: 39 * <ul> 40 * <li><code> addMailMergeEventListener() </code></li> 41 * <li><code> removeMailMergeEventListener() </code></li> 42 * </ul><p> 43 * This test needs the following object relations : 44 * <ul> 45 * <li> <code>'Job'</code> (of type <code>XJob</code>): 46 * used to fire MailMergeEvent</li> 47 * <li> <code>'executeArgs'</code> (of type <code>NamedValue[]</code>): 48 * used as parameter for <code>'Job'</code> </li> 49 * </ul> <p> 50 * 51 * Test is <b> NOT </b> multithread compilant. <p> 52 * @see com.sun.star.text.XMailMergeBroadcaster 53 */ 54 public class _XMailMergeBroadcaster extends MultiMethodTest { 55 public static XMailMergeBroadcaster oObj = null; 56 protected boolean changed = false; 57 58 59 /** 60 * Class we need to test methods 61 */ 62 protected class MyMailMergeEventListener implements XMailMergeListener { notifyMailMergeEvent( MailMergeEvent oEvent )63 public void notifyMailMergeEvent ( MailMergeEvent oEvent ) { 64 System.out.println("Listener called"); 65 changed = true; 66 } 67 } 68 69 protected XMailMergeListener listener = new MyMailMergeEventListener(); 70 71 /** 72 * Tries to query the tested component for object relation 73 * <code>executeArgs</code> [<code>NamedValue</code>] and <code>Job</code> 74 * [<code>XJob</code>] 75 * @throw StatusException If relations are not found 76 */ before()77 public void before() { 78 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs") ; 79 if (executeArgs == null) 80 throw new StatusException(Status.failed 81 ("'executeArgs' relation not found ")) ; 82 XJob Job = (XJob) tEnv.getObjRelation("Job") ; 83 if (Job == null) 84 throw new StatusException(Status.failed 85 ("'Job' relation not found ")) ; 86 } 87 88 /** 89 * Test executes mail merge process<p> 90 * Has <b> OK </b> status if listener was called 91 */ _addMailMergeEventListener()92 public void _addMailMergeEventListener() { 93 log.println("Testing addMailMergeEventListener ..."); 94 95 oObj.addMailMergeEventListener( listener ); 96 97 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs"); 98 XJob Job = (XJob) tEnv.getObjRelation("Job"); 99 100 try { 101 Job.execute(executeArgs); 102 } catch ( com.sun.star.lang.IllegalArgumentException e) { 103 throw new StatusException(Status.failed 104 ("'could not fire event: " + e)) ; 105 } catch ( com.sun.star.uno.Exception e) { 106 throw new StatusException(Status.failed 107 ("'could not fire event: " + e)) ; 108 } 109 110 shortWait(); 111 112 tRes.tested("addMailMergeEventListener()", changed); 113 } 114 115 /** 116 * Test executes mail merge process<p> 117 * Has <b> OK </b> status if listener was not called 118 */ _removeMailMergeEventListener()119 public void _removeMailMergeEventListener() { 120 log.println("Testing removeMailMergeEventListener ..."); 121 requiredMethod("addMailMergeEventListener()"); 122 changed = false; 123 124 oObj.removeMailMergeEventListener( listener ); 125 126 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs"); 127 XJob Job = (XJob) tEnv.getObjRelation("Job"); 128 129 try { 130 Job.execute(executeArgs); 131 } catch ( com.sun.star.lang.IllegalArgumentException e) { 132 throw new StatusException(Status.failed 133 ("'could not fire event: " + e)) ; 134 } catch ( com.sun.star.uno.Exception e) { 135 throw new StatusException(Status.failed 136 ("'could not fire event: " + e)) ; 137 } 138 139 shortWait(); 140 141 tRes.tested("removeMailMergeEventListener()", !changed); 142 } 143 144 /** 145 * Sleeps for 0.2 sec. to allow StarOffice to react on <code> 146 * execute</code> call. 147 */ shortWait()148 private void shortWait() { 149 try { 150 Thread.sleep(200) ; 151 } catch (InterruptedException e) { 152 log.println("While waiting :" + e) ; 153 } 154 } 155 156 157 } // finished class _XMailMergeBroadcaster 158 159