KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)VirtualWindowUIUTest.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 import java.awt.Frame JavaDoc;
31 import java.awt.Rectangle JavaDoc;
32 import java.awt.Color JavaDoc;
33 import java.awt.Graphics2D JavaDoc;
34 import java.awt.image.BufferedImage JavaDoc;
35
36 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
37 import junit.framework.Test;
38 import junit.framework.TestCase;
39 import junit.framework.TestSuite;
40
41
42 /**
43  * Tests the VirtualWindowUI class.
44  *
45  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
46  * @version $Date: 2003/02/10 22:52:34 $
47  * @since Jan 6, 2002
48  */

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

54     private static final Class JavaDoc THIS_CLASS = VirtualWindowUIUTest.class;
55     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
56     
57     public VirtualWindowUIUTest( String JavaDoc name )
58     {
59         super( name );
60     }
61
62
63
64     //-------------------------------------------------------------------------
65
// Tests
66

67     public void testInstantiation()
68     {
69         VirtualWindowUI vwui = createVWUI();
70         assertTrue(
71             "Default glass pane state is false.",
72             !vwui.isGlassEnabled() );
73     }
74     
75     
76     public void testCoveredScreen()
77     {
78         VirtualWindowUI vwui = createVWUI();
79         Rectangle JavaDoc r = vwui.getCoveredScreen();
80         assertNotNull(
81             "Covered screen should never be null.",
82             r );
83         assertEquals(
84             "X is not 0",
85             0,
86             (int)r.getX() );
87         assertEquals(
88             "Y is not 0",
89             0,
90             (int)r.getY() );
91     }
92     
93     
94     public void testGlass1()
95     {
96         VirtualWindowUI vwui = createVWUI();
97         assertTrue(
98             "Default glass pane state is false.",
99             !vwui.isGlassEnabled() );
100         vwui.show();
101         assertTrue(
102             "Showing UI should set glass pane state to true.",
103             vwui.isGlassEnabled() );
104         vwui.hide();
105         assertTrue(
106             "Hiding UI should set glass pane state to false.",
107             !vwui.isGlassEnabled() );
108     }
109     
110     
111     public void testGlass2()
112     {
113         VirtualWindowUI vwui = createVWUI();
114         assertTrue(
115             "Default glass pane state is false.",
116             !vwui.isGlassEnabled() );
117         vwui.hide();
118         assertTrue(
119             "Hiding UI should set glass pane state to false.",
120             !vwui.isGlassEnabled() );
121         vwui.show();
122         assertTrue(
123             "Showing UI should set glass pane state to true.",
124             vwui.isGlassEnabled() );
125         vwui.show();
126         assertTrue(
127             "Showing UI should set glass pane state to true.",
128             vwui.isGlassEnabled() );
129         vwui.hide();
130         assertTrue(
131             "Hiding UI should set glass pane state to false.",
132             !vwui.isGlassEnabled() );
133         vwui.hide();
134         assertTrue(
135             "Hiding UI should set glass pane state to false.",
136             !vwui.isGlassEnabled() );
137     }
138     
139     
140     /*
141     this test has never worked right.
142     If a screen-saver is running, or the moon is full, then the test will
143     fail.
144     
145     public void testDraw1()
146             throws Exception
147     {
148         Robot r = new Robot();
149         Color p1 = r.getPixelColor( 0, 0 );
150         // set the new UI's background to a color that is opposite of
151         // the current color.
152         Color inverse = new Color( 255 - p1.getRed(), 255 - p1.getGreen(),
153             255 - p1.getBlue() );
154         BufferedImage img = new BufferedImage( 2, 2,
155             BufferedImage.TYPE_3BYTE_BGR );
156         Graphics2D g = img.createGraphics();
157         g.setColor( inverse );
158         g.drawLine( 0, 0, 1, 0 );
159         
160         VirtualWindowUI vwui = createVWUI();
161         vwui.setBackground( img );
162         
163         vwui.show();
164         
165         Color p2 = r.getPixelColor( 0, 0 );
166         assertEquals(
167             "Displayed image was not the same.",
168             inverse,
169             p2 );
170     }
171     */

172     
173     
174
175
176     //-------------------------------------------------------------------------
177
// Helpers
178

179     private Frame JavaDoc f;
180     private VirtualWindowUI innervwui;
181     
182     protected VirtualWindowUI createVWUI()
183     {
184         if (this.f == null)
185         {
186             this.f = new Frame JavaDoc( "Test" );
187             // f.show();
188
}
189         VirtualWindowUI vwui = new VirtualWindowUI( f );
190         this.innervwui = vwui;
191         return vwui;
192     }
193     
194     
195     //-------------------------------------------------------------------------
196
// Standard JUnit declarations
197

198     
199     public static Test suite()
200     {
201         TestSuite suite = new TestSuite( THIS_CLASS );
202         
203         return suite;
204     }
205     
206     public static void main( String JavaDoc[] args )
207     {
208         String JavaDoc[] name = { THIS_CLASS.getName() };
209         
210         // junit.textui.TestRunner.main( name );
211
// junit.swingui.TestRunner.main( name );
212

213         junit.textui.TestRunner.main( name );
214     }
215     
216     /**
217      *
218      * @exception Exception thrown under any exceptional condition.
219      */

220     protected void setUp() throws Exception JavaDoc
221     {
222         super.setUp();
223         
224         // set ourself up
225
}
226     
227     
228     /**
229      *
230      * @exception Exception thrown under any exceptional condition.
231      */

232     protected void tearDown() throws Exception JavaDoc
233     {
234         // tear ourself down
235
if (this.f != null)
236         {
237             this.f.dispose();
238             this.f = null;
239         }
240         if (this.innervwui != null)
241         {
242             try
243             {
244                 this.innervwui.dispose();
245             }
246             catch (Exception JavaDoc e)
247             {
248                 DOC.getLog().info( "VWUI threw an exception during disposal.", e );
249             }
250             this.innervwui = null;
251         }
252         
253         super.tearDown();
254     }
255 }
256
257
Popular Tags