001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans.
026: * The Initial Developer of the Original Software is Sun Microsystems, Inc.
027: * Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: * Contributor(s): Sun Microsystems, Inc.
042: */
043:
044: package gui.debuggercore;
045:
046: import java.io.File;
047: import junit.textui.TestRunner;
048: import org.netbeans.jellytools.*;
049: import org.netbeans.jellytools.actions.Action;
050: import org.netbeans.jellytools.actions.OpenAction;
051: import org.netbeans.jellytools.modules.debugger.actions.RunToCursorAction;
052: import org.netbeans.jellytools.nodes.Node;
053: import org.netbeans.jellytools.nodes.SourcePackagesNode;
054: import org.netbeans.jemmy.EventTool;
055: import org.netbeans.jemmy.JemmyProperties;
056: import org.netbeans.jemmy.operators.JTableOperator;
057: import org.netbeans.jemmy.util.PNGEncoder;
058: import org.netbeans.junit.NbTestSuite;
059:
060: /**
061: *
062: * @author ehucka
063: */
064: public class LocalVariables extends JellyTestCase {
065:
066: static int consoleLineNumber = 0;
067:
068: String projectPropertiesTitle;
069:
070: /**
071: *
072: * @param name
073: */
074: public LocalVariables(String name) {
075: super (name);
076: }
077:
078: /**
079: *
080: * @param args
081: */
082: public static void main(String[] args) {
083: TestRunner.run(suite());
084: }
085:
086: /**
087: *
088: * @return
089: */
090: public static NbTestSuite suite() {
091: NbTestSuite suite = new NbTestSuite();
092: suite.addTest(new LocalVariables("testLocalVariablesThisNode"));
093: suite
094: .addTest(new LocalVariables(
095: "testLocalVariablesStaticNode"));
096: suite.addTest(new LocalVariables(
097: "testLocalVariablesStaticInherited"));
098: suite.addTest(new LocalVariables(
099: "testLocalVariablesInheritedNode"));
100: suite.addTest(new LocalVariables("testLocalVariablesExtended"));
101: suite.addTest(new LocalVariables("testLocalVariablesValues"));
102: suite.addTest(new LocalVariables(
103: "testLocalVariablesSubExpressions"));
104: return suite;
105: }
106:
107: /**
108: *
109: */
110: public void setUp() {
111: System.out.println("######## " + getName() + " #######");
112: if (getName().equals("testLocalVariablesThisNode")) {
113: //open source
114: Node beanNode = new Node(new SourcePackagesNode(
115: Utilities.testProjectName),
116: "examples.advanced|MemoryView.java"); //NOI18N
117: new OpenAction().performAPI(beanNode);
118: EditorOperator eo = new EditorOperator("MemoryView.java");
119: Utilities.setCaret(eo, 52);
120: new RunToCursorAction().perform();
121: Utilities.getDebugToolbar().waitComponentVisible(true);
122: consoleLineNumber = Utilities.waitDebuggerConsole(
123: "Thread main stopped at MemoryView.java:52.", 0);
124: new EventTool().waitNoEvent(1000);
125: expandNodes();
126: }
127: }
128:
129: /**
130: *
131: */
132: public void tearDown() {
133: JemmyProperties.getCurrentOutput().printTrace("\nteardown\n");
134: if (getName().equals("testLocalVariablesSubExpressions")) {//last
135: Utilities.endAllSessions();
136: }
137: }
138:
139: /**
140: *
141: */
142: protected void expandNodes() {
143: Utilities.showDebuggerView(Utilities.localVarsViewTitle);
144: JTableOperator jTableOperator = new JTableOperator(
145: new TopComponentOperator(Utilities.localVarsViewTitle));
146: TreeTableOperator treeTableOperator = new TreeTableOperator(
147: (javax.swing.JTable) jTableOperator.getSource());
148: new org.netbeans.jellytools.nodes.Node(
149: treeTableOperator.tree(), "this").expand();
150: //Utilities.sleep(500);
151: new org.netbeans.jellytools.nodes.Node(
152: treeTableOperator.tree(), "this|Static").expand();
153: //Utilities.sleep(500);
154: new org.netbeans.jellytools.nodes.Node(
155: treeTableOperator.tree(), "this|Inherited").expand();
156: //Utilities.sleep(500);
157: }
158:
159: /**
160: *
161: */
162: public void testLocalVariablesThisNode() throws Throwable {
163: try {
164: JTableOperator jTableOperator = new JTableOperator(
165: new TopComponentOperator(
166: Utilities.localVarsViewTitle));
167: checkTreeTableLine(jTableOperator, 2, "Vpublic", "String",
168: "\"Public Variable\"");
169: checkTreeTableLine(jTableOperator, 3, "Vprotected",
170: "String", "\"Protected Variable\"");
171: checkTreeTableLine(jTableOperator, 4, "Vprivate", "String",
172: "\"Private Variable\"");
173: checkTreeTableLine(jTableOperator, 5, "VpackagePrivate",
174: "String", "\"Package-private Variable\"");
175: } catch (Throwable th) {
176: Utilities.captureScreen(this );
177: throw th;
178: }
179: }
180:
181: /**
182: *
183: */
184: public void testLocalVariablesStaticNode() throws Throwable {
185: try {
186: JTableOperator jTableOperator = new JTableOperator(
187: new TopComponentOperator(
188: Utilities.localVarsViewTitle));
189: checkTreeTableLine(jTableOperator, 10, "Spublic", "String",
190: "\"Public Variable\"");
191: checkTreeTableLine(jTableOperator, 11, "Sprotected",
192: "String", "\"Protected Variable\"");
193: checkTreeTableLine(jTableOperator, 12, "Sprivate",
194: "String", "\"Private Variable\"");
195: checkTreeTableLine(jTableOperator, 13, "SpackagePrivate",
196: "String", "\"Package-private Variable\"");
197: } catch (Throwable th) {
198: Utilities.captureScreen(this );
199: throw th;
200: }
201: }
202:
203: /**
204: *
205: */
206: public void testLocalVariablesStaticInherited() throws Throwable {
207: try {
208: JTableOperator jTableOperator = new JTableOperator(
209: new TopComponentOperator(
210: Utilities.localVarsViewTitle));
211: checkTreeTableLine(jTableOperator, 15, "inheritedSpublic",
212: "String", "\"Inherited Public Variable\"");
213: checkTreeTableLine(jTableOperator, 16,
214: "inheritedSprotected", "String",
215: "\"Inherited Protected Variable\"");
216: checkTreeTableLine(jTableOperator, 17, "inheritedSprivate",
217: "String", "\"Inherited Private Variable\"");
218: checkTreeTableLine(jTableOperator, 18,
219: "inheritedSpackagePrivate", "String",
220: "\"Inherited Package-private Variable\"");
221: } catch (Throwable th) {
222: Utilities.captureScreen(this );
223: throw th;
224: }
225: }
226:
227: /**
228: *
229: */
230: public void testLocalVariablesInheritedNode() throws Throwable {
231: try {
232: JTableOperator jTableOperator = new JTableOperator(
233: new TopComponentOperator(
234: Utilities.localVarsViewTitle));
235: checkTreeTableLine(jTableOperator, 20, "inheritedVpublic",
236: "String", "\"Inherited Public Variable\"");
237: checkTreeTableLine(jTableOperator, 21,
238: "inheritedVprotected", "String",
239: "\"Inherited Protected Variable\"");
240: checkTreeTableLine(jTableOperator, 22, "inheritedVprivate",
241: "String", "\"Inherited Private Variable\"");
242: checkTreeTableLine(jTableOperator, 23,
243: "inheritedVpackagePrivate", "String",
244: "\"Inherited Package-private Variable\"");
245: } catch (Throwable th) {
246: Utilities.captureScreen(this );
247: throw th;
248: }
249: }
250:
251: /**
252: *
253: */
254: public void testLocalVariablesExtended() throws Throwable {
255: try {
256: EditorOperator eo = new EditorOperator("MemoryView.java");
257: Utilities.setCaret(eo, 76);
258: new RunToCursorAction().perform();
259: consoleLineNumber = Utilities.waitDebuggerConsole(
260: "Thread main stopped at MemoryView.java:76.",
261: consoleLineNumber + 1);
262: new EventTool().waitNoEvent(1000);
263:
264: Utilities.showDebuggerView(Utilities.localVarsViewTitle);
265: JTableOperator jTableOperator = new JTableOperator(
266: new TopComponentOperator(
267: Utilities.localVarsViewTitle));
268: TreeTableOperator treeTableOperator = new TreeTableOperator(
269: (javax.swing.JTable) jTableOperator.getSource());
270: int count = 0;
271: checkTreeTableLine(jTableOperator, count++, "this",
272: "MemoryView", null);
273: checkTreeTableLine(jTableOperator, count++, "timer", null,
274: "null");
275: checkTreeTableLine(jTableOperator, count++, "Vpublic",
276: "String", "\"Public Variable\"");
277: checkTreeTableLine(jTableOperator, count++, "Vprotected",
278: "String", "\"Protected Variable\"");
279: checkTreeTableLine(jTableOperator, count++, "Vprivate",
280: "String", "\"Private Variable\"");
281: checkTreeTableLine(jTableOperator, count++,
282: "VpackagePrivate", "String",
283: "\"Package-private Variable\"");
284: checkTreeTableLine(jTableOperator, count++, "Static", null,
285: null);
286: checkTreeTableLine(jTableOperator, count++, "bundle",
287: "PropertyResourceBundle", null);
288: assertTrue("Node bundle has no child nodes", hasChildNodes(
289: "this|Static|bundle", treeTableOperator));
290: checkTreeTableLine(jTableOperator, count++, "msgMemory",
291: "MessageFormat", null);
292: assertTrue("Node msgMemory has no child nodes",
293: hasChildNodes("this|Static|msgMemory",
294: treeTableOperator));
295: checkTreeTableLine(jTableOperator, count++, "UPDATE_TIME",
296: "int", "1000");
297: checkTreeTableLine(jTableOperator, count++, "Spublic",
298: "String", "\"Public Variable\"");
299: checkTreeTableLine(jTableOperator, count++, "Sprotected",
300: "String", "\"Protected Variable\"");
301: checkTreeTableLine(jTableOperator, count++, "Sprivate",
302: "String", "\"Private Variable\"");
303: checkTreeTableLine(jTableOperator, count++,
304: "SpackagePrivate", "String",
305: "\"Package-private Variable\"");
306: checkTreeTableLine(jTableOperator, count++,
307: "class$java$lang$Runtime", "Class",
308: "class java.lang.Runtime");
309: assertTrue(
310: "Node class$java$lang$Runtime has no child nodes",
311: hasChildNodes(
312: "this|Static|class$java$lang$Runtime",
313: treeTableOperator));
314: checkTreeTableLine(jTableOperator, count++,
315: "inheritedSpublic", "String",
316: "\"Inherited Public Variable\"");
317: checkTreeTableLine(jTableOperator, count++,
318: "inheritedSprotected", "String",
319: "\"Inherited Protected Variable\"");
320: checkTreeTableLine(jTableOperator, count++,
321: "inheritedSprivate", "String",
322: "\"Inherited Private Variable\"");
323: checkTreeTableLine(jTableOperator, count++,
324: "inheritedSpackagePrivate", "String",
325: "\"Inherited Package-private Variable\"");
326: checkTreeTableLine(jTableOperator, count++, "Inherited",
327: null, null);
328: checkTreeTableLine(jTableOperator, count++,
329: "inheritedVpublic", "String",
330: "\"Inherited Public Variable\"");
331: checkTreeTableLine(jTableOperator, count++,
332: "inheritedVprotected", "String",
333: "\"Inherited Protected Variable\"");
334: checkTreeTableLine(jTableOperator, count++,
335: "inheritedVprivate", "String",
336: "\"Inherited Private Variable\"");
337: checkTreeTableLine(jTableOperator, count++,
338: "inheritedVpackagePrivate", "String",
339: "\"Inherited Package-private Variable\"");
340: checkTreeTableLine(jTableOperator, count++, "clazz",
341: "Class", "class java.lang.Runtime");
342: assertTrue("Node clazz has no child nodes", hasChildNodes(
343: "clazz", treeTableOperator));
344: checkTreeTableLine(jTableOperator, count++, "string",
345: "String", "\"Hi!\"");
346: checkTreeTableLine(jTableOperator, count++, "n", "int",
347: "50");
348: checkTreeTableLine(jTableOperator, count++, "llist",
349: "LinkedList", null);
350: assertTrue("Node llist has no child nodes", hasChildNodes(
351: "llist", treeTableOperator));
352: checkTreeTableLine(jTableOperator, count++, "alist",
353: "ArrayList", null);
354: assertTrue("Node alist has no child nodes", hasChildNodes(
355: "alist", treeTableOperator));
356: checkTreeTableLine(jTableOperator, count++, "vec",
357: "Vector", null);
358: assertTrue("Node vec has no child nodes", hasChildNodes(
359: "vec", treeTableOperator));
360: checkTreeTableLine(jTableOperator, count++, "hmap",
361: "HashMap", null);
362: assertTrue("Node hmap has no child nodes", hasChildNodes(
363: "hmap", treeTableOperator));
364: checkTreeTableLine(jTableOperator, count++, "htab",
365: "Hashtable", null);
366: assertTrue("Node htab has no child nodes", hasChildNodes(
367: "htab", treeTableOperator));
368: checkTreeTableLine(jTableOperator, count++, "tmap",
369: "TreeMap", null);
370: assertTrue("Node tmap has no child nodes", hasChildNodes(
371: "tmap", treeTableOperator));
372: checkTreeTableLine(jTableOperator, count++, "hset",
373: "HashSet", null);
374: assertTrue("Node hset has no child nodes", hasChildNodes(
375: "hset", treeTableOperator));
376: checkTreeTableLine(jTableOperator, count++, "tset",
377: "TreeSet", null);
378: assertTrue("Node tset has no child nodes", hasChildNodes(
379: "tset", treeTableOperator));
380: checkTreeTableLine(jTableOperator, count++, "policko",
381: "int[]", null);
382: assertTrue("Node policko has no child nodes",
383: hasChildNodes("policko", treeTableOperator));
384: checkTreeTableLine(jTableOperator, count++, "pole",
385: "int[]", null);
386: assertTrue("Node pole has no child nodes", hasChildNodes(
387: "pole", treeTableOperator));
388: checkTreeTableLine(jTableOperator, count++, "d2",
389: "int[][]", null);
390: assertTrue("Node d2 has no child nodes", hasChildNodes(
391: "d2", treeTableOperator));
392: } catch (Throwable th) {
393: Utilities.captureScreen(this );
394: throw th;
395: }
396: }
397:
398: /**
399: *
400: */
401: public void testLocalVariablesValues() throws Throwable {
402: try {
403: Node beanNode = new Node(new SourcePackagesNode(
404: Utilities.testProjectName),
405: "examples.advanced|MemoryView.java"); //NOI18N
406: new OpenAction().performAPI(beanNode);
407: EditorOperator eo = new EditorOperator("MemoryView.java");
408: Utilities.setCaret(eo, 104);
409: new EventTool().waitNoEvent(500);
410: new RunToCursorAction().performMenu();
411: new EventTool().waitNoEvent(500);
412: consoleLineNumber = Utilities.waitDebuggerConsole(
413: "Thread main stopped at MemoryView.java:104.",
414: consoleLineNumber + 1);
415:
416: Utilities.showDebuggerView(Utilities.localVarsViewTitle);
417: JTableOperator jTableOperator = new JTableOperator(
418: new TopComponentOperator(
419: Utilities.localVarsViewTitle));
420: try {
421: org.openide.nodes.Node.Property property;
422: property = (org.openide.nodes.Node.Property) jTableOperator
423: .getValueAt(25, 2);
424: long free = Long.parseLong(property.getValue()
425: .toString());
426: property = (org.openide.nodes.Node.Property) jTableOperator
427: .getValueAt(26, 2);
428: long total = Long.parseLong(property.getValue()
429: .toString());
430: property = (org.openide.nodes.Node.Property) jTableOperator
431: .getValueAt(27, 2);
432: long taken = Long.parseLong(property.getValue()
433: .toString());
434: assertTrue(
435: "Local varaibles values does not seem to be correct (total != free + taken) - "
436: + total + " != " + free + " + " + taken,
437: (total == free + taken));
438:
439: } catch (java.lang.IllegalAccessException e1) {
440: assertTrue(e1.getMessage(), false);
441: } catch (java.lang.reflect.InvocationTargetException e2) {
442: assertTrue(e2.getMessage(), false);
443: }
444: } catch (Throwable th) {
445: Utilities.captureScreen(this );
446: throw th;
447: }
448: }
449:
450: /**
451: *
452: */
453: public void testLocalVariablesSubExpressions() throws Throwable {
454: try {
455: /*Node beanNode = new Node(new SourcePackagesNode(Utilities.testProjectName), "examples.advanced|MemoryView.java"); //NOI18N
456: new OpenAction().performAPI(beanNode);
457: EditorOperator eo = new EditorOperator("MemoryView.java");
458: Utilities.setCaret(eo, 104);
459: new EventTool().waitNoEvent(500);
460: new RunToCursorAction().performMenu();
461: new EventTool().waitNoEvent(500);
462: consoleLineNumber = Utilities.waitDebuggerConsole("Thread main stopped at MemoryView.java:104.", consoleLineNumber+1);
463: */
464: new Action(Utilities.runMenu + "|"
465: + Utilities.stepOverExpresItem, null).perform();
466: new Action(Utilities.runMenu + "|"
467: + Utilities.stepOverExpresItem, null).perform();
468: new Action(Utilities.runMenu + "|"
469: + Utilities.stepOverExpresItem, null).perform();
470: new Action(Utilities.runMenu + "|"
471: + Utilities.stepOverExpresItem, null).perform();
472: new Action(Utilities.runMenu + "|"
473: + Utilities.stepOverExpresItem, null).perform();
474: new Action(Utilities.runMenu + "|"
475: + Utilities.stepOverExpresItem, null).perform();
476:
477: Utilities.showDebuggerView(Utilities.localVarsViewTitle);
478: JTableOperator jTableOperator = new JTableOperator(
479: new TopComponentOperator(
480: Utilities.localVarsViewTitle));
481: TreeTableOperator treeTableOperator = new TreeTableOperator(
482: (javax.swing.JTable) jTableOperator.getSource());
483: String name = Bundle
484: .getString(
485: "org.netbeans.modules.debugger.jpda.ui.models.Bundle",
486: "lastOperationsNode");
487: org.netbeans.jellytools.nodes.Node nd = new org.netbeans.jellytools.nodes.Node(
488: treeTableOperator.tree(), name);
489: nd.expand();
490: String[] children = nd.getChildren();
491: assertEquals(5, children.length);
492: assertEquals("Wrong sub-expression node",
493: "return <init>()", children[0]);
494: assertEquals("Wrong sub-expression node",
495: "return <init>()", children[1]);
496: assertEquals("Wrong sub-expression node",
497: "return <init>()", children[2]);
498: assertEquals("Wrong sub-expression node",
499: "return format()", children[3]);
500: assertEquals("Wrong sub-expression node",
501: "return println()", children[4]);
502:
503: } catch (Throwable th) {
504: Utilities.captureScreen(this );
505: throw th;
506: }
507: }
508:
509: /**
510: * check values in TreeTable line
511: * @param table
512: * @param lineNumber
513: * @param name
514: * @param type
515: * @param value
516: */
517: protected void checkTreeTableLine(JTableOperator table,
518: int lineNumber, String name, String type, String value) {
519: try {
520: table.scrollToCell(lineNumber, 0);
521: org.openide.nodes.Node.Property property;
522: String string = null;
523: assertTrue("Node " + name
524: + " not displayed in Local Variables view", name
525: .equals(table.getValueAt(lineNumber, 0).toString()));
526: property = (org.openide.nodes.Node.Property) table
527: .getValueAt(lineNumber, 1);
528: string = property.getValue().toString();
529: int maxWait = 100;
530: while (string.equals(Utilities.evaluatingPropertyText)
531: && maxWait > 0) {
532: new EventTool().waitNoEvent(300);
533: maxWait--;
534: }
535: assertTrue(
536: "Node "
537: + name
538: + " has wrong type in Local Variables view (displayed: "
539: + string + ", expected: " + type + ")",
540: (type == null) || type.equals(string));
541: property = (org.openide.nodes.Node.Property) table
542: .getValueAt(lineNumber, 2);
543: string = property.getValue().toString();
544: maxWait = 100;
545: while (string.equals(Utilities.evaluatingPropertyText)
546: && maxWait > 0) {
547: new EventTool().waitNoEvent(300);
548: maxWait--;
549: }
550: assertTrue(
551: "Node "
552: + name
553: + " has wrong value in Local Variables view (displayed: "
554: + string + ", expected: " + value + ")",
555: (type == null) || !type.equals(string));
556: } catch (java.lang.IllegalAccessException e1) {
557: assertTrue(e1.getMessage(), false);
558: } catch (java.lang.reflect.InvocationTargetException e2) {
559: assertTrue(e2.getMessage(), false);
560: }
561: }
562:
563: protected boolean hasChildNodes(String nodePath,
564: TreeTableOperator jTableOperator) {
565: org.netbeans.jellytools.nodes.Node node = new org.netbeans.jellytools.nodes.Node(
566: jTableOperator.tree(), nodePath);
567: node.select();
568: return !node.isLeaf();
569: }
570: }
|