1 26 27 package net.sourceforge.groboutils.uicapture.v1; 28 29 import java.awt.Robot ; 30 import java.awt.Frame ; 31 import java.awt.Rectangle ; 32 import java.awt.Color ; 33 import java.awt.Graphics2D ; 34 import java.awt.image.BufferedImage ; 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 49 public class VirtualWindowUIUTest extends TestCase 50 { 51 54 private static final Class THIS_CLASS = VirtualWindowUIUTest.class; 55 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 56 57 public VirtualWindowUIUTest( String name ) 58 { 59 super( name ); 60 } 61 62 63 64 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 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 172 173 174 175 176 179 private Frame f; 180 private VirtualWindowUI innervwui; 181 182 protected VirtualWindowUI createVWUI() 183 { 184 if (this.f == null) 185 { 186 this.f = new Frame ( "Test" ); 187 } 189 VirtualWindowUI vwui = new VirtualWindowUI( f ); 190 this.innervwui = vwui; 191 return vwui; 192 } 193 194 195 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 [] args ) 207 { 208 String [] name = { THIS_CLASS.getName() }; 209 210 213 junit.textui.TestRunner.main( name ); 214 } 215 216 220 protected void setUp() throws Exception 221 { 222 super.setUp(); 223 224 } 226 227 228 232 protected void tearDown() throws Exception 233 { 234 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 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 |