KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > uicapture > v1 > VirtualWindowUTest


1 /*
2  * @(#)VirtualWindowUTest.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.uicapture.v1;
28
29 import java.awt.Robot JavaDoc;
30
31 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
32 import junit.framework.Test;
33 import junit.framework.TestCase;
34 import junit.framework.TestSuite;
35
36 import net.sourceforge.groboutils.uicapture.v1.event.*;
37 import java.awt.*;
38 import java.awt.event.*;
39 import java.util.*;
40
41
42
43 /**
44  * Tests the VirtualWindow class.
45  *
46  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
47  * @version $Date: 2003/02/10 22:52:34 $
48  * @since Jan 6, 2002
49  */

50 public class VirtualWindowUTest extends TestCase
51 {
52     //-------------------------------------------------------------------------
53
// Standard JUnit Class-specific declarations
54

55     private static final Class JavaDoc THIS_CLASS = VirtualWindowUTest.class;
56     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
57     
58     public VirtualWindowUTest( String JavaDoc name )
59     {
60         super( name );
61     }
62
63     
64     private VirtualWindow vw;
65     
66     
67     public class MyCaptureListener implements ICaptureListener
68     {
69         ArrayList mwm = new ArrayList();
70         ArrayList mm = new ArrayList();
71         ArrayList mp = new ArrayList();
72         ArrayList mr = new ArrayList();
73         ArrayList kp = new ArrayList();
74         ArrayList kr = new ArrayList();
75         
76         public void mouseWheelMoved( MouseWheelCaptureEvent ce )
77         { mwm.add( ce ); }
78         
79         public void mouseMoved( MouseMovedCaptureEvent ce )
80         { mm.add( ce ); }
81         
82         public void mousePressed( MousePressedCaptureEvent ce )
83         { mp.add( ce ); }
84         
85         public void mouseReleased( MouseReleasedCaptureEvent ce )
86         { mr.add( ce ); }
87         
88         public void keyPressed( KeyPressedCaptureEvent ce )
89         { kp.add( ce ); }
90         
91         public void keyReleased( KeyReleasedCaptureEvent ce )
92         { kr.add( ce ); }
93     }
94     
95     
96
97     //-------------------------------------------------------------------------
98
// Tests
99

100     public void testInstantiation1()
101     {
102         this.vw = createVirtualWindow();
103         assertTrue(
104             "Default glass pane state is true.",
105             this.vw.isGlassEnabled() );
106     }
107     
108     
109     public void testInstantiation2()
110     {
111         this.vw = createVirtualWindow( null, true );
112         assertTrue(
113             "Manually set glass pane state to true.",
114             this.vw.isGlassEnabled() );
115     }
116     
117     
118     public void testInstantiation3()
119     {
120         this.vw = createVirtualWindow( null, false );
121         assertTrue(
122             "Manually set glass pane state to false.",
123             !this.vw.isGlassEnabled() );
124     }
125     
126     
127     public void testMouseWheelMoved1()
128     {
129         this.vw = createVirtualWindow();
130         MyCaptureListener mcl1 = createCaptureListener();
131         MyCaptureListener mcl2 = createCaptureListener();
132         this.vw.addCaptureListener( mcl1 );
133         this.vw.addCaptureListener( mcl2 );
134         
135         MouseWheelEvent mwe = new MouseWheelEvent( getUIComponent(),
136             1, System.currentTimeMillis(), 0, 0, 0, 2, false,
137             MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, 1 );
138         this.vw.mouseWheelMoved( mwe );
139         
140         assertEquals( "Did not fire a wheel event to listener 1.",
141             1,
142             mcl1.mwm.size() );
143         assertEquals( "Did not fire a wheel event to listener 2.",
144             1,
145             mcl2.mwm.size() );
146     }
147     
148     
149     public void testMouseDragged1()
150     {
151         this.vw = createVirtualWindow();
152         MyCaptureListener mcl1 = createCaptureListener();
153         MyCaptureListener mcl2 = createCaptureListener();
154         this.vw.addCaptureListener( mcl1 );
155         this.vw.addCaptureListener( mcl2 );
156         
157         MouseEvent me = new MouseEvent( getUIComponent(),
158             1, System.currentTimeMillis(), 0, 0, 0,
159             0, // click count
160
false, 0 );
161         this.vw.mouseDragged( me );
162     }
163     
164     
165     public void testMouseMoved1()
166     {
167         this.vw = createVirtualWindow();
168         MyCaptureListener mcl1 = createCaptureListener();
169         MyCaptureListener mcl2 = createCaptureListener();
170         this.vw.addCaptureListener( mcl1 );
171         this.vw.addCaptureListener( mcl2 );
172         
173         MouseEvent me = new MouseEvent( getUIComponent(),
174             1, System.currentTimeMillis(), 0, 0, 0,
175             0, // click count
176
false, 0 );
177         this.vw.mouseMoved( me );
178         
179         assertEquals( "Did not fire a move event to listener 1.",
180             1,
181             mcl1.mm.size() );
182         assertEquals( "Did not fire a move event to listener 2.",
183             1,
184             mcl2.mm.size() );
185     }
186     
187     
188     public void testMousePressed1()
189     {
190         this.vw = createVirtualWindow();
191         MyCaptureListener mcl1 = createCaptureListener();
192         MyCaptureListener mcl2 = createCaptureListener();
193         this.vw.addCaptureListener( mcl1 );
194         this.vw.addCaptureListener( mcl2 );
195         
196         MouseEvent me = new MouseEvent( getUIComponent(),
197             1, System.currentTimeMillis(), 0, 0, 0,
198             1, // click count
199
false, 0 );
200         this.vw.mousePressed( me );
201         
202         assertEquals( "Did not fire a mouse press event to listener 1.",
203             1,
204             mcl1.mp.size() );
205         assertEquals( "Did not fire a mouse press event to listener 2.",
206             1,
207             mcl2.mp.size() );
208     }
209     
210     
211     public void testMouseReleased1()
212     {
213         this.vw = createVirtualWindow();
214         MyCaptureListener mcl1 = createCaptureListener();
215         MyCaptureListener mcl2 = createCaptureListener();
216         this.vw.addCaptureListener( mcl1 );
217         this.vw.addCaptureListener( mcl2 );
218         
219         MouseEvent me = new MouseEvent( getUIComponent(),
220             1, System.currentTimeMillis(), 0, 0, 0,
221             0, // click count
222
false, 0 );
223         this.vw.mouseReleased( me );
224         
225         assertEquals( "Did not fire a mouse release event to listener 1.",
226             1,
227             mcl1.mr.size() );
228         assertEquals( "Did not fire a mouse release event to listener 2.",
229             1,
230             mcl2.mr.size() );
231     }
232     
233     
234     public void testKeyPressed1()
235     {
236         this.vw = createVirtualWindow();
237         MyCaptureListener mcl1 = createCaptureListener();
238         MyCaptureListener mcl2 = createCaptureListener();
239         this.vw.addCaptureListener( mcl1 );
240         this.vw.addCaptureListener( mcl2 );
241         
242         KeyEvent ke = new KeyEvent( getUIComponent(),
243             1, System.currentTimeMillis(), 0, KeyEvent.VK_A, 'a', 0 );
244         this.vw.keyPressed( ke );
245         
246         assertEquals( "Did not fire a key press event to listener 1.",
247             1,
248             mcl1.kp.size() );
249         assertEquals( "Did not fire a key press event to listener 2.",
250             1,
251             mcl2.kp.size() );
252     }
253     
254     
255     public void testKeyReleased1()
256     {
257         this.vw = createVirtualWindow();
258         MyCaptureListener mcl1 = createCaptureListener();
259         MyCaptureListener mcl2 = createCaptureListener();
260         this.vw.addCaptureListener( mcl1 );
261         this.vw.addCaptureListener( mcl2 );
262         
263         KeyEvent ke = new KeyEvent( getUIComponent(),
264             1, System.currentTimeMillis(), 0, KeyEvent.VK_A, 'a', 0 );
265         this.vw.keyReleased( ke );
266         
267         assertEquals( "Did not fire a key release event to listener 1.",
268             1,
269             mcl1.kr.size() );
270         assertEquals( "Did not fire a key release event to listener 2.",
271             1,
272             mcl2.kr.size() );
273     }
274     
275     
276     
277     
278     //-------------------------------------------------------------------------
279

280     
281     protected VirtualWindow createVirtualWindow()
282     {
283         try
284         {
285             return new VirtualWindow();
286         }
287         catch (java.awt.AWTException JavaDoc ae)
288         {
289             fail( "JDK implementation does not support low-level Robot "+
290                 "actions: "+ae );
291             // unreachable
292
return null;
293         }
294     }
295     
296     
297     protected VirtualWindow createVirtualWindow( String JavaDoc title, boolean enable )
298     {
299         try
300         {
301             return new VirtualWindow( title, enable );
302         }
303         catch (java.awt.AWTException JavaDoc ae)
304         {
305             fail( "JDK implementation does not support low-level Robot "+
306                 "actions: "+ae );
307             // unreachable
308
return null;
309         }
310     }
311     
312     
313     protected Component getUIComponent()
314     {
315         return this.vw.getWindow();
316     }
317     
318     
319     protected MyCaptureListener createCaptureListener()
320     {
321         return new MyCaptureListener();
322     }
323     
324     
325     
326     
327     //-------------------------------------------------------------------------
328
// Standard JUnit declarations
329

330     
331     public static Test suite()
332     {
333         TestSuite suite = new TestSuite( THIS_CLASS );
334         
335         return suite;
336     }
337     
338     public static void main( String JavaDoc[] args )
339     {
340         String JavaDoc[] name = { THIS_CLASS.getName() };
341         
342         // junit.textui.TestRunner.main( name );
343
// junit.swingui.TestRunner.main( name );
344

345         junit.textui.TestRunner.main( name );
346     }
347     
348     /**
349      *
350      * @exception Exception thrown under any exceptional condition.
351      */

352     protected void setUp() throws Exception JavaDoc
353     {
354         super.setUp();
355         
356         // set ourself up
357
}
358     
359     
360     /**
361      *
362      * @exception Exception thrown under any exceptional condition.
363      */

364     protected synchronized void tearDown() throws Exception JavaDoc
365     {
366         // tear ourself down
367
if (this.vw != null)
368         {
369             this.vw.dispose();
370             this.vw = null;
371         }
372         
373         super.tearDown();
374     }
375 }
376
377
Popular Tags