PageRenderTime 66ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/debugger.jpda.ui/test/qa-functional/src/org/netbeans/modules/debugger/jpda/ui/WatchesTest.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 571 lines | 410 code | 36 blank | 125 comment | 20 complexity | bdf0a7024f6514b3e15fc0cb07276cc1 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. * The Original Software is NetBeans.
  29. * The Initial Developer of the Original Software is Sun Microsystems, Inc.
  30. * Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
  31. * All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. *
  44. * Contributor(s): Sun Microsystems, Inc.
  45. */
  46. package org.netbeans.modules.debugger.jpda.ui;
  47. import java.io.IOException;
  48. import junit.framework.Test;
  49. import junit.textui.TestRunner;
  50. import org.netbeans.jellytools.EditorOperator;
  51. import org.netbeans.jellytools.NbDialogOperator;
  52. import org.netbeans.jellytools.OutlineOperator;
  53. import org.netbeans.jellytools.TopComponentOperator;
  54. import org.netbeans.jellytools.actions.ActionNoBlock;
  55. import org.netbeans.jellytools.actions.OpenAction;
  56. import org.netbeans.jellytools.nodes.OutlineNode;
  57. import org.netbeans.jellytools.nodes.SourcePackagesNode;
  58. import org.netbeans.jemmy.EventTool;
  59. import org.netbeans.jemmy.Waitable;
  60. import org.netbeans.jemmy.Waiter;
  61. import org.netbeans.jemmy.operators.JEditorPaneOperator;
  62. import org.openide.nodes.Node;
  63. /**
  64. *
  65. * @author ehucka, Jiri Kovalsky
  66. */
  67. public class WatchesTest extends DebuggerTestCase {
  68. private static String[] tests = new String[]{
  69. "testWatchesPublicVariables",
  70. "testWatchesProtectedVariables",
  71. "testWatchesPrivateVariables",
  72. "testWatchesPackagePrivateVariables",
  73. "testWatchesFiltersBasic",
  74. "testWatchesFiltersLinkedList",
  75. "testWatchesFiltersArrayList",
  76. "testWatchesFiltersVector",
  77. "testWatchesFiltersHashMap",
  78. "testWatchesFiltersHashtable",
  79. "testWatchesFiltersTreeMap",
  80. "testWatchesFiltersTreeSet",
  81. "testWatchesFilters1DArray",
  82. "testWatchesFilters2DArray",
  83. "testWatchesValues"
  84. };
  85. /**
  86. *
  87. * @param name
  88. */
  89. public WatchesTest(String name) {
  90. super(name);
  91. }
  92. /**
  93. *
  94. * @param args
  95. */
  96. public static void main(String[] args) {
  97. TestRunner.run(suite());
  98. }
  99. /**
  100. *
  101. * @return
  102. */
  103. public static Test suite() {
  104. return createModuleTest(WatchesTest.class, tests);
  105. }
  106. /**
  107. *
  108. */
  109. public void setUp() throws IOException {
  110. super.setUp();
  111. System.out.println("######## " + getName() + " #######");
  112. }
  113. /**
  114. *
  115. */
  116. public void tearDown() {
  117. super.tearDown();
  118. Utilities.deleteAllWatches();
  119. }
  120. /**
  121. *
  122. */
  123. public void testWatchesPublicVariables() {
  124. //open source
  125. org.netbeans.jellytools.nodes.Node beanNode = new org.netbeans.jellytools.nodes.Node(new SourcePackagesNode(Utilities.testProjectName), "examples.advanced|MemoryView.java"); //NOI18N
  126. new OpenAction().performAPI(beanNode); // NOI18N
  127. new EventTool().waitNoEvent(5000);
  128. EditorOperator eo = new EditorOperator("MemoryView.java");
  129. try {
  130. eo.clickMouse(50,50,1);
  131. } catch (Throwable t) {
  132. System.err.println(t.getMessage());
  133. }
  134. Utilities.toggleBreakpoint(eo, 76);
  135. Utilities.startDebugger();
  136. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  137. createWatch("Vpublic");
  138. createWatch("Spublic");
  139. createWatch("inheritedVpublic");
  140. createWatch("inheritedSpublic");
  141. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  142. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  143. checkOutlineTableLine(outlineOp, 0, "Vpublic", "String", "\"Public Variable\"");
  144. checkOutlineTableLine(outlineOp, 1, "Spublic", "String", "\"Public Variable\"");
  145. checkOutlineTableLine(outlineOp, 2, "inheritedVpublic", "String", "\"Inherited Public Variable\"");
  146. checkOutlineTableLine(outlineOp, 3, "inheritedSpublic", "String", "\"Inherited Public Variable\"");
  147. }
  148. /**
  149. *
  150. */
  151. public void testWatchesProtectedVariables() {
  152. EditorOperator eo = new EditorOperator("MemoryView.java");
  153. Utilities.toggleBreakpoint(eo, 76);
  154. Utilities.startDebugger();
  155. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  156. createWatch("Vprotected");
  157. createWatch("Sprotected");
  158. createWatch("inheritedVprotected");
  159. createWatch("inheritedSprotected");
  160. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  161. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  162. checkOutlineTableLine(outlineOp, 0, "Vprotected", "String", "\"Protected Variable\"");
  163. checkOutlineTableLine(outlineOp, 1, "Sprotected", "String", "\"Protected Variable\"");
  164. checkOutlineTableLine(outlineOp, 2, "inheritedVprotected", "String", "\"Inherited Protected Variable\"");
  165. checkOutlineTableLine(outlineOp, 3, "inheritedSprotected", "String", "\"Inherited Protected Variable\"");
  166. }
  167. /**
  168. *
  169. */
  170. public void testWatchesPrivateVariables() {
  171. EditorOperator eo = new EditorOperator("MemoryView.java");
  172. Utilities.toggleBreakpoint(eo, 76);
  173. Utilities.startDebugger();
  174. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  175. createWatch("Vprivate");
  176. createWatch("Sprivate");
  177. createWatch("inheritedVprivate");
  178. createWatch("inheritedSprivate");
  179. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  180. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  181. checkOutlineTableLine(outlineOp, 0, "Vprivate", "String", "\"Private Variable\"");
  182. checkOutlineTableLine(outlineOp, 1, "Sprivate", "String", "\"Private Variable\"");
  183. checkOutlineTableLine(outlineOp, 2, "inheritedVprivate", "String", "\"Inherited Private Variable\"");
  184. checkOutlineTableLine(outlineOp, 3, "inheritedSprivate", "String", "\"Inherited Private Variable\"");
  185. }
  186. /**
  187. *
  188. */
  189. public void testWatchesPackagePrivateVariables() {
  190. EditorOperator eo = new EditorOperator("MemoryView.java");
  191. Utilities.toggleBreakpoint(eo, 76);
  192. Utilities.startDebugger();
  193. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  194. createWatch("VpackagePrivate");
  195. createWatch("SpackagePrivate");
  196. createWatch("inheritedVpackagePrivate");
  197. createWatch("inheritedSpackagePrivate");
  198. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  199. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  200. checkOutlineTableLine(outlineOp, 0, "VpackagePrivate", "String", "\"Package-private Variable\"");
  201. checkOutlineTableLine(outlineOp, 1, "SpackagePrivate", "String", "\"Package-private Variable\"");
  202. checkOutlineTableLine(outlineOp, 2, "inheritedVpackagePrivate", "String", "\"Inherited Package-private Variable\"");
  203. checkOutlineTableLine(outlineOp, 3, "inheritedSpackagePrivate", "String", "\"Inherited Package-private Variable\"");
  204. }
  205. /**
  206. *
  207. */
  208. public void testWatchesFiltersBasic() {
  209. EditorOperator eo = new EditorOperator("MemoryView.java");
  210. Utilities.toggleBreakpoint(eo, 76);
  211. Utilities.startDebugger();
  212. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  213. createWatch("1==1");
  214. createWatch("1==0");
  215. createWatch("Integer.toString(10)");
  216. createWatch("clazz");
  217. createWatch("n");
  218. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  219. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  220. checkOutlineTableLine(outlineOp, 0, "1==1", "boolean", "true");
  221. checkOutlineTableLine(outlineOp, 1, "1==0", "boolean", "false");
  222. checkOutlineTableLine(outlineOp, 2, "Integer.toString(10)", "String", "\"10\"");
  223. checkOutlineTableLine(outlineOp, 3, "clazz", "Class", "class java.lang.Runtime");
  224. assertTrue("Node \'clazz\' has no child nodes", hasChildNodes("clazz", outlineOp));
  225. checkOutlineTableLine(outlineOp, 4, "n", "int", "50");
  226. }
  227. /**
  228. *
  229. */
  230. public void testWatchesFiltersLinkedList() {
  231. EditorOperator eo = new EditorOperator("MemoryView.java");
  232. Utilities.toggleBreakpoint(eo, 76);
  233. Utilities.startDebugger();
  234. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  235. createWatch("llist");
  236. createWatch("llist.toString()");
  237. createWatch("llist.getFirst()");
  238. createWatch("llist.getLast()");
  239. createWatch("llist.get(1)");
  240. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  241. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  242. checkOutlineTableLine(outlineOp, 0, "llist", "LinkedList", null);
  243. assertTrue("Node \'llist\' has no child nodes", hasChildNodes("llist", outlineOp));
  244. checkOutlineTableLine(outlineOp, 1, "llist.toString()", "String", "\"[0. item, 1. item, 2. item, 3. item, 4. item, 5. item, 6. item, 7. item, 8. item, 9. item, 10. item, 11. item, 12. item, 13. item, 14. item, 15. item, 16. item, 17. item, 18. item, 19. item, 20. item, 21. item, 22. item, 23. item, 24. item, 25. item, 26. item, 27. item, 28. item, 29. item, 30. item, 31. item, 32. item, 33. item, 34. item, 35. item, 36. item, 37. item, 38. item, 39. item, 40. item, 41. item, 42. item, 43. item, 44. item, 45. item, 46. item, 47. item, 48. item, 49. item]\"");
  245. checkOutlineTableLine(outlineOp, 2, "llist.getFirst()", "String", "\"0. item\"");
  246. checkOutlineTableLine(outlineOp, 3, "llist.getLast()", "String", "\"49. item\"");
  247. checkOutlineTableLine(outlineOp, 4, "llist.get(1)", "String", "\"1. item\"");
  248. }
  249. /**
  250. *
  251. */
  252. public void testWatchesFiltersArrayList() {
  253. EditorOperator eo = new EditorOperator("MemoryView.java");
  254. Utilities.toggleBreakpoint(eo, 76);
  255. Utilities.startDebugger();
  256. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  257. createWatch("alist");
  258. createWatch("alist.toString()");
  259. createWatch("alist.get(2)");
  260. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  261. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  262. checkOutlineTableLine(outlineOp, 0, "alist", "ArrayList", null);
  263. assertTrue("Node \'alist\' has no child nodes", hasChildNodes("alist", outlineOp));
  264. checkOutlineTableLine(outlineOp, 1, "alist.toString()", "String", "\"[0. item, 1. item, 2. item, 3. item, 4. item, 5. item, 6. item, 7. item, 8. item, 9. item, 10. item, 11. item, 12. item, 13. item, 14. item, 15. item, 16. item, 17. item, 18. item, 19. item, 20. item, 21. item, 22. item, 23. item, 24. item, 25. item, 26. item, 27. item, 28. item, 29. item, 30. item, 31. item, 32. item, 33. item, 34. item, 35. item, 36. item, 37. item, 38. item, 39. item, 40. item, 41. item, 42. item, 43. item, 44. item, 45. item, 46. item, 47. item, 48. item, 49. item]\"");
  265. checkOutlineTableLine(outlineOp, 2, "alist.get(2)", "String", "\"2. item\"");
  266. }
  267. /**
  268. *
  269. */
  270. public void testWatchesFiltersVector() {
  271. EditorOperator eo = new EditorOperator("MemoryView.java");
  272. Utilities.toggleBreakpoint(eo, 76);
  273. Utilities.startDebugger();
  274. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  275. createWatch("vec");
  276. createWatch("vec.toString()");
  277. createWatch("vec.get(3)");
  278. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  279. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  280. checkOutlineTableLine(outlineOp, 0, "vec", "Vector", null);
  281. assertTrue("Node \'vec\' has no child nodes", hasChildNodes("vec", outlineOp));
  282. checkOutlineTableLine(outlineOp, 1, "vec.toString()", "String", "\"[0. item, 1. item, 2. item, 3. item, 4. item, 5. item, 6. item, 7. item, 8. item, 9. item, 10. item, 11. item, 12. item, 13. item, 14. item, 15. item, 16. item, 17. item, 18. item, 19. item, 20. item, 21. item, 22. item, 23. item, 24. item, 25. item, 26. item, 27. item, 28. item, 29. item, 30. item, 31. item, 32. item, 33. item, 34. item, 35. item, 36. item, 37. item, 38. item, 39. item, 40. item, 41. item, 42. item, 43. item, 44. item, 45. item, 46. item, 47. item, 48. item, 49. item]\"");
  283. checkOutlineTableLine(outlineOp, 2, "vec.get(3)", "String", "\"3. item\"");
  284. }
  285. /**
  286. *
  287. */
  288. public void testWatchesFiltersHashMap() {
  289. EditorOperator eo = new EditorOperator("MemoryView.java");
  290. Utilities.toggleBreakpoint(eo, 76);
  291. Utilities.startDebugger();
  292. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  293. createWatch("hmap");
  294. createWatch("hmap.containsKey(\"4\")");
  295. createWatch("hmap.get(\"5\")");
  296. createWatch("hmap.put(\"6\",\"test\")");
  297. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  298. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  299. checkOutlineTableLine(outlineOp, 0, "hmap", "HashMap", null);
  300. assertTrue("Node \'hmap\' has no child nodes", hasChildNodes("hmap", outlineOp));
  301. checkOutlineTableLine(outlineOp, 1, "hmap.containsKey(\"4\")", "boolean", "true");
  302. checkOutlineTableLine(outlineOp, 2, "hmap.get(\"5\")", "String", "\"5. item\"");
  303. checkOutlineTableLine(outlineOp, 3, "hmap.put(\"6\",\"test\")", "String", "\"6. item\"");
  304. }
  305. /**
  306. *
  307. */
  308. public void testWatchesFiltersHashtable() {
  309. EditorOperator eo = new EditorOperator("MemoryView.java");
  310. Utilities.toggleBreakpoint(eo, 76);
  311. Utilities.startDebugger();
  312. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  313. createWatch("htab");
  314. createWatch("htab.containsKey(\"7\")");
  315. createWatch("htab.get(\"9\")");
  316. createWatch("htab.put(\"10\", \"test\")");
  317. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  318. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  319. checkOutlineTableLine(outlineOp, 0, "htab", "Hashtable", null);
  320. assertTrue("Node \'htab\' has no child nodes", hasChildNodes("htab", outlineOp));
  321. checkOutlineTableLine(outlineOp, 1, "htab.containsKey(\"7\")", "boolean", "true");
  322. checkOutlineTableLine(outlineOp, 2, "htab.get(\"9\")", "String", "\"9. item\"");
  323. checkOutlineTableLine(outlineOp, 3, "htab.put(\"10\", \"test\")", "String", "\"10. item\"");
  324. }
  325. /**
  326. *
  327. */
  328. public void testWatchesFiltersTreeMap() {
  329. EditorOperator eo = new EditorOperator("MemoryView.java");
  330. Utilities.toggleBreakpoint(eo, 76);
  331. Utilities.startDebugger();
  332. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  333. createWatch("tmap");
  334. createWatch("tmap.containsKey(\"11\")");
  335. createWatch("tmap.get(\"12\")");
  336. createWatch("tmap.put(\"13\",\"test\")");
  337. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  338. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  339. checkOutlineTableLine(outlineOp, 0, "tmap", "TreeMap", null);
  340. assertTrue("Node \'tmap\' has no child nodes", hasChildNodes("tmap", outlineOp));
  341. checkOutlineTableLine(outlineOp, 1, "tmap.containsKey(\"11\")", "boolean", "true");
  342. checkOutlineTableLine(outlineOp, 2, "tmap.get(\"12\")", "String", "\"12. item\"");
  343. checkOutlineTableLine(outlineOp, 3, "tmap.put(\"13\",\"test\")", "String", "\"13. item\"");
  344. }
  345. /**
  346. *
  347. */
  348. public void testWatchesFiltersTreeSet() {
  349. EditorOperator eo = new EditorOperator("MemoryView.java");
  350. Utilities.toggleBreakpoint(eo, 76);
  351. Utilities.startDebugger();
  352. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  353. createWatch("tset");
  354. createWatch("tset.contains(\"14. item\")");
  355. createWatch("tset.iterator()");
  356. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  357. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  358. checkOutlineTableLine(outlineOp, 0, "tset", "TreeSet", null);
  359. assertTrue("Node \'tset\' has no child nodes", hasChildNodes("tset", outlineOp));
  360. checkOutlineTableLine(outlineOp, 1, "tset.contains(\"14. item\")", "boolean", "true");
  361. checkOutlineTableLine(outlineOp, 2, "tset.iterator()", "TreeMap$KeyIterator", null);
  362. }
  363. /**
  364. *
  365. */
  366. public void testWatchesFilters1DArray() {
  367. EditorOperator eo = new EditorOperator("MemoryView.java");
  368. Utilities.toggleBreakpoint(eo, 76);
  369. Utilities.startDebugger();
  370. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  371. createWatch("policko");
  372. createWatch("policko.length");
  373. createWatch("policko[1]");
  374. createWatch("policko[10]");
  375. createWatch("pole");
  376. createWatch("pole.length");
  377. createWatch("pole[1]");
  378. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  379. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  380. checkOutlineTableLine(outlineOp, 0, "policko", "int[]", null);
  381. assertTrue("Node \'policko\' has no child nodes", hasChildNodes("policko", outlineOp));
  382. checkOutlineTableLine(outlineOp, 1, "policko.length", "int", "5");
  383. checkOutlineTableLine(outlineOp, 2, "policko[1]", "int", "2");
  384. checkOutlineTableLine(outlineOp, 3, "policko[10]", null, ">Array index \"10\" is out of range <0,4><");
  385. checkOutlineTableLine(outlineOp, 4, "pole", "int[]", null);
  386. assertTrue("Node \'pole\' has no child nodes", hasChildNodes("pole", outlineOp));
  387. checkOutlineTableLine(outlineOp, 5, "pole.length", "int", "50");
  388. checkOutlineTableLine(outlineOp, 6, "pole[1]", "int", "0");
  389. }
  390. /**
  391. *
  392. */
  393. public void testWatchesFilters2DArray() {
  394. EditorOperator eo = new EditorOperator("MemoryView.java");
  395. Utilities.toggleBreakpoint(eo, 76);
  396. Utilities.startDebugger();
  397. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:76");
  398. createWatch("d2");
  399. createWatch("d2.length");
  400. createWatch("d2[1]");
  401. createWatch("d2[1].length");
  402. createWatch("d2[1][1]");
  403. createWatch("d2[15].length");
  404. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  405. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  406. checkOutlineTableLine(outlineOp, 0, "d2", "int[][]", null);
  407. assertTrue("Node \'d2\' has no child nodes", hasChildNodes("d2", outlineOp));
  408. checkOutlineTableLine(outlineOp, 1, "d2.length", "int", "10");
  409. checkOutlineTableLine(outlineOp, 2, "d2[1]", "int[]", null);
  410. assertTrue("Node \'d2[1]\' has no child nodes", hasChildNodes("d2[1]", outlineOp));
  411. checkOutlineTableLine(outlineOp, 3, "d2[1].length", "int", "20");
  412. checkOutlineTableLine(outlineOp, 4, "d2[1][1]", "int", "0");
  413. checkOutlineTableLine(outlineOp, 5, "d2[15].length", null, ">Array index \"15\" is out of range <0,9><");
  414. }
  415. /**
  416. *
  417. */
  418. public void testWatchesValues() {
  419. EditorOperator eo = new EditorOperator("MemoryView.java");
  420. Utilities.toggleBreakpoint(eo, 104);
  421. Utilities.startDebugger();
  422. Utilities.checkConsoleLastLineForText("Thread main stopped at MemoryView.java:104");
  423. createWatch("free");
  424. createWatch("taken");
  425. createWatch("total");
  426. createWatch("this");
  427. Utilities.showDebuggerView(Utilities.watchesViewTitle);
  428. OutlineOperator outlineOp = new OutlineOperator(new TopComponentOperator(Utilities.watchesViewTitle));
  429. Node.Property property;
  430. int count = 0;
  431. try {
  432. if (!("free".equals(outlineOp.getValueAt(count,0).toString())))
  433. assertTrue("Watch for expression \'free\' was not created", false);
  434. property = (Node.Property)outlineOp.getValueAt(count,1);
  435. if (!("long".equals(property.getValue())))
  436. assertTrue("Watch type for expression \'free\' is " + property.getValue() + ", should be long", false);
  437. property = (Node.Property)outlineOp.getValueAt(count++,2);
  438. long free = Long.parseLong(property.getValue().toString());
  439. if (!("taken".equals(outlineOp.getValueAt(count,0).toString())))
  440. assertTrue("Watch for expression \'taken\' was not created", false);
  441. property = (Node.Property)outlineOp.getValueAt(count,1);
  442. if (!("int".equals(property.getValue())))
  443. assertTrue("Watch type for expression \'taken\' is " + property.getValue() + ", should be long", false);
  444. property = (Node.Property)outlineOp.getValueAt(count++,2);
  445. long taken = Long.parseLong(property.getValue().toString());
  446. if (!("total".equals(outlineOp.getValueAt(count,0).toString())))
  447. assertTrue("Watch for expression \'total\' was not created", false);
  448. property = (Node.Property)outlineOp.getValueAt(count,1);
  449. if (!("long".equals(property.getValue())))
  450. assertTrue("Watch type for expression \'total\' is " + property.getValue() + ", should be long", false);
  451. property = (Node.Property)outlineOp.getValueAt(count++,2);
  452. long total = Long.parseLong(property.getValue().toString());
  453. assertTrue("Watches values does not seem to be correct (total != free + taken)", total == free + taken);
  454. if (!("this".equals(outlineOp.getValueAt(count,0).toString())))
  455. assertTrue("Watch for expression \'this\' was not created", false);
  456. property = (Node.Property)outlineOp.getValueAt(count,1);
  457. if (!("MemoryView".equals(property.getValue())))
  458. assertTrue("Watch type for expression \'this\' is " + property.getValue() + ", should be MemoryView", false);
  459. assertTrue("Watch this has no child nodes", hasChildNodes("this", outlineOp));
  460. } catch (java.lang.IllegalAccessException e1) {
  461. assertTrue(e1.getMessage(), false);
  462. } catch (java.lang.reflect.InvocationTargetException e2) {
  463. assertTrue(e2.getMessage(), false);
  464. }
  465. }
  466. /**
  467. *
  468. * @param exp
  469. */
  470. protected void createWatch(String exp) {
  471. new ActionNoBlock(Utilities.runMenu + "|" + Utilities.newWatchItem, null).perform();
  472. NbDialogOperator dialog = new NbDialogOperator(Utilities.newWatchTitle);
  473. new JEditorPaneOperator(dialog, 0).setText(exp);
  474. dialog.ok();
  475. try {
  476. new Waiter(new Waitable() {
  477. public Object actionProduced(Object dialog) {
  478. NbDialogOperator op = (NbDialogOperator)dialog;
  479. if (!op.isVisible()) {
  480. return Boolean.TRUE;
  481. }
  482. return null;
  483. }
  484. public String getDescription() {
  485. return "Wait new watch dialog is closed";
  486. }
  487. }).waitAction(dialog);
  488. } catch (InterruptedException ex) {
  489. ex.printStackTrace();
  490. }
  491. }
  492. /**
  493. *
  494. * @param table
  495. * @param lineNumber
  496. * @param name
  497. * @param type
  498. * @param value
  499. */
  500. protected void checkOutlineTableLine(OutlineOperator outline, int lineNumber, String name, String type, String value) {
  501. try {
  502. outline.scrollToCell(lineNumber, 0);
  503. org.openide.nodes.Node.Property property;
  504. String string = null;
  505. assertTrue("Node " + name + " not displayed in Watches view", name.equals(outline.getValueAt(lineNumber, 0).toString()));
  506. property = (org.openide.nodes.Node.Property)outline.getValueAt(lineNumber, 1);
  507. string = property.getValue().toString();
  508. int maxWait = 100;
  509. while (string.equals(Utilities.evaluatingPropertyText) && maxWait > 0) {
  510. new EventTool().waitNoEvent(300);
  511. maxWait--;
  512. }
  513. assertTrue("Node " + name + " has wrong type in Watches view (displayed: " + string + ", expected: " + type + ")",
  514. (type == null) || type.length() == 0 || type.equals(string));
  515. property = (org.openide.nodes.Node.Property)outline.getValueAt(lineNumber, 2);
  516. string = property.getValue().toString();
  517. maxWait = 100;
  518. while (string.equals(Utilities.evaluatingPropertyText) && maxWait > 0) {
  519. new EventTool().waitNoEvent(300);
  520. maxWait--;
  521. }
  522. assertTrue("Node " + name + " has wrong value in Watches view (displayed: " + string + ", expected: " + value + ")",
  523. (type == null) || !type.equals(string));
  524. } catch (java.lang.IllegalAccessException e1) {
  525. assertTrue(e1.getMessage(), false);
  526. } catch (java.lang.reflect.InvocationTargetException e2) {
  527. assertTrue(e2.getMessage(), false);
  528. }
  529. }
  530. protected boolean hasChildNodes(String nodePath, OutlineOperator outlineOp) {
  531. OutlineNode node = new OutlineNode(outlineOp, nodePath);
  532. node.select();
  533. return !node.isLeaf();
  534. }
  535. }