| 1 21 22 package gui.debuggercore; 23 24 import java.io.File ; 25 import junit.textui.TestRunner; 26 import org.netbeans.jellytools.*; 27 import org.netbeans.jellytools.actions.Action; 28 import org.netbeans.jellytools.actions.OpenAction; 29 import org.netbeans.jellytools.modules.debugger.actions.RunToCursorAction; 30 import org.netbeans.jellytools.nodes.Node; 31 import org.netbeans.jellytools.nodes.SourcePackagesNode; 32 import org.netbeans.jemmy.EventTool; 33 import org.netbeans.jemmy.JemmyProperties; 34 import org.netbeans.jemmy.operators.JTableOperator; 35 import org.netbeans.jemmy.util.PNGEncoder; 36 import org.netbeans.junit.NbTestSuite; 37 38 42 public class LocalVariables extends JellyTestCase { 43 44 static int consoleLineNumber = 0; 45 46 String projectPropertiesTitle; 47 48 52 public LocalVariables(String name) { 53 super(name); 54 } 55 56 60 public static void main(String [] args) { 61 TestRunner.run(suite()); 62 } 63 64 68 public static NbTestSuite suite() { 69 NbTestSuite suite = new NbTestSuite(); 70 suite.addTest(new LocalVariables("testLocalVariablesThisNode")); 71 suite.addTest(new LocalVariables("testLocalVariablesStaticNode")); 72 suite.addTest(new LocalVariables("testLocalVariablesStaticInherited")); 73 suite.addTest(new LocalVariables("testLocalVariablesInheritedNode")); 74 suite.addTest(new LocalVariables("testLocalVariablesExtended")); 75 suite.addTest(new LocalVariables("testLocalVariablesValues")); 76 suite.addTest(new LocalVariables("testLocalVariablesSubExpressions")); 77 return suite; 78 } 79 80 83 public void setUp() { 84 System.out.println("######## " + getName() + " #######"); 85 if (getName().equals("testLocalVariablesThisNode")) { 86 Node beanNode = new Node(new SourcePackagesNode(Utilities.testProjectName), "examples.advanced|MemoryView.java"); new OpenAction().performAPI(beanNode); 89 EditorOperator eo = new EditorOperator("MemoryView.java"); 90 Utilities.setCaret(eo, 52); 91 new RunToCursorAction().perform(); 92 Utilities.getDebugToolbar().waitComponentVisible(true); 93 consoleLineNumber = Utilities.waitDebuggerConsole("Thread main stopped at MemoryView.java:52.", 0); 94 new EventTool().waitNoEvent(1000); 95 expandNodes(); 96 } 97 } 98 99 102 public void tearDown() { 103 JemmyProperties.getCurrentOutput().printTrace("\nteardown\n"); 104 if (getName().equals("testLocalVariablesSubExpressions")) { Utilities.endAllSessions(); 106 } 107 } 108 109 112 protected void expandNodes() { 113 Utilities.showDebuggerView(Utilities.localVarsViewTitle); 114 JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.localVarsViewTitle)); 115 TreeTableOperator treeTableOperator = new TreeTableOperator((javax.swing.JTable ) jTableOperator.getSource()); 116 new org.netbeans.jellytools.nodes.Node(treeTableOperator.tree(), "this").expand(); 117 new org.netbeans.jellytools.nodes.Node(treeTableOperator.tree(), "this|Static").expand(); 119 new org.netbeans.jellytools.nodes.Node(treeTableOperator.tree(), "this|Inherited").expand(); 121 } 123 124 127 public void testLocalVariablesThisNode() throws Throwable { 128 try { 129 JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.localVarsViewTitle)); 130 checkTreeTableLine(jTableOperator, 2, "Vpublic", "String", "\"Public Variable\""); 131 checkTreeTableLine(jTableOperator, 3, "Vprotected", "String", "\"Protected Variable\""); 132 checkTreeTableLine(jTableOperator, 4, "Vprivate", "String", "\"Private Variable\""); 133 checkTreeTableLine(jTableOperator, 5, "VpackagePrivate", "String", "\"Package-private Variable\""); 134 } catch (Throwable th) { 135 try { 136 PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png"); 138 } catch (Exception e1) { 139 } 141 throw th; 142 } 143 } 144 145 148 public void testLocalVariablesStaticNode() throws Throwable { 149 try { 150 JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.localVarsViewTitle)); 151 checkTreeTableLine(jTableOperator, 10, "Spublic", "String", "\"Public Variable\""); 152 checkTreeTableLine(jTableOperator, 11, "Sprotected", "String", "\"Protected Variable\""); 153 checkTreeTableLine(jTableOperator, 12, "Sprivate", "String", "\"Private Variable\""); 154 checkTreeTableLine(jTableOperator, 13, "SpackagePrivate", "String", "\"Package-private Variable\""); 155 } catch (Throwable th) { 156 try { 157 PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png"); 159 } catch (Exception e1) { 160 } 162 throw th; 163 } 164 } 165 166 169 public void testLocalVariablesStaticInherited() throws Throwable { 170 try { 171 JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.localVarsViewTitle)); 172 checkTreeTableLine(jTableOperator, 15, "inheritedSpublic", "String", "\"Inherited Public Variable\""); 173 checkTreeTableLine(jTableOperator, 16, "inheritedSprotected", "String", "\"Inherited Protected Variable\""); 174 checkTreeTableLine(jTableOperator, 17, "inheritedSprivate", "String", "\"Inherited Private Variable\""); 175 checkTreeTableLine(jTableOperator, 18, "inheritedSpackagePrivate", "String", "\"Inherited Package-private Variable\""); 176 } catch (Throwable th) { 177 try { 178 PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png"); 180 } catch (Exception e1) { 181 } 183 throw th; 184 } 185 } 186 187 190 public void testLocalVariablesInheritedNode() throws Throwable { 191 try { 192 JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.localVarsViewTitle)); 193 checkTreeTableLine(jTableOperator, 20, "inheritedVpublic", "String", "\"Inherited Public Variable\""); 194 checkTreeTableLine(jTableOperator, 21, "inheritedVprotected", "String", "\"Inherited Protected Variable\""); 195 checkTreeTableLine(jTableOperator, 22, "inheritedVprivate", "String", "\"Inherited Private Variable\""); 196 checkTreeTableLine(jTableOperator, 23, "inheritedVpackagePrivate", "String", "\"Inherited Package-private Variable\""); 197 } catch (Throwable th) { 198 try { 199 PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png"); 201 } catch (Exception e1) { 202 } 204 throw th; 205 } 206 } 207 208 211 public void testLocalVariablesExtended() throws Throwable { 212 try { 213 EditorOperator eo = new EditorOperator("MemoryView.java"); 214 Utilities.setCaret(eo, 76); 215 new RunToCursorAction().perform(); 216 consoleLineNumber = Utilities.waitDebuggerConsole("Thread main stopped at MemoryView.java:76.", consoleLineNumber+1); 217 new EventTool().waitNoEvent(1000); 218 219 Utilities.showDebuggerView(Utilities.localVarsViewTitle); 220 JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.localVarsViewTitle)); 221 TreeTableOperator treeTableOperator = new TreeTableOperator((javax.swing.JTable ) jTableOperator.getSource()); 222 int count = 0; 223 checkTreeTableLine(jTableOperator, count++, "this", "MemoryView", null); 224 checkTreeTableLine(jTableOperator, count++, "timer", null, "null"); 225 checkTreeTableLine(jTableOperator, count++, "Vpublic", "String", "\"Public Variable\""); 226 checkTreeTableLine(jTableOperator, count++, "Vprotected", "String", "\"Protected Variable\""); 227 checkTreeTableLine(jTableOperator, count++, "Vprivate", "String", "\"Private Variable\""); 228 checkTreeTableLine(jTableOperator, count++, "VpackagePrivate", "String", "\"Package-private Variable\""); 229 checkTreeTableLine(jTableOperator, count++, "Static", null, null); 230 checkTreeTableLine(jTableOperator, count++, "bundle", "PropertyResourceBundle", null); 231 assertTrue("Node bundle has no child nodes", hasChildNodes("this|Static|bundle", treeTableOperator)); 232 checkTreeTableLine(jTableOperator, count++, "msgMemory", "MessageFormat", null); 233 assertTrue("Node msgMemory has no child nodes", hasChildNodes("this|Static|msgMemory", treeTableOperator)); 234 checkTreeTableLine(jTableOperator, count++, "UPDATE_TIME", "int", "1000"); 235 checkTreeTableLine(jTableOperator, count++, "Spublic", "String", "\"Public Variable\""); 236 checkTreeTableLine(jTableOperator, count++, "Sprotected", "String", "\"Protected Variable\""); 237 checkTreeTableLine(jTableOperator, count++, "Sprivate", "String", "\"Private Variable\""); 238 checkTreeTableLine(jTableOperator, count++, "SpackagePrivate", "String", "\"Package-private Variable\""); 239 checkTreeTableLine(jTableOperator, count++, "class$java$lang$Runtime", "Class", "class java.lang.Runtime"); 240 assertTrue("Node class$java$lang$Runtime has no child nodes", hasChildNodes("this|Static|class$java$lang$Runtime", treeTableOperator)); 241 checkTreeTableLine(jTableOperator, count++, "inheritedSpublic", "String", "\"Inherited Public Variable\""); 242 checkTreeTableLine(jTableOperator, count++, "inheritedSprotected", "String", "\"Inherited Protected Variable\""); 243 checkTreeTableLine(jTableOperator, count++, "inheritedSprivate", "String", "\"Inherited Private Variable\""); 244 checkTreeTableLine(jTableOperator, count++, "inheritedSpackagePrivate", "String", "\"Inherited Package-private Variable\""); 245 checkTreeTableLine(jTableOperator, count++, "Inherited", null, null); 246 checkTreeTableLine(jTableOperator, count++, "inheritedVpublic", "String", "\"Inherited Public Variable\""); 247 checkTreeTableLine(jTableOperator, count++, "inheritedVprotected", "String", "\"Inherited Protected Variable\""); 248 checkTreeTableLine(jTableOperator, count++, "inheritedVprivate", "String", "\"Inherited Private Variable\""); 249 checkTreeTableLine(jTableOperator, count++, "inheritedVpackagePrivate", "String", "\"Inherited Package-private Variable\""); 250 checkTreeTableLine(jTableOperator, count++, "clazz", "Class", "class java.lang.Runtime"); 251 assertTrue("Node clazz has no child nodes", hasChildNodes("clazz", treeTableOperator)); 252 checkTreeTableLine(jTableOperator, count++, "string", "String", "\"Hi!\""); 253 checkTreeTableLine(jTableOperator, count++, "n", "int", "50"); 254 checkTreeTableLine(jTableOperator, count++, "llist", "LinkedList", null); 255 assertTrue("Node llist has no child nodes", hasChildNodes("llist", treeTableOperator)); 256 checkTreeTableLine(jTableOperator, count++, "alist", "ArrayList", null); 257 assertTrue("Node alist has no child nodes", hasChildNodes("alist", treeTableOperator)); 258 checkTreeTableLine(jTableOperator, count++, "vec", "Vector", null); 259 assertTrue("Node vec has no child nodes", hasChildNodes("vec", treeTableOperator)); 260 checkTreeTableLine(jTableOperator, count++, "hmap", "HashMap", null); 261 assertTrue("Node hmap has no child nodes", hasChildNodes("hmap", treeTableOperator)); 262 checkTreeTableLine(jTableOperator, count++, "htab", "Hashtable", null); 263 assertTrue("Node htab has no child nodes", hasChildNodes("htab", treeTableOperator)); 264 checkTreeTableLine(jTableOperator, count++, "tmap", "TreeMap", null); 265 assertTrue("Node tmap has no child nodes", hasChildNodes("tmap", treeTableOperator)); 266 checkTreeTableLine(jTableOperator, count++, "hset", "HashSet", null); 267 assertTrue("Node hset has no child nodes", hasChildNodes("hset", treeTableOperator)); 268 checkTreeTableLine(jTableOperator, count++, "tset", "TreeSet", null); 269 assertTrue("Node tset has no child nodes", hasChildNodes("tset", treeTableOperator)); 270 checkTreeTableLine(jTableOperator, count++, "policko", "int[]", null); 271 assertTrue("Node policko has no child nodes", hasChildNodes("policko", treeTableOperator)); 272 checkTreeTableLine(jTableOperator, count++, "pole", "int[]", null); 273 assertTrue("Node pole has no child nodes", hasChildNodes("pole", treeTableOperator)); 274 checkTreeTableLine(jTableOperator, count++, "d2", "int[][]", null); 275 assertTrue("Node d2 has no child nodes", hasChildNodes("d2", treeTableOperator)); 276 } catch (Throwable th) { 277 try { 278 PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png"); 280 } catch (Exception e1) { 281 } 283 throw th; 284 } 285 } 286 287 290 public void testLocalVariablesValues() throws Throwable { 291 try { 292 Node beanNode = new Node(new SourcePackagesNode(Utilities.testProjectName), "examples.advanced|MemoryView.java"); new OpenAction().performAPI(beanNode); 294 EditorOperator eo = new EditorOperator("MemoryView.java"); 295 Utilities.setCaret(eo, 104); 296 new EventTool().waitNoEvent(500); 297 new RunToCursorAction().performMenu(); 298 new EventTool().waitNoEvent(500); 299 consoleLineNumber = Utilities.waitDebuggerConsole("Thread main stopped at MemoryView.java:104.", consoleLineNumber+1); 300 301 Utilities.showDebuggerView(Utilities.localVarsViewTitle); 302 JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.localVarsViewTitle)); 303 try { 304 org.openide.nodes.Node.Property property; 305 property = (org.openide.nodes.Node.Property)jTableOperator.getValueAt(25, 2); 306 long free = Long.parseLong(property.getValue().toString()); 307 property = (org.openide.nodes.Node.Property)jTableOperator.getValueAt(26, 2); 308 long total = Long.parseLong(property.getValue().toString()); 309 property = (org.openide.nodes.Node.Property)jTableOperator.getValueAt(27, 2); 310 long taken = Long.parseLong(property.getValue().toString()); 311 assertTrue("Local varaibles values does not seem to be correct (total != free + taken) - "+total+" != "+free+" + "+taken, (total == free + taken)); 312 313 } catch (java.lang.IllegalAccessException e1) { 314 assertTrue(e1.getMessage(), false); 315 } catch (java.lang.reflect.InvocationTargetException e2) { 316 assertTrue(e2.getMessage(), false); 317 } 318 } catch (Throwable th) { 319 try { 320 PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png"); 322 } catch (Exception e1) { 323 } 325 throw th; 326 } 327 } 328 329 332 public void testLocalVariablesSubExpressions() throws Throwable { 333 try { 334 343 new Action(Utilities.runMenu+"|"+Utilities.stepOverExpresItem, null).perform(); 344 new Action(Utilities.runMenu+"|"+Utilities.stepOverExpresItem, null).perform(); 345 new Action(Utilities.runMenu+"|"+Utilities.stepOverExpresItem, null).perform(); 346 new Action(Utilities.runMenu+"|"+Utilities.stepOverExpresItem, null).perform(); 347 new Action(Utilities.runMenu+"|"+Utilities.stepOverExpresItem, null).perform(); 348 new Action(Utilities.runMenu+"|"+Utilities.stepOverExpresItem, null).perform(); 349 350 Utilities.showDebuggerView(Utilities.localVarsViewTitle); 351 JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.localVarsViewTitle)); 352 TreeTableOperator treeTableOperator = new TreeTableOperator((javax.swing.JTable ) jTableOperator.getSource()); 353 String name = Bundle.getString("org.netbeans.modules.debugger.jpda.ui.models.Bundle", "lastOperationsNode"); 354 org.netbeans.jellytools.nodes.Node nd = new org.netbeans.jellytools.nodes.Node(treeTableOperator.tree(), name); 355 nd.expand(); 356 String [] children = nd.getChildren(); 357 assertEquals(5, children.length); 358 assertEquals("Wrong sub-expression node", "return <init>()", children[0]); 359 assertEquals("Wrong sub-expression node", "return <init>()", children[1]); 360 assertEquals("Wrong sub-expression node", "return <init>()", children[2]); 361 assertEquals("Wrong sub-expression node", "return format()", children[3]); 362 assertEquals("Wrong sub-expression node", "return println()", children[4]); 363 364 } catch (Throwable th) { 365 try { 366 PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png"); 368 } catch (Exception e1) { 369 } 371 throw th; 372 } 373 } 374 375 383 protected void checkTreeTableLine(JTableOperator table, int lineNumber, String name, String type, String value) { 384 try { 385 table.scrollToCell(lineNumber, 0); 386 org.openide.nodes.Node.Property property; 387 String string = null; 388 assertTrue("Node " + name + " not displayed in Local Variables view", name.equals(table.getValueAt(lineNumber, 0).toString())); 389 property = (org.openide.nodes.Node.Property)table.getValueAt(lineNumber, 1); 390 string = property.getValue().toString(); 391 int maxWait = 100; 392 while (string.equals(Utilities.evaluatingPropertyText) && maxWait > 0) { 393 new EventTool().waitNoEvent(300); 394 maxWait--; 395 } 396 assertTrue("Node " + name + " has wrong type in Local Variables view (displayed: " + string + ", expected: " + type + ")", 397 (type == null) || type.equals(string)); 398 property = (org.openide.nodes.Node.Property)table.getValueAt(lineNumber, 2); 399 string = property.getValue().toString(); 400 maxWait = 100; 401 while (string.equals(Utilities.evaluatingPropertyText) && maxWait > 0) { 402 new EventTool().waitNoEvent(300); 403 maxWait--; 404 } 405 assertTrue("Node " + name + " has wrong value in Local Variables view (displayed: " + string + ", expected: " + value + ")", 406 (type == null) || !type.equals(string)); 407 } catch (java.lang.IllegalAccessException e1) { 408 assertTrue(e1.getMessage(), false); 409 } catch (java.lang.reflect.InvocationTargetException e2) { 410 assertTrue(e2.getMessage(), false); 411 } 412 } 413 414 protected boolean hasChildNodes(String nodePath, TreeTableOperator jTableOperator) { 415 org.netbeans.jellytools.nodes.Node node = new org.netbeans.jellytools.nodes.Node(jTableOperator.tree(), nodePath); 416 node.select(); 417 return !node.isLeaf(); 418 } 419 } 420 | Popular Tags |