1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package ifc.text; 29 30 import lib.MultiMethodTest; 31 import lib.Status; 32 import lib.StatusException; 33 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; 39 40 /** 41 * Testing <code>com.sun.star.text.XMailMergeBroadcaster</code> 42 * interface methods: 43 * <ul> 44 * <li><code> addMailMergeEventListener() </code></li> 45 * <li><code> removeMailMergeEventListener() </code></li> 46 * </ul><p> 47 * This test needs the following object relations : 48 * <ul> 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> 53 * </ul> <p> 54 * 55 * Test is <b> NOT </b> multithread compilant. <p> 56 * @see com.sun.star.text.XMailMergeBroadcaster 57 */ 58 public class _XMailMergeBroadcaster extends MultiMethodTest { 59 public static XMailMergeBroadcaster oObj = null; 60 protected boolean changed = false; 61 62 63 /** 64 * Class we need to test methods 65 */ 66 protected class MyMailMergeEventListener implements XMailMergeListener { 67 public void notifyMailMergeEvent ( MailMergeEvent oEvent ) { 68 System.out.println("Listener called"); 69 changed = true; 70 } 71 } 72 73 protected XMailMergeListener listener = new MyMailMergeEventListener(); 74 75 /** 76 * Tries to query the tested component for object relation 77 * <code>executeArgs</code> [<code>NamedValue</code>] and <code>Job</code> 78 * [<code>XJob</code>] 79 * @throw StatusException If relations are not found 80 */ 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") ; 87 if (Job == null) 88 throw new StatusException(Status.failed 89 ("'Job' relation not found ")) ; 90 } 91 92 /** 93 * Test executes mail merge process<p> 94 * Has <b> OK </b> status if listener was called 95 */ 96 public void _addMailMergeEventListener() { 97 log.println("Testing addMailMergeEventListener ..."); 98 99 oObj.addMailMergeEventListener( listener ); 100 101 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs"); 102 XJob Job = (XJob) tEnv.getObjRelation("Job"); 103 104 try { 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)) ; 112 } 113 114 shortWait(); 115 116 tRes.tested("addMailMergeEventListener()", changed); 117 } 118 119 /** 120 * Test executes mail merge process<p> 121 * Has <b> OK </b> status if listener was not called 122 */ 123 public void _removeMailMergeEventListener() { 124 log.println("Testing removeMailMergeEventListener ..."); 125 requiredMethod("addMailMergeEventListener()"); 126 changed = false; 127 128 oObj.removeMailMergeEventListener( listener ); 129 130 NamedValue[] executeArgs = (NamedValue[]) tEnv.getObjRelation("executeArgs"); 131 XJob Job = (XJob) tEnv.getObjRelation("Job"); 132 133 try { 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)) ; 141 } 142 143 shortWait(); 144 145 tRes.tested("removeMailMergeEventListener()", !changed); 146 } 147 148 /** 149 * Sleeps for 0.2 sec. to allow StarOffice to react on <code> 150 * execute</code> call. 151 */ 152 private void shortWait() { 153 try { 154 Thread.sleep(200) ; 155 } catch (InterruptedException e) { 156 log.println("While waiting :" + e) ; 157 } 158 } 159 160 161 } // finished class _XMailMergeBroadcaster 162 163