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