< prev index next >

test/java/awt/Mixing/OpaqueTest.java

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   @test
  26   @bug 4811096
  27   @summary Tests whether opaque and non-opaque components mix correctly
  28   @author anthony.petrov@...: area=awt.mixing
  29   @library ../regtesthelpers
  30   @modules java.desktop/com.sun.awt
  31   @build Util
  32   @run main OpaqueTest
  33 */
  34 
  35 
  36 /**
  37  * OpaqueTest.java
  38  *
  39  * summary:  OpaqueTest
  40  */
  41 
  42 import java.awt.*;
  43 import java.awt.event.*;

  44 import javax.swing.*;
  45 import test.java.awt.regtesthelpers.Util;
  46 import com.sun.awt.AWTUtilities;
  47 
  48 
  49 
  50 public class OpaqueTest
  51 {
  52 
  53     //*** test-writer defined static variables go here ***
  54 
  55     static String testSeq = new String("");
  56     final static String checkSeq = new String("010000101");
  57 
  58     private static void init()
  59     {
  60         //*** Create instructions for the user here ***
  61 
  62         String[] instructions =
  63         {
  64             "This is an AUTOMATIC test, simply wait until it is done.",
  65             "The result (passed or failed) will be shown in the",
  66             "message window below."


 107         f.add(p);
 108         f.setBounds(50, 50, 400, 400);
 109         f.show();
 110 
 111 
 112         Robot robot = Util.createRobot();
 113         robot.setAutoDelay(20);
 114 
 115         Util.waitForIdle(robot);
 116 
 117         // Move the mouse pointer to the position where both
 118         //    buttons overlap
 119         Point heavyLoc = heavy.getLocationOnScreen();
 120         robot.mouseMove(heavyLoc.x + 5, heavyLoc.y + 5);
 121 
 122         // Now perform the click at this point for 9 times
 123         // In the middle of the process toggle the opaque
 124         // flag value.
 125         for (int i = 0; i < 9; ++i) {
 126             if (i == 3) {
 127                 AWTUtilities.setComponentMixingCutoutShape(light,
 128                         new Rectangle());
 129             }
 130             if (i == 6) {
 131                 AWTUtilities.setComponentMixingCutoutShape(light,
 132                         null);
 133             }
 134 
 135             robot.mousePress(InputEvent.BUTTON1_MASK);
 136             robot.mouseRelease(InputEvent.BUTTON1_MASK);
 137             Util.waitForIdle(robot);
 138         }
 139 
 140         Util.waitForIdle(robot);
 141 
 142         // If the buttons are correctly mixed, the test sequence
 143         // is equal to the check sequence.
 144         if (testSeq.equals(checkSeq)) {
 145             OpaqueTest.pass();
 146         } else {
 147             OpaqueTest.fail("The components changed their visible Z-order in a wrong sequence: '" + testSeq + "' instead of '" + checkSeq + "'");
 148         }
 149     }//End  init()
 150 
 151 
 152 


 157      * synchronisation necessary for the test harness.
 158      * By keeping it the same in all tests, it is easier
 159      * to read and understand someone else's test, as
 160      * well as insuring that all tests behave correctly
 161      * with the test harness.
 162      * There is a section following this for test-
 163      * classes
 164      ******************************************************/
 165     private static boolean theTestPassed = false;
 166     private static boolean testGeneratedInterrupt = false;
 167     private static String failureMessage = "";
 168 
 169     private static Thread mainThread = null;
 170 
 171     private static int sleepTime = 300000;
 172 
 173     // Not sure about what happens if multiple of this test are
 174     //  instantiated in the same VM.  Being static (and using
 175     //  static vars), it aint gonna work.  Not worrying about
 176     //  it for now.
 177     public static void main( String args[] ) throws InterruptedException
 178     {




 179         mainThread = Thread.currentThread();
 180         try
 181         {
 182             init();
 183         }
 184         catch( TestPassedException e )
 185         {
 186             //The test passed, so just return from main and harness will
 187             // interepret this return as a pass
 188             return;
 189         }
 190         //At this point, neither test pass nor test fail has been
 191         // called -- either would have thrown an exception and ended the
 192         // test, so we know we have multiple threads.
 193 
 194         //Test involves other threads, so sleep and wait for them to
 195         // called pass() or fail()
 196         try
 197         {
 198             Thread.sleep( sleepTime );
 199             //Timed out, so fail the test
 200             throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
 201         }
 202         catch (InterruptedException e)
 203         {
 204             //The test harness may have interrupted the test.  If so, rethrow the exception
 205             // so that the harness gets it and deals with it.
 206             if( ! testGeneratedInterrupt ) throw e;
 207 
 208             //reset flag in case hit this code more than once for some reason (just safety)
 209             testGeneratedInterrupt = false;
 210 
 211             if ( theTestPassed == false )
 212             {
 213                 throw new RuntimeException( failureMessage );
 214             }
 215         }
 216 
 217     }//main











 218 
 219     public static synchronized void setTimeoutTo( int seconds )
 220     {
 221         sleepTime = seconds * 1000;
 222     }
 223 
 224     public static synchronized void pass()
 225     {
 226         Sysout.println( "The test passed." );
 227         Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
 228         //first check if this is executing in main thread
 229         if ( mainThread == Thread.currentThread() )
 230         {
 231             //Still in the main thread, so set the flag just for kicks,
 232             // and throw a test passed exception which will be caught
 233             // and end the test.
 234             theTestPassed = true;
 235             throw new TestPassedException();
 236         }
 237         theTestPassed = true;




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   @test
  26   @bug 4811096
  27   @summary Tests whether opaque and non-opaque components mix correctly
  28   @author anthony.petrov@...: area=awt.mixing
  29   @library ../regtesthelpers

  30   @build Util
  31   @run main OpaqueTest
  32 */
  33 
  34 
  35 /**
  36  * OpaqueTest.java
  37  *
  38  * summary:  OpaqueTest
  39  */
  40 
  41 import java.awt.*;
  42 import java.awt.event.*;
  43 import java.lang.reflect.Method;
  44 import javax.swing.*;
  45 import test.java.awt.regtesthelpers.Util;

  46 
  47 
  48 
  49 public class OpaqueTest
  50 {
  51 
  52     //*** test-writer defined static variables go here ***
  53 
  54     static String testSeq = new String("");
  55     final static String checkSeq = new String("010000101");
  56 
  57     private static void init()
  58     {
  59         //*** Create instructions for the user here ***
  60 
  61         String[] instructions =
  62         {
  63             "This is an AUTOMATIC test, simply wait until it is done.",
  64             "The result (passed or failed) will be shown in the",
  65             "message window below."


 106         f.add(p);
 107         f.setBounds(50, 50, 400, 400);
 108         f.show();
 109 
 110 
 111         Robot robot = Util.createRobot();
 112         robot.setAutoDelay(20);
 113 
 114         Util.waitForIdle(robot);
 115 
 116         // Move the mouse pointer to the position where both
 117         //    buttons overlap
 118         Point heavyLoc = heavy.getLocationOnScreen();
 119         robot.mouseMove(heavyLoc.x + 5, heavyLoc.y + 5);
 120 
 121         // Now perform the click at this point for 9 times
 122         // In the middle of the process toggle the opaque
 123         // flag value.
 124         for (int i = 0; i < 9; ++i) {
 125             if (i == 3) {
 126                 setMixingCutoutShape(light, new Rectangle());

 127             }
 128             if (i == 6) {
 129                 setMixingCutoutShape(light, null);

 130             }
 131 
 132             robot.mousePress(InputEvent.BUTTON1_MASK);
 133             robot.mouseRelease(InputEvent.BUTTON1_MASK);
 134             Util.waitForIdle(robot);
 135         }
 136 
 137         Util.waitForIdle(robot);
 138 
 139         // If the buttons are correctly mixed, the test sequence
 140         // is equal to the check sequence.
 141         if (testSeq.equals(checkSeq)) {
 142             OpaqueTest.pass();
 143         } else {
 144             OpaqueTest.fail("The components changed their visible Z-order in a wrong sequence: '" + testSeq + "' instead of '" + checkSeq + "'");
 145         }
 146     }//End  init()
 147 
 148 
 149 


 154      * synchronisation necessary for the test harness.
 155      * By keeping it the same in all tests, it is easier
 156      * to read and understand someone else's test, as
 157      * well as insuring that all tests behave correctly
 158      * with the test harness.
 159      * There is a section following this for test-
 160      * classes
 161      ******************************************************/
 162     private static boolean theTestPassed = false;
 163     private static boolean testGeneratedInterrupt = false;
 164     private static String failureMessage = "";
 165 
 166     private static Thread mainThread = null;
 167 
 168     private static int sleepTime = 300000;
 169 
 170     // Not sure about what happens if multiple of this test are
 171     //  instantiated in the same VM.  Being static (and using
 172     //  static vars), it aint gonna work.  Not worrying about
 173     //  it for now.
 174     public static void main( String args[] ) throws Exception
 175     {
 176         setMixingCutoutShapeMethod = Component.class.
 177                 getDeclaredMethod("setMixingCutoutShape", Shape.class);
 178         setMixingCutoutShapeMethod.setAccessible(true);
 179 
 180         mainThread = Thread.currentThread();
 181         try
 182         {
 183             init();
 184         }
 185         catch( TestPassedException e )
 186         {
 187             //The test passed, so just return from main and harness will
 188             // interepret this return as a pass
 189             return;
 190         }
 191         //At this point, neither test pass nor test fail has been
 192         // called -- either would have thrown an exception and ended the
 193         // test, so we know we have multiple threads.
 194 
 195         //Test involves other threads, so sleep and wait for them to
 196         // called pass() or fail()
 197         try
 198         {
 199             Thread.sleep( sleepTime );
 200             //Timed out, so fail the test
 201             throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
 202         }
 203         catch (InterruptedException e)
 204         {
 205             //The test harness may have interrupted the test.  If so, rethrow the exception
 206             // so that the harness gets it and deals with it.
 207             if( ! testGeneratedInterrupt ) throw e;
 208 
 209             //reset flag in case hit this code more than once for some reason (just safety)
 210             testGeneratedInterrupt = false;
 211 
 212             if ( theTestPassed == false )
 213             {
 214                 throw new RuntimeException( failureMessage );
 215             }
 216         }
 217 
 218     }//main
 219 
 220     private static Method setMixingCutoutShapeMethod;
 221 
 222     private static void setMixingCutoutShape(Component comp, Shape shape) {
 223         try {
 224             setMixingCutoutShapeMethod.invoke(comp, shape);
 225         } catch (Exception e) {
 226             throw new RuntimeException("Cannot execute setMixingCutoutShape " +
 227                     "method");
 228         }
 229     }
 230 
 231     public static synchronized void setTimeoutTo( int seconds )
 232     {
 233         sleepTime = seconds * 1000;
 234     }
 235 
 236     public static synchronized void pass()
 237     {
 238         Sysout.println( "The test passed." );
 239         Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
 240         //first check if this is executing in main thread
 241         if ( mainThread == Thread.currentThread() )
 242         {
 243             //Still in the main thread, so set the flag just for kicks,
 244             // and throw a test passed exception which will be caught
 245             // and end the test.
 246             theTestPassed = true;
 247             throw new TestPassedException();
 248         }
 249         theTestPassed = true;


< prev index next >