1 19 20 package org.netbeans.api.debugger.jpda; 21 22 import org.netbeans.api.debugger.DebuggerManager; 23 import org.netbeans.junit.NbTestCase; 24 25 30 public class EvaluationTest extends NbTestCase { 31 32 private JPDASupport support; 33 34 35 public EvaluationTest (String s) { 36 super (s); 37 } 38 39 protected void setUp () throws Exception { 40 super.setUp (); 41 JPDASupport.removeAllBreakpoints (); 42 LineBreakpoint lb = LineBreakpoint.create ( 43 Utils.getURL(System.getProperty ("test.dir.src")+ 44 "org/netbeans/api/debugger/jpda/testapps/EvalApp.java"), 45 34 46 ); 47 DebuggerManager.getDebuggerManager ().addBreakpoint (lb); 48 support = JPDASupport.attach ( 49 "org.netbeans.api.debugger.jpda.testapps.EvalApp" 50 ); 51 support.waitState (JPDADebugger.STATE_STOPPED); 52 } 53 54 public void testStaticEvaluation () throws Exception { 55 try { 56 checkEval ("1", 1); 57 checkEval ("4.3", 4.3); 58 checkEval ("ix", 74); 59 60 checkEvalFails ("this"); 61 checkEvalFails ("NoSuchClass.class"); 62 } finally { 63 support.doFinish (); 64 } 65 } 66 67 public void testStaticExpressions () throws Exception { 68 try { 69 checkEval ("ix * fx", 740.0f); 70 checkEval ("sx % 3", 1); 71 72 checkEvalFails ("ix * fx ** fx"); 73 } finally { 74 support.doFinish (); 75 } 76 } 77 78 private void checkEval (String expression, int value) { 79 try { 80 Variable var = support.getDebugger ().evaluate (expression); 81 assertEquals ( 82 "Evaluation of expression failed (wrong value): " + expression, 83 value, 84 Integer.parseInt (var.getValue ()), 0 85 ); 86 assertEquals ( 87 "Evaluation of expression failed (wrong type of result): " + 88 expression, 89 "int", 90 var.getType () 91 ); 92 } catch (InvalidExpressionException e) { 93 fail ( 94 "Evaluation of expression was unsuccessful: " + e 95 ); 96 } 97 } 98 99 private void checkEval(String expression, float value) { 100 try { 101 Variable var = support.getDebugger ().evaluate (expression); 102 assertEquals ( 103 "Evaluation of expression failed (wrong value): " + expression, 104 value, 105 Float.parseFloat (var.getValue ()), 106 0 107 ); 108 assertEquals ( 109 "Evaluation of expression failed (wrong type of result): " + 110 expression, 111 "float", 112 var.getType () 113 ); 114 } catch (InvalidExpressionException e) { 115 fail ( 116 "Evaluation of expression was unsuccessful: " + e 117 ); 118 } 119 } 120 121 private void checkEval (String expression, double value) { 122 try { 123 Variable var = support.getDebugger ().evaluate (expression); 124 assertEquals ( 125 "Evaluation of expression failed (wrong value): " + expression, 126 value, 127 Double.parseDouble (var.getValue ()), 128 0 129 ); 130 assertEquals ( 131 "Evaluation of expression failed (wrong type of result): " + 132 expression, 133 "double", 134 var.getType () 135 ); 136 } catch (InvalidExpressionException e) { 137 fail ( 138 "Evaluation of expression was unsuccessful: " + e 139 ); 140 } 141 } 142 143 private void checkEval (String expression, String type, String value) { 144 try { 145 Variable var = support.getDebugger ().evaluate (expression); 146 assertEquals ( 147 "Evaluation of expression failed (wrong value): " + expression, 148 value, 149 var.getValue () 150 ); 151 assertEquals ( 152 "Evaluation of expression failed (wrong type of result): " + 153 expression, 154 type, 155 var.getType () 156 ); 157 } catch (InvalidExpressionException e) { 158 fail ( 159 "Evaluation of expression was unsuccessful: " + e 160 ); 161 } 162 } 163 164 private void checkEvalFails (String expression) { 165 try { 166 Variable var = support.getDebugger ().evaluate (expression); 167 fail ( 168 "Evaluation of expression was unexpectedly successful: " + 169 expression + " = " + var.getValue () 170 ); 171 } catch (InvalidExpressionException e) { 172 return; 174 } 175 } 176 } 177 | Popular Tags |