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