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