1 2 3 4 5 6 public class SwitchLoad implements org.quilt.cl.RunTest { 7 public static final int MAGICNUMBER = 0xCAFEBABE; 8 public static final long MAGICLONG = 0x00000000CAFEBABE; 9 public static final short MAGICSHORT = (short) 0xCAFE; 10 11 public static final float PI_FLOAT = (float) 3.1415; 12 public static final double PI_DOUBLE = (double) 3.1415; 13 public static final int NORMALNUMBER = 188; 14 public static final int WEIRDNUMBER = -1; 15 16 private double twoPie; 17 18 public boolean switchStatement( int stmt ) { 19 20 switch( stmt ) { 21 case WEIRDNUMBER: 22 throw new RuntimeException ("Weird Switch"); 23 case NORMALNUMBER: 24 return false; 25 case MAGICNUMBER: 26 return true; 27 default: 28 throw new RuntimeException ("Default Switch"); 29 } 30 } 31 32 public boolean doMagicSwitch() throws RuntimeException { 33 return switchStatement( MAGICNUMBER ); 34 } 36 37 public boolean doNormalSwitch( ) throws RuntimeException { 38 return switchStatement( NORMALNUMBER ); 39 } 41 42 public boolean doWeirdSwitch( ) throws RuntimeException { 43 return switchStatement( WEIRDNUMBER ); 44 } 46 47 public boolean doDefaultSwitch( ) throws RuntimeException { 48 return switchStatement( 10 ); 49 } 50 51 public int runTest(int x) { 52 boolean weirdSwitchOK = true; 53 boolean defaultSwitchOK = true; 54 55 if (!doMagicSwitch()) 56 throw new RuntimeException ("Magic Switch failed."); 57 if (doNormalSwitch()) 58 throw new RuntimeException ("Normal Switch failed."); 59 try { 60 doWeirdSwitch(); 61 weirdSwitchOK = false; 62 } catch (Exception e) { 63 weirdSwitchOK = true; 64 } 65 66 if (!weirdSwitchOK) 67 throw new RuntimeException ("Weird Switch failed."); 68 69 boolean isBad = false; 70 try { 71 doDefaultSwitch(); 72 defaultSwitchOK = false; 73 } catch (Exception e) { 74 defaultSwitchOK = true; 75 } 76 77 if (!defaultSwitchOK) 78 throw new RuntimeException ("Default Switch Failed"); 79 80 return 42; 81 } 82 } 83 | Popular Tags |