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.awt; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 30 import com.sun.star.awt.TextEvent; 31 import com.sun.star.awt.XTextListener; 32 33 /** 34 * Testing <code>com.sun.star.awt.XTextListener</code> 35 * interface methods: 36 * <ul> 37 * <li><code> textChanged() </code></li> 38 * </ul><p> 39 * 40 * This test needs the following object relations : 41 * <ul> 42 * <li> <code>'TestTextListener'</code> 43 * (of type <code>ifc.awt._XTextListener.TestTextListener</code>): 44 * this listener implementation must be registered for object tested for 45 * checking 46 * <code>textChanged()</code> method call. The listener must be registered 47 * in object environment creation because it's not a fact that tested 48 * component supports <code>XTextComponent</code> interface and the listener 49 * can be registered in another object.</li> 50 * <ul> <p> 51 * 52 * @see com.sun.star.awt.XTextListener 53 */ 54 public class _XTextListener extends MultiMethodTest { 55 public XTextListener oObj = null; 56 57 /** 58 * Listener implementation which sets flags on appropriate method calls 59 * and stores event passed. 60 */ 61 public static class TestTextListener implements 62 com.sun.star.awt.XTextListener { 63 public boolean textChangedCalled = false ; 64 public TextEvent event = null ; 65 textChanged(TextEvent e)66 public void textChanged(TextEvent e) { 67 textChangedCalled = true ; 68 event = e ; 69 } 70 disposing(com.sun.star.lang.EventObject e)71 public void disposing(com.sun.star.lang.EventObject e) {} 72 73 } 74 75 TestTextListener textListener = null; 76 /** 77 * Retrieves object relation. 78 * @throws StatusException If the relation not found. 79 */ before()80 public void before() { 81 textListener = (TestTextListener) 82 tEnv.getObjRelation("TestTextListener"); 83 if (textListener == null) { 84 throw new StatusException(Status.failed("Relation not found")); 85 } 86 } 87 88 /** 89 * First a <code>TextEvent</code> object created and 90 * it is passed to <code>textChanged</code> method 91 * call. Then a short wait follows for listener already 92 * registered at the object to be called. <p> 93 * Has <b> OK </b> status if the listener was called with 94 * the same <code>TextEvent</code> object as was created 95 * before. 96 */ _textChanged()97 public void _textChanged() { 98 99 boolean result = true ; 100 101 TextEvent event = new TextEvent() ; 102 event.dummy1 = 2; 103 oObj.textChanged(event); 104 105 try { 106 Thread.sleep(200) ; 107 } catch (InterruptedException e) {} 108 109 result = textListener.textChangedCalled && 110 textListener.event.dummy1 == 2; 111 112 tRes.tested("textChanged()", result) ; 113 } 114 115 /** 116 * Forces environment recreation. 117 */ after()118 protected void after() { 119 disposeEnvironment(); 120 } 121 122 123 } 124 125