/jdk/test/com/sun/jdi/sde/TemperatureTableTest.java

https://github.com/Morriar/ProxyJDK · Java · 502 lines · 365 code · 106 blank · 31 comment · 29 complexity · b889a555778d95ef91ae3b6e7dc91404 MD5 · raw file

  1. /**
  2. * @test
  3. * @bug 4390869
  4. * @bug 4460328
  5. * @summary Test the new SourceDebugExtension facility
  6. *
  7. * @author Robert Field
  8. *
  9. * @library ..
  10. * @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE
  11. * @run compile TemperatureTableTest.java
  12. * @run compile -g TemperatureTableServlet.java
  13. * @run main TemperatureTableTest
  14. */
  15. import com.sun.jdi.*;
  16. import com.sun.jdi.event.*;
  17. import com.sun.jdi.request.*;
  18. import java.util.*;
  19. import java.io.File;
  20. public class TemperatureTableTest extends TestScaffold {
  21. ReferenceType targetClass;
  22. TemperatureTableTest (String args[]) {
  23. super(args);
  24. }
  25. public static void main(String[] args) throws Exception {
  26. testSetUp();
  27. new TemperatureTableTest(args).startTests();
  28. }
  29. /********** test set-up **********/
  30. static void testSetUp() throws Exception {
  31. InstallSDE.install(new File(System.getProperty("test.classes", "."),
  32. "TemperatureTableServlet.class"),
  33. new File(System.getProperty("test.src", "."),
  34. "TemperatureTable.sde"));
  35. }
  36. /********** test assist **********/
  37. void checkLocation(Location loc, String label,
  38. String expectedSourceName,
  39. String expectedSourcePath,
  40. int expectedLinenumber) throws Exception {
  41. String sourceName = loc.sourceName();
  42. if (sourceName.equals(expectedSourceName)) {
  43. println(label + " sourceName: " + sourceName);
  44. } else {
  45. failure("FAIL: " + label +
  46. " expected sourceName " + expectedSourceName +
  47. " got - " + sourceName);
  48. }
  49. String sourcePath = loc.sourcePath();
  50. if (sourcePath.equals(expectedSourcePath)) {
  51. println(label + " sourcePath: " + sourcePath);
  52. } else {
  53. failure("FAIL: " + label +
  54. " expected sourcePath " + expectedSourcePath +
  55. " got - " + sourcePath);
  56. }
  57. int ln = loc.lineNumber();
  58. if (ln == expectedLinenumber) {
  59. println(label + " line number: " + ln);
  60. } else {
  61. failure("FAIL: " + label +
  62. " expected line number " + expectedLinenumber +
  63. " got - " + ln);
  64. }
  65. }
  66. void checkLocation(String stratum, Location loc, String label,
  67. String expectedSourceName,
  68. String expectedSourcePath,
  69. int expectedLinenumber) throws Exception {
  70. String sourceName = loc.sourceName(stratum);
  71. if (sourceName.equals(expectedSourceName)) {
  72. println(label + "(" + stratum + ")" +
  73. " sourceName: " + sourceName);
  74. } else {
  75. failure("FAIL: " + label + "(" + stratum + ")" +
  76. " expected sourceName " + expectedSourceName +
  77. " got " + sourceName);
  78. }
  79. String sourcePath = loc.sourcePath(stratum);
  80. if (sourcePath.equals(expectedSourcePath)) {
  81. println(label + "(" + stratum + ")" +
  82. " sourcePath: " + sourcePath);
  83. } else {
  84. failure("FAIL: " + label + "(" + stratum + ")" +
  85. " expected sourcePath " + expectedSourcePath +
  86. " got " + sourcePath);
  87. }
  88. int ln = loc.lineNumber(stratum);
  89. if (ln == expectedLinenumber) {
  90. println(label + "(" + stratum + ")" +
  91. " line number: " + ln);
  92. } else {
  93. failure("FAIL: " + label + "(" + stratum + ")" +
  94. " expected line number " + expectedLinenumber +
  95. " got " + ln);
  96. }
  97. }
  98. /********** test core **********/
  99. protected void runTests() throws Exception {
  100. /*
  101. * Get to the top of main()
  102. * to determine targetClass
  103. */
  104. BreakpointEvent bpe = startToMain("TemperatureTableServlet");
  105. targetClass = bpe.location().declaringType();
  106. if (!vm().canGetSourceDebugExtension()) {
  107. failure("FAIL: canGetSourceDebugExtension() is false");
  108. } else {
  109. println("canGetSourceDebugExtension() is true");
  110. }
  111. checkLocation(bpe.location(), "main BP",
  112. "TemperatureTable.jsp",
  113. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  114. checkLocation("JSP", bpe.location(), "main BP",
  115. "TemperatureTable.jsp",
  116. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  117. checkLocation("bogus", bpe.location(), "main BP",
  118. "TemperatureTable.jsp",
  119. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  120. checkLocation(null, bpe.location(), "main BP",
  121. "TemperatureTable.jsp",
  122. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  123. checkLocation("Java", bpe.location(), "main BP",
  124. "TemperatureTableServlet.java",
  125. "TemperatureTableServlet.java", 11);
  126. // ref type source name
  127. String sourceName = targetClass.sourceName();
  128. if (sourceName.equals("TemperatureTable.jsp")) {
  129. println("ref type sourceName: " + sourceName);
  130. } else {
  131. failure("FAIL: unexpected ref type sourceName - " + sourceName);
  132. }
  133. List allLines = targetClass.allLineLocations();
  134. for (Iterator it = allLines.iterator(); it.hasNext(); ) {
  135. Location loc = (Location)it.next();
  136. println("Location: " + loc);
  137. }
  138. List locs = targetClass.locationsOfLine(7);
  139. if (locs.size() != 1) {
  140. failure("FAIL: expect on elocation, got " + locs.size());
  141. }
  142. Location loc7 = (Location)locs.get(0);
  143. checkLocation(loc7, "line7",
  144. "TemperatureTable.jsp",
  145. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  146. checkLocation("JSP", loc7, "line7",
  147. "TemperatureTable.jsp",
  148. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  149. checkLocation("bogus", loc7, "line7",
  150. "TemperatureTable.jsp",
  151. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  152. checkLocation(null, loc7, "line7",
  153. "TemperatureTable.jsp",
  154. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  155. checkLocation("Java", loc7, "line7",
  156. "TemperatureTableServlet.java",
  157. "TemperatureTableServlet.java", 28);
  158. List availSt = targetClass.availableStrata();
  159. List avail = new ArrayList(availSt);
  160. if (avail.size() == 2 &&
  161. avail.remove("JSP") &&
  162. avail.remove("Java") &&
  163. avail.size() == 0) {
  164. println("availableStrata: " + availSt);
  165. } else {
  166. failure("FAIL: unexpected availableStrata - " + availSt);
  167. }
  168. String def = targetClass.defaultStratum();
  169. if (def.equals("JSP")) {
  170. println("defaultStratum: " + def);
  171. } else {
  172. failure("FAIL: unexpected defaultStratum - " + def);
  173. }
  174. // Test HelloWorld
  175. BreakpointEvent bpHello = resumeTo("HelloWorld", "main",
  176. "([Ljava/lang/String;)V");
  177. Location hello = bpHello.location();
  178. checkLocation(hello, "hello BP",
  179. "HelloWorld.java",
  180. "HelloWorld.java", 3);
  181. checkLocation("JSP", hello, "hello BP",
  182. "HelloWorld.java",
  183. "HelloWorld.java", 3);
  184. checkLocation("bogus", hello, "hello BP",
  185. "HelloWorld.java",
  186. "HelloWorld.java", 3);
  187. checkLocation(null, hello, "hello BP",
  188. "HelloWorld.java",
  189. "HelloWorld.java", 3);
  190. checkLocation("Java", hello, "hello BP",
  191. "HelloWorld.java",
  192. "HelloWorld.java", 3);
  193. /******** test VM default *************/
  194. vm().setDefaultStratum("Java");
  195. println("VM default set to Java");
  196. checkLocation(bpe.location(), "main BP",
  197. "TemperatureTableServlet.java",
  198. "TemperatureTableServlet.java", 11);
  199. checkLocation("JSP", bpe.location(), "main BP",
  200. "TemperatureTable.jsp",
  201. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  202. checkLocation("bogus", bpe.location(), "main BP",
  203. "TemperatureTable.jsp",
  204. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  205. checkLocation(null, bpe.location(), "main BP",
  206. "TemperatureTable.jsp",
  207. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  208. checkLocation("Java", bpe.location(), "main BP",
  209. "TemperatureTableServlet.java",
  210. "TemperatureTableServlet.java", 11);
  211. checkLocation(loc7, "line7",
  212. "TemperatureTableServlet.java",
  213. "TemperatureTableServlet.java", 28);
  214. checkLocation("JSP", loc7, "line7",
  215. "TemperatureTable.jsp",
  216. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  217. checkLocation("bogus", loc7, "line7",
  218. "TemperatureTable.jsp",
  219. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  220. checkLocation(null, loc7, "line7",
  221. "TemperatureTable.jsp",
  222. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  223. checkLocation("Java", loc7, "line7",
  224. "TemperatureTableServlet.java",
  225. "TemperatureTableServlet.java", 28);
  226. checkLocation(hello, "hello BP",
  227. "HelloWorld.java",
  228. "HelloWorld.java", 3);
  229. checkLocation("JSP", hello, "hello BP",
  230. "HelloWorld.java",
  231. "HelloWorld.java", 3);
  232. checkLocation("bogus", hello, "hello BP",
  233. "HelloWorld.java",
  234. "HelloWorld.java", 3);
  235. checkLocation(null, hello, "hello BP",
  236. "HelloWorld.java",
  237. "HelloWorld.java", 3);
  238. checkLocation("Java", hello, "hello BP",
  239. "HelloWorld.java",
  240. "HelloWorld.java", 3);
  241. vm().setDefaultStratum(null);
  242. println("VM default set to null");
  243. checkLocation(bpe.location(), "main BP",
  244. "TemperatureTable.jsp",
  245. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  246. checkLocation("JSP", bpe.location(), "main BP",
  247. "TemperatureTable.jsp",
  248. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  249. checkLocation("bogus", bpe.location(), "main BP",
  250. "TemperatureTable.jsp",
  251. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  252. checkLocation(null, bpe.location(), "main BP",
  253. "TemperatureTable.jsp",
  254. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  255. checkLocation("Java", bpe.location(), "main BP",
  256. "TemperatureTableServlet.java",
  257. "TemperatureTableServlet.java", 11);
  258. checkLocation(loc7, "line7",
  259. "TemperatureTable.jsp",
  260. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  261. checkLocation("JSP", loc7, "line7",
  262. "TemperatureTable.jsp",
  263. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  264. checkLocation("bogus", loc7, "line7",
  265. "TemperatureTable.jsp",
  266. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  267. checkLocation(null, loc7, "line7",
  268. "TemperatureTable.jsp",
  269. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  270. checkLocation("Java", loc7, "line7",
  271. "TemperatureTableServlet.java",
  272. "TemperatureTableServlet.java", 28);
  273. checkLocation(hello, "hello BP",
  274. "HelloWorld.java",
  275. "HelloWorld.java", 3);
  276. checkLocation("JSP", hello, "hello BP",
  277. "HelloWorld.java",
  278. "HelloWorld.java", 3);
  279. checkLocation("bogus", hello, "hello BP",
  280. "HelloWorld.java",
  281. "HelloWorld.java", 3);
  282. checkLocation(null, hello, "hello BP",
  283. "HelloWorld.java",
  284. "HelloWorld.java", 3);
  285. checkLocation("Java", hello, "hello BP",
  286. "HelloWorld.java",
  287. "HelloWorld.java", 3);
  288. vm().setDefaultStratum("bogus");
  289. println("VM default set to bogus");
  290. checkLocation(bpe.location(), "main BP",
  291. "TemperatureTable.jsp",
  292. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  293. checkLocation("JSP", bpe.location(), "main BP",
  294. "TemperatureTable.jsp",
  295. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  296. checkLocation("bogus", bpe.location(), "main BP",
  297. "TemperatureTable.jsp",
  298. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  299. checkLocation(null, bpe.location(), "main BP",
  300. "TemperatureTable.jsp",
  301. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  302. checkLocation("Java", bpe.location(), "main BP",
  303. "TemperatureTableServlet.java",
  304. "TemperatureTableServlet.java", 11);
  305. checkLocation(loc7, "line7",
  306. "TemperatureTable.jsp",
  307. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  308. checkLocation("JSP", loc7, "line7",
  309. "TemperatureTable.jsp",
  310. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  311. checkLocation("bogus", loc7, "line7",
  312. "TemperatureTable.jsp",
  313. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  314. checkLocation(null, loc7, "line7",
  315. "TemperatureTable.jsp",
  316. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  317. checkLocation("Java", loc7, "line7",
  318. "TemperatureTableServlet.java",
  319. "TemperatureTableServlet.java", 28);
  320. checkLocation(hello, "hello BP",
  321. "HelloWorld.java",
  322. "HelloWorld.java", 3);
  323. checkLocation("JSP", hello, "hello BP",
  324. "HelloWorld.java",
  325. "HelloWorld.java", 3);
  326. checkLocation("bogus", hello, "hello BP",
  327. "HelloWorld.java",
  328. "HelloWorld.java", 3);
  329. checkLocation(null, hello, "hello BP",
  330. "HelloWorld.java",
  331. "HelloWorld.java", 3);
  332. checkLocation("Java", hello, "hello BP",
  333. "HelloWorld.java",
  334. "HelloWorld.java", 3);
  335. vm().setDefaultStratum("JSP");
  336. println("VM default set to JSP");
  337. checkLocation(bpe.location(), "main BP",
  338. "TemperatureTable.jsp",
  339. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  340. checkLocation("JSP", bpe.location(), "main BP",
  341. "TemperatureTable.jsp",
  342. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  343. checkLocation("bogus", bpe.location(), "main BP",
  344. "TemperatureTable.jsp",
  345. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  346. checkLocation(null, bpe.location(), "main BP",
  347. "TemperatureTable.jsp",
  348. "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
  349. checkLocation("Java", bpe.location(), "main BP",
  350. "TemperatureTableServlet.java",
  351. "TemperatureTableServlet.java", 11);
  352. checkLocation(loc7, "line7",
  353. "TemperatureTable.jsp",
  354. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  355. checkLocation("JSP", loc7, "line7",
  356. "TemperatureTable.jsp",
  357. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  358. checkLocation("bogus", loc7, "line7",
  359. "TemperatureTable.jsp",
  360. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  361. checkLocation(null, loc7, "line7",
  362. "TemperatureTable.jsp",
  363. "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
  364. checkLocation("Java", loc7, "line7",
  365. "TemperatureTableServlet.java",
  366. "TemperatureTableServlet.java", 28);
  367. checkLocation(hello, "hello BP",
  368. "HelloWorld.java",
  369. "HelloWorld.java", 3);
  370. checkLocation("JSP", hello, "hello BP",
  371. "HelloWorld.java",
  372. "HelloWorld.java", 3);
  373. checkLocation("bogus", hello, "hello BP",
  374. "HelloWorld.java",
  375. "HelloWorld.java", 3);
  376. checkLocation(null, hello, "hello BP",
  377. "HelloWorld.java",
  378. "HelloWorld.java", 3);
  379. checkLocation("Java", hello, "hello BP",
  380. "HelloWorld.java",
  381. "HelloWorld.java", 3);
  382. /*
  383. * resume the target listening for events
  384. */
  385. listenUntilVMDisconnect();
  386. /*
  387. * deal with results of test
  388. * if anything has called failure("foo") testFailed will be true
  389. */
  390. if (!testFailed) {
  391. println("TemperatureTableTest: passed");
  392. } else {
  393. throw new Exception("TemperatureTableTest: failed");
  394. }
  395. }
  396. }