您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JvstTest.java 44KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. package javassist;
  2. import junit.framework.*;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.InputStream;
  6. import java.lang.reflect.Method;
  7. import javassist.bytecode.*;
  8. import javassist.expr.*;
  9. import javassist.runtime.*;
  10. @SuppressWarnings({"rawtypes","unused", "resource"})
  11. public class JvstTest extends JvstTestRoot {
  12. public static boolean java9;
  13. static {
  14. //javassist.bytecode.MethodInfo.doPreverify = true;
  15. java9 = javassist.bytecode.ClassFile.MAJOR_VERSION
  16. >= javassist.bytecode.ClassFile.JAVA_9;
  17. }
  18. public JvstTest(String name) {
  19. super(name);
  20. }
  21. public void testConfig() {
  22. // is the value of PATH correct?
  23. assertTrue("not found " + PATH, new java.io.File(PATH).exists());
  24. }
  25. public void testLoader() throws Exception {
  26. Loader loader = new Loader(sloader);
  27. loader.delegateLoadingOf("test1.");
  28. assertEquals(loader.loadClass("test1.Cflow").getClassLoader(),
  29. loader.getParent());
  30. assertEquals(loader.loadClass("javassist.Loader").getClassLoader(),
  31. loader.getParent());
  32. assertEquals(loader.loadClass("javassist.CtClass").getClassLoader(),
  33. loader);
  34. }
  35. public void testDefreeze() throws Exception {
  36. CtClass cc = sloader.get("test1.Freeze");
  37. cc.stopPruning(true);
  38. cc.addInterface(sloader.get("java.io.Serializable"));
  39. assertTrue(!cc.isFrozen());
  40. cc.writeFile();
  41. assertTrue(cc.isFrozen());
  42. cc.defrost();
  43. assertTrue(!cc.isFrozen());
  44. }
  45. public void testClassPath() throws Exception {
  46. ClassPool pool = new ClassPool(null);
  47. ClassPath cp1 = pool.appendClassPath("d1");
  48. ClassPath cp2 = pool.appendClassPath("d2");
  49. ClassPath cp3 = pool.appendClassPath("d3");
  50. ClassPath cp4 = pool.appendClassPath("d4");
  51. print(pool.toString());
  52. pool.removeClassPath(cp3);
  53. print(pool.toString());
  54. pool.removeClassPath(cp4);
  55. print(pool.toString());
  56. pool.removeClassPath(cp2);
  57. print(pool.toString());
  58. pool.removeClassPath(cp1);
  59. assertTrue("[class path: ]".equals(pool.toString()));
  60. }
  61. public void testReleaseJarClassPathFileHandle() throws Exception {
  62. String jarFileName = "./empty.jar";
  63. ClassLoader classLoader = getClass().getClassLoader();
  64. File jarFile = new File(classLoader.getResource(jarFileName).getFile());
  65. assertTrue(jarFile.exists());
  66. // Prepare class pool and force it to open the Jar file
  67. ClassPool pool = ClassPool.getDefault();
  68. ClassPath cp = pool.appendClassPath(jarFile.getAbsolutePath());
  69. assertNull(cp.openClassfile("nothere.Dummy"));
  70. // Assert that it is possible to delete the jar file.
  71. // On Windows deleting an open file will fail, while on on Mac/Linux this is always possible.
  72. // This check will thus only fail on Windos if the file is still open.
  73. assertTrue(jarFile.delete());
  74. }
  75. public void testJarClassPath() throws Exception {
  76. String jarFileName = "./simple.jar";
  77. ClassLoader classLoader = getClass().getClassLoader();
  78. File jarFile = new File(classLoader.getResource(jarFileName).getFile());
  79. assertTrue(jarFile.exists());
  80. ClassPool pool = ClassPool.getDefault();
  81. ClassPath cp = pool.appendClassPath(jarFile.getAbsolutePath());
  82. InputStream is = cp.openClassfile("com.test.Test");
  83. assertNotNull(is);
  84. is.close();
  85. }
  86. public void testSubtype() throws Exception {
  87. CtClass cc = sloader.get("test1.Subtype");
  88. assertTrue(cc.subtypeOf(cc));
  89. assertTrue(cc.subtypeOf(sloader.get("test1.SubtypeA")));
  90. assertTrue(cc.subtypeOf(sloader.get("test1.SubtypeB")));
  91. assertTrue(cc.subtypeOf(sloader.get("test1.SubtypeC")));
  92. assertTrue(cc.subtypeOf(sloader.get("java.lang.Object")));
  93. assertTrue(!cc.subtypeOf(sloader.get("java.lang.String")));
  94. }
  95. public void testClassPoolGet() throws Exception {
  96. ClassPool pool = ClassPool.getDefault();
  97. CtClass cc = pool.makeClass("test1.Point");
  98. CtClass cc1 = pool.get("test1.Point"); // cc1 is identical to cc.
  99. cc.setName("test1.Pair");
  100. CtClass cc2 = pool.get("test1.Pair"); // cc2 is identical to cc.
  101. CtClass cc3 = pool.get("test1.Point"); // cc3 is not identical to cc.
  102. assertTrue(cc == cc1);
  103. assertTrue(cc == cc2);
  104. assertTrue(cc != cc3);
  105. assertEquals("test1.Pair", cc.getName());
  106. assertEquals("test1.Point", cc3.getName());
  107. }
  108. public static long testFieldInitHash;
  109. /* test CodeIterator.insertExGap().
  110. * The result of this test is checked again by JvstTest3#testFieldInitAgain().
  111. */
  112. public void testFieldInit() throws Exception {
  113. CtClass cc = sloader.get("test1.FieldInit");
  114. CtField f1 = new CtField(CtClass.intType, "f1", cc);
  115. cc.addField(f1, CtField.Initializer.byCall(cc, "get"));
  116. CtField f2 = CtField.make("public int f2 = 3;", cc);
  117. cc.addField(f2);
  118. CtField f3 = CtField.make("public int f3;", cc);
  119. cc.addField(f3);
  120. testFieldInitHash = f1.hashCode();
  121. cc.writeFile();
  122. Object obj = make(cc.getName());
  123. int value = obj.getClass().getField("counter").getInt(obj);
  124. assertEquals(1, value);
  125. int value2 = obj.getClass().getField("f2").getInt(obj);
  126. assertEquals(3, value2);
  127. int value3 = obj.getClass().getField("f3").getInt(obj);
  128. assertEquals(0, value3);
  129. }
  130. /* test CodeIterator.insertExGap().
  131. */
  132. public void testFieldInit2() throws Exception {
  133. CtClass cc = sloader.get("test1.FieldInit2");
  134. CtField f = new CtField(CtClass.intType, "f1", cc);
  135. cc.addField(f, CtField.Initializer.byCall(cc, "get"));
  136. cc.writeFile();
  137. try {
  138. Object obj = make(cc.getName());
  139. fail();
  140. }
  141. catch (Exception e) {
  142. print("testFieldInit2: catch");
  143. }
  144. }
  145. public static CtMethod testCalleeBeforeMethod;
  146. public static long testCalleeBeforeMethod2;
  147. /* The test result is checked again by JvstTest3#testCalleeBeforeAgain().
  148. */
  149. public void testCalleeBefore() throws Exception {
  150. CtClass cc = sloader.get("test1.CalleeBefore");
  151. CtMethod m1 = cc.getDeclaredMethod("m1");
  152. m1.insertBefore("{ int k = 1; p = k; }");
  153. CtMethod m2 = cc.getDeclaredMethod("m2");
  154. testCalleeBeforeMethod = m1;
  155. testCalleeBeforeMethod2 = m2.getMethodInfo2().hashCode();
  156. m2.insertBefore("{ int k = 3; q = k; }");
  157. CtConstructor[] cons = cc.getDeclaredConstructors();
  158. for (int i = 0; i < cons.length; ++i) {
  159. MethodInfo minfo = cons[i].getMethodInfo();
  160. CodeAttribute ca = minfo.getCodeAttribute();
  161. CodeIterator iterator = ca.iterator();
  162. if (cons[i].getParameterTypes().length == 0) {
  163. assertTrue(iterator.skipThisConstructor() >= 0);
  164. assertTrue(iterator.skipSuperConstructor() < 0);
  165. assertTrue(iterator.skipConstructor() >= 0);
  166. }
  167. else {
  168. assertTrue(iterator.skipThisConstructor() < 0);
  169. assertTrue(iterator.skipSuperConstructor() >= 0);
  170. assertTrue(iterator.skipConstructor() >= 0);
  171. }
  172. cons[i].insertBeforeBody("{ int k = 1; counter += k; }");
  173. }
  174. cc.writeFile();
  175. Object obj = make(cc.getName());
  176. assertEquals(0, invoke(obj, "getr"));
  177. assertEquals(17, invoke(obj, "test"));
  178. }
  179. public void testCalleeAfter() throws Exception {
  180. CtClass cc = sloader.get("test1.CalleeAfter");
  181. CtMethod m1 = cc.getDeclaredMethod("m1");
  182. m1.insertAfter("{ int k = 1; $_ = $_ + k; }", false);
  183. CtMethod m2 = cc.getDeclaredMethod("m2");
  184. m2.insertAfter("{ char k = 1; $_ = $_ + k; }", false);
  185. CtConstructor[] cons = cc.getDeclaredConstructors();
  186. cons[0].insertAfter("{ ++p; $_ = ($r)null; }", false);
  187. cc.writeFile();
  188. Object obj = make(cc.getName());
  189. assertEquals(15, invoke(obj, "test"));
  190. }
  191. public void testCalleeAfter2() throws Exception {
  192. CtClass cc = sloader.get("test1.CalleeAfter2");
  193. CtMethod m1 = cc.getDeclaredMethod("m1");
  194. m1.insertAfter("$_ = 7; $_ = ($r)k1(0);", false);
  195. CtMethod m2 = cc.getDeclaredMethod("m2");
  196. m2.insertAfter("$_ = ($r)k2(0);", false);
  197. CtMethod m3 = cc.getDeclaredMethod("m3");
  198. m3.insertAfter("$_ = ($r)k3(0);", false);
  199. CtMethod m4 = cc.getDeclaredMethod("m4");
  200. try {
  201. m4.insertAfter("$_ = ($r)1;", false);
  202. assertTrue(false);
  203. }
  204. catch (CannotCompileException e) {
  205. }
  206. CtMethod m5 = cc.getDeclaredMethod("m5");
  207. m5.insertAfter("$_ = ($r)k5(0);", false);
  208. cc.writeFile();
  209. Object obj = make(cc.getName());
  210. assertEquals(17, invoke(obj, "test"));
  211. }
  212. public void testCalleeAfter3() throws Exception {
  213. CtClass cc = sloader.get("test1.CalleeAfter3");
  214. CtMethod m1 = cc.getDeclaredMethod("m1");
  215. m1.insertAfter("value++;", true);
  216. CtMethod m2 = cc.getDeclaredMethod("m2");
  217. m2.insertAfter("value++;", true);
  218. CtMethod m3 = cc.getDeclaredMethod("m3");
  219. m3.insertAfter("value++;", true);
  220. CtMethod m4 = cc.getDeclaredMethod("m4");
  221. m4.insertAfter("value++;", true);
  222. cc.writeFile();
  223. Object obj = make(cc.getName());
  224. assertEquals(22, invoke(obj, "test"));
  225. }
  226. public void testCalleeCatch() throws Exception {
  227. CtClass cc = sloader.get("test1.CalleeCatch");
  228. CtMethod m1 = cc.getDeclaredMethod("m1");
  229. m1.addCatch("{ System.out.println($e); return p; }",
  230. sloader.get("java.lang.Exception"));
  231. cc.writeFile();
  232. Object obj = make(cc.getName());
  233. assertEquals(3, invoke(obj, "test"));
  234. }
  235. public void testSuperclass() throws Exception {
  236. CtClass cc = sloader.get("java.lang.Object");
  237. assertEquals(null, cc.getSuperclass());
  238. }
  239. public void testProceed() throws Exception {
  240. CtClass cc = sloader.get("test1.Proceed");
  241. CtMethod m1 = CtNewMethod.make(
  242. "public int m1() { return $proceed(3); }",
  243. cc, "this", "k1");
  244. CtMethod m2 = CtNewMethod.make(
  245. "public int m2() { return $proceed(3); }",
  246. cc, "another", "k2");
  247. CtMethod m3 = CtNewMethod.make(
  248. "public int q(int i) { return p($1 + 1, $$); }", cc);
  249. cc.addMethod(m1);
  250. cc.addMethod(m2);
  251. cc.addMethod(m3);
  252. CtMethod m4 = CtNewMethod.make(
  253. "public int q2() { return q(4); }", cc);
  254. cc.addMethod(m4);
  255. cc.writeFile();
  256. Object obj = make(cc.getName());
  257. assertEquals(3, invoke(obj, "m1"));
  258. assertEquals(4, invoke(obj, "m2"));
  259. assertEquals(9, invoke(obj, "q2"));
  260. }
  261. public void testProceed2() throws Exception {
  262. CtClass cc = sloader.get("test1.Proceed2");
  263. CtMethod m1 = cc.getDeclaredMethod("k1");
  264. m1.instrument(new ExprEditor() {
  265. public void edit(MethodCall m) throws CannotCompileException {
  266. m.replace("{ $_ = $proceed($$); }");
  267. }
  268. public void edit(NewExpr m) throws CannotCompileException {
  269. m.replace("{ $_ = $proceed($$); }");
  270. }
  271. public void edit(FieldAccess m) throws CannotCompileException {
  272. m.replace("{ $_ = $proceed($$); }");
  273. }
  274. public void edit(Instanceof i) throws CannotCompileException {
  275. i.replace("{ $_ = $proceed($$); }");
  276. }
  277. public void edit(Cast c) throws CannotCompileException {
  278. c.replace("{ $_ = $proceed($$); }");
  279. }
  280. });
  281. CtMethod m2 = cc.getDeclaredMethod("k2");
  282. m2.instrument(new ExprEditor() {
  283. public void edit(MethodCall m) throws CannotCompileException {
  284. m.replace("{ $proceed(); }");
  285. }
  286. public void edit(NewExpr m) throws CannotCompileException {
  287. m.replace("{ $_ = $proceed(); }");
  288. }
  289. public void edit(FieldAccess m) throws CannotCompileException {
  290. if (m.isReader())
  291. m.replace("{ $_ = $proceed(); }");
  292. else
  293. m.replace("{ $proceed($$); }");
  294. }
  295. });
  296. cc.writeFile();
  297. Object obj = make(cc.getName());
  298. assertEquals(2, invoke(obj, "k1"));
  299. }
  300. public void testProceed3() throws Exception {
  301. CtClass cc = sloader.get("test1.Proceed3");
  302. CtMethod m1 = cc.getDeclaredMethod("p");
  303. CtMethod m2 = CtNewMethod.copy(m1, cc, null);
  304. m1.setName(m1.getName() + "_orig");
  305. m2.setBody("{ return $proceed($1 + 1); }", "this", m1.getName());
  306. cc.addMethod(m2);
  307. cc.writeFile();
  308. Object obj = make(cc.getName());
  309. assertEquals(4, invoke(obj, "k1"));
  310. }
  311. public void testSetBody() throws Exception {
  312. CtClass cc = sloader.get("test1.SetBody");
  313. CtMethod m1 = cc.getDeclaredMethod("m1");
  314. m1.setBody("{ int i = $1 * $2; return i; }");
  315. CtMethod m2 = cc.getDeclaredMethod("m2");
  316. m2.setBody("System.out.println(\"setbody: \" + $1);");
  317. CtMethod m3 = cc.getDeclaredMethod("m3");
  318. try {
  319. m3.setBody("value = 1; System.out.println(\"setbody: \" + $1);");
  320. fail();
  321. }
  322. catch (CannotCompileException e) {
  323. // System.err.println(e);
  324. }
  325. CtConstructor cons
  326. = new CtConstructor(new CtClass[] { CtClass.intType }, cc);
  327. cons.setBody(null);
  328. cc.addConstructor(cons);
  329. cc.writeFile();
  330. Object obj = make(cc.getName());
  331. assertEquals(12, invoke(obj, "run"));
  332. }
  333. public void testSetStaticConsBody() throws Exception {
  334. CtClass cc = sloader.get("test1.StaticConsBody");
  335. CtConstructor cons = cc.getClassInitializer();
  336. cons.setBody(null);
  337. cons = cc.getConstructors()[0];
  338. cons.setBody(null);
  339. cc.writeFile();
  340. Object obj = make(cc.getName());
  341. assertEquals(0, invoke(obj, "run"));
  342. }
  343. public void testSetConsBody() throws Exception {
  344. CtClass superClazz = sloader.get("java.io.File");
  345. CtClass cc = sloader.makeClass("test1.SetConsBody");
  346. cc.setSuperclass(superClazz);
  347. CtConstructor constructor = new CtConstructor(new CtClass[0], cc);
  348. constructor.setBody("super(\"MyFile\");");
  349. cc.addConstructor(constructor);
  350. constructor = new CtConstructor(new CtClass[] { CtClass.intType },
  351. cc);
  352. constructor.setBody("{ super(\"MyFile\"); }");
  353. cc.addConstructor(constructor);
  354. cc.addMethod(CtNewMethod.make(CtClass.voidType, "m1",
  355. null, null, null, cc));
  356. cc.addMethod(CtNewMethod.make(CtClass.intType, "m2",
  357. null, null, null, cc));
  358. cc.addMethod(CtNewMethod.make(CtClass.byteType, "m3",
  359. null, null, null, cc));
  360. cc.addMethod(CtNewMethod.make(CtClass.longType, "m4",
  361. null, null, null, cc));
  362. cc.addMethod(CtNewMethod.make(CtClass.floatType, "m5",
  363. null, null, null, cc));
  364. cc.addMethod(CtNewMethod.make(CtClass.doubleType, "m6",
  365. null, null, null, cc));
  366. cc.addMethod(CtNewMethod.make(sloader.get("int[]"), "m7",
  367. null, null, null, cc));
  368. cc.addMethod(CtNewMethod.make(
  369. "public int run() {"
  370. + " return (int)(m2() + m3() + m4() + m5() + m6() + 3); }", cc));
  371. cc.writeFile();
  372. Object obj = make(cc.getName());
  373. assertEquals(3, invoke(obj, "run"));
  374. }
  375. public void testEmptyBody() throws Exception {
  376. String[] methods = { "m1", "m2", "m3", "m4" };
  377. boolean[] results = { true, false, false, false, true };
  378. boolean[] cResults = { true, true, false, false, false, true };
  379. CtClass cc = sloader.get("test1.EmptyBody");
  380. for (int i = 0; i < methods.length; ++i) {
  381. CtMethod m = cc.getDeclaredMethod(methods[i]);
  382. assertEquals(results[i], m.isEmpty());
  383. }
  384. CtConstructor[] cons = cc.getDeclaredConstructors();
  385. for (int j = 0; j < cons.length; ++j)
  386. assertEquals(cResults[j], cons[j].isEmpty());
  387. }
  388. public void testExprEditor() throws Exception {
  389. CtClass cc = sloader.get("test1.ExprEdit");
  390. CtMethod m1 = cc.getDeclaredMethod("k0");
  391. m1.instrument(new ExprEditor() {
  392. public void edit(MethodCall m) throws CannotCompileException {
  393. if (m.getClassName().equals("test1.ExprEdit")) {
  394. String name = m.getMethodName();
  395. if (name.equals("k1") || name.equals("k2")) {
  396. try {
  397. CtMethod cm = m.getMethod();
  398. print(cm.getParameterTypes()[0].getName());
  399. print(cm.getReturnType().getName());
  400. }
  401. catch (NotFoundException e) {
  402. throw new CannotCompileException(e);
  403. }
  404. m.replace("{ ++$1; $_ = $proceed($$); }");
  405. }
  406. else if (name.equals("k3"))
  407. m.replace("{ ++$1; $proceed($$); }");
  408. }
  409. }
  410. });
  411. cc.writeFile();
  412. Object obj = make(cc.getName());
  413. assertEquals(12, invoke(obj, "k0"));
  414. }
  415. public void testExprEditor2() throws Exception {
  416. CtClass cc = sloader.get("test1.ExprEdit2");
  417. CtMethod m1 = cc.getDeclaredMethod("k1");
  418. m1.instrument(new ExprEditor() {
  419. public void edit(FieldAccess m) throws CannotCompileException {
  420. if (m.getClassName().equals("test1.ExprEdit2")) {
  421. String name = m.getFieldName();
  422. try {
  423. CtField cf = m.getField();
  424. print(cf.getType().getName());
  425. print("file: " + m.getFileName());
  426. print("line: " + m.getLineNumber());
  427. }
  428. catch (NotFoundException e) {
  429. throw new CannotCompileException(e);
  430. }
  431. if (name.equals("df"))
  432. if (m.isReader())
  433. m.replace("{ $_ = $proceed() + 1; }");
  434. else
  435. m.replace("{ $proceed($1 + 1); }");
  436. else if (name.equals("sf"))
  437. if (m.isReader())
  438. m.replace("{ $_ = $proceed() + 2; }");
  439. else
  440. m.replace("{ $proceed($1 + 2); }");
  441. }
  442. }
  443. });
  444. cc.writeFile();
  445. Object obj = make(cc.getName());
  446. assertEquals(16, invoke(obj, "k1"));
  447. }
  448. public void testExprEditor3() throws Exception {
  449. CtClass cc = sloader.get("test1.ExprEdit3");
  450. CtMethod m1 = cc.getDeclaredMethod("k1");
  451. m1.instrument(new ExprEditor() {
  452. public void edit(NewExpr m) throws CannotCompileException {
  453. System.out.println("new " + m.getClassName());
  454. try {
  455. CtConstructor cc = m.getConstructor();
  456. print(cc.getParameterTypes()[0].getName());
  457. }
  458. catch (NotFoundException e) {
  459. throw new CannotCompileException(e);
  460. }
  461. if (m.getClassName().equals("test1.ExprEdit3")) {
  462. m.replace("{ ++$2; $_ = $proceed($$); }");
  463. }
  464. }
  465. });
  466. cc.writeFile();
  467. Object obj = make(cc.getName());
  468. assertEquals(4, invoke(obj, "k1"));
  469. }
  470. public void testExprEditor4() throws Exception {
  471. CtClass cc = sloader.get("test1.ExprEdit4");
  472. CtMethod m1 = cc.getDeclaredMethod("k1");
  473. m1.instrument(new ExprEditor() {
  474. public void edit(NewExpr m) throws CannotCompileException {
  475. System.out.println("new " + m.getClassName());
  476. if (m.getClassName().equals("test1.ExprEdit4"))
  477. m.replace("$_ = null;");
  478. }
  479. public void edit(MethodCall m) throws CannotCompileException {
  480. if (m.getClassName().equals("test1.ExprEdit4"))
  481. m.replace("{}");
  482. }
  483. });
  484. cc.writeFile();
  485. Object obj = make(cc.getName());
  486. assertEquals(1, invoke(obj, "k1"));
  487. }
  488. public void testExprEditor5() throws Exception {
  489. CtClass cc = sloader.get("test1.ExprEdit5");
  490. CtMethod m1 = cc.getDeclaredMethod("k1");
  491. m1.instrument(new ExprEditor() {
  492. public void edit(NewExpr m) throws CannotCompileException {
  493. m.replace("{ $_ = $proceed($$, \"test\"); }");
  494. }
  495. });
  496. cc.writeFile();
  497. Object obj = make(cc.getName());
  498. assertEquals(1, invoke(obj, "k1"));
  499. }
  500. public void testExprEditor6() throws Exception {
  501. CtClass cc = sloader.get("test1.ExprEdit6");
  502. cc.instrument(new ExprEditor() {
  503. public void edit(MethodCall m) throws CannotCompileException {
  504. assertTrue(m.where().getName().equals("k1"));
  505. m.replace("$_ = 3;");
  506. }
  507. });
  508. cc.writeFile();
  509. Object obj = make(cc.getName());
  510. assertEquals(3, invoke(obj, "k1"));
  511. }
  512. public void testExprEditor7() throws Exception {
  513. CtClass cc = sloader.get("test1.ExprEdit7");
  514. cc.instrument(new ExprEditor() {
  515. public void edit(Instanceof i) throws CannotCompileException {
  516. i.replace("{ this.c1 = $type; $_ = !$proceed($1); }");
  517. }
  518. public void edit(Cast c) throws CannotCompileException {
  519. c.replace("{ this.c2 = $type; $_ = ($r)$1; }");
  520. }
  521. });
  522. cc.writeFile();
  523. Object obj = make(cc.getName());
  524. assertEquals(7, invoke(obj, "k1"));
  525. }
  526. public void testExprEditor8() throws Exception {
  527. CtClass cc = sloader.get("test1.ExprEdit8");
  528. cc.instrument(new ExprEditor() {
  529. public void edit(ConstructorCall c) throws CannotCompileException {
  530. assertTrue(c.isSuper());
  531. c.replace("{ $_ = $proceed($$); value = 7; }");
  532. }
  533. });
  534. cc.writeFile();
  535. Object obj = make(cc.getName());
  536. assertEquals(7, invoke(obj, "k1"));
  537. }
  538. public void testCflow() throws Exception {
  539. CtClass cc = sloader.get("test1.Cflow");
  540. CtMethod m1 = cc.getDeclaredMethod("k1");
  541. m1.useCflow("cflow1");
  542. m1.insertBefore("System.out.println(\"$cflow1: \" + $cflow(cflow1));");
  543. m1.insertAfter("System.out.println(\"*$cflow1: \" + $cflow(cflow1));",
  544. true);
  545. CtMethod m2 = cc.getDeclaredMethod("k2");
  546. m2.useCflow("test1.t.cflow2");
  547. m2.insertBefore(
  548. "System.out.println(\"$cflow2: \" + $cflow(test1.t.cflow2));");
  549. CtMethod m3 = cc.getDeclaredMethod("fact");
  550. m3.useCflow("fact");
  551. m3.insertBefore("if ($cflow(fact) == 0)"
  552. + " System.out.println(\"fact \" + $1);");
  553. cc.writeFile();
  554. Object obj = make(cc.getName());
  555. assertEquals(1, invoke(obj, "run"));
  556. assertEquals(120, invoke(obj, "run2"));
  557. }
  558. public void testSigType() throws Exception {
  559. CtClass cc = sloader.get("test1.SigType");
  560. CtMethod m1 = cc.getDeclaredMethod("k1");
  561. m1.insertBefore("{ Class[] p = $sig; $1 += p.length; }");
  562. m1.insertAfter("System.out.println(\"testSigType: \""
  563. + " + $type.getName());", false);
  564. CtMethod m2 = cc.getDeclaredMethod("k2");
  565. m2.instrument(new ExprEditor() {
  566. public void edit(FieldAccess m) throws CannotCompileException {
  567. m.replace("{ $_ = $proceed($$) + $type.getName().length(); }");
  568. }
  569. public void edit(MethodCall m) throws CannotCompileException {
  570. m.replace("{ $_ = $proceed($$) + $sig.length; }");
  571. }
  572. });
  573. cc.writeFile();
  574. Object obj = make(cc.getName());
  575. assertEquals(19, invoke(obj, "run"));
  576. }
  577. public void testDollarClass() throws Exception {
  578. CtClass cc = sloader.get("test1.DollarClass");
  579. CtMethod m1 = cc.getDeclaredMethod("k1");
  580. m1.insertBefore("{ $1 += $class.getName().length(); }");
  581. CtMethod m2 = cc.getDeclaredMethod("k2");
  582. m2.instrument(new ExprEditor() {
  583. public void edit(MethodCall m) throws CannotCompileException {
  584. m.replace("{ $_ = $class.getName().length(); }");
  585. }
  586. });
  587. m2.insertBefore("{ $1 += $class.getName().length(); }");
  588. cc.writeFile();
  589. Object obj = make(cc.getName());
  590. assertEquals(58, invoke(obj, "run"));
  591. }
  592. public void testHandler() throws Exception {
  593. CtClass cc = sloader.get("test1.Handler");
  594. CtMethod m1 = cc.getDeclaredMethod("m1");
  595. m1.instrument(new ExprEditor() {
  596. public void edit(Handler h) throws CannotCompileException {
  597. try {
  598. print(h.getType().getName());
  599. h.insertBefore(
  600. "{ p = (($r)$1).getClass().getName().length()"
  601. + "+ $type.getName().length(); }");
  602. }
  603. catch (NotFoundException e) {
  604. throw new CannotCompileException(e);
  605. }
  606. }
  607. });
  608. cc.writeFile();
  609. Object obj = make(cc.getName());
  610. assertEquals(("java.lang.IndexOutOfBoundsException".length()
  611. + "java.lang.ClassNotFoundException".length())
  612. * 2 + 1,
  613. invoke(obj, "test"));
  614. }
  615. public void testInterface() throws Exception {
  616. String className = "test1.NewInterface";
  617. ClassPool pool = ClassPool.getDefault();
  618. CtClass targetCtClass = pool.get(className);
  619. CtClass ctInterface
  620. = pool.makeInterface(className + "2");
  621. CtMethod[] ctMethods = targetCtClass.getDeclaredMethods();
  622. for (int i = 0;i < ctMethods.length; i++) {
  623. String code = Modifier.toString(ctMethods[i].getModifiers())
  624. + " " + ctMethods[i].getReturnType().getName()
  625. + " " + ctMethods[i].getName() + "();";
  626. System.out.println(code);
  627. CtMethod m = CtNewMethod.make(code, ctInterface);
  628. ctInterface.addMethod(m);
  629. }
  630. targetCtClass.addInterface(ctInterface);
  631. targetCtClass.stopPruning(true);
  632. targetCtClass.writeFile();
  633. ctInterface.stopPruning(true);
  634. ctInterface.writeFile();
  635. ctInterface.toClass();
  636. targetCtClass.toClass();
  637. }
  638. public void testDispatch() throws Exception {
  639. CtClass cc = sloader.get("test1.Dispatch");
  640. CtMethod m1 = cc.getDeclaredMethod("run");
  641. m1.insertAfter("$_ += f(new Object[1]);");
  642. cc.writeFile();
  643. Object obj = make(cc.getName());
  644. assertEquals(7, invoke(obj, "run"));
  645. }
  646. public void testMakeClass()throws Exception {
  647. CtClass cc = sloader.makeClass(
  648. new FileInputStream(PATH + "test1/MakeClass.class"));
  649. assertEquals("test1.MakeClass", cc.getName());
  650. assertEquals(cc, sloader.get(cc.getName()));
  651. cc.toBytecode();
  652. assertTrue(cc.isFrozen());
  653. try {
  654. cc = sloader.makeClass(
  655. new FileInputStream(PATH + "test1/MakeClass.class"));
  656. assertTrue(false);
  657. }
  658. catch (RuntimeException e) {
  659. print(e.getMessage());
  660. }
  661. }
  662. public void testMakeMethod() throws Exception {
  663. CtClass cc = sloader.makeClass("test1.MakeMethod");
  664. cc.addField(new CtField(CtClass.intType, "i", cc));
  665. String cons_body = "{ i = 3; }";
  666. CtConstructor cons = CtNewConstructor.make(null, null,
  667. cons_body, cc);
  668. cc.addConstructor(cons);
  669. CtMethod m = CtNewMethod.make(CtClass.intType, "run", null, null,
  670. "{ return i; }", cc);
  671. cc.addMethod(m);
  672. cc.writeFile();
  673. Object obj = make(cc.getName());
  674. assertEquals(3, invoke(obj, "run"));
  675. }
  676. public void testDesc() throws Exception {
  677. Class[] sig;
  678. assertEquals(int.class, Desc.getType("I"));
  679. assertEquals(String.class, Desc.getType("Ljava/lang/String;"));
  680. assertEquals(String[].class, Desc.getType("[Ljava/lang/String;"));
  681. assertEquals(int[].class, Desc.getType("[I"));
  682. sig = Desc.getParams("()V");
  683. assertEquals(0, sig.length);
  684. sig = Desc.getParams("(I)V");
  685. assertEquals(int.class, sig[0]);
  686. assertEquals(1, sig.length);
  687. sig = Desc.getParams("(IJ)V");
  688. assertEquals(long.class, sig[1]);
  689. assertEquals(2, sig.length);
  690. sig = Desc.getParams("(Ljava/lang/String;)V");
  691. assertEquals(String.class, sig[0]);
  692. assertEquals(1, sig.length);
  693. sig = Desc.getParams("([Ljava/lang/String;I)V");
  694. assertEquals(String[].class, sig[0]);
  695. assertEquals(2, sig.length);
  696. sig = Desc.getParams("(Ljava/lang/String;[Ljava/lang/String;)V");
  697. assertEquals(String[].class, sig[1]);
  698. assertEquals(2, sig.length);
  699. }
  700. public void testCast() throws Exception {
  701. CtClass cc = sloader.makeClass("test1.CastTest");
  702. StringBuffer src = new StringBuffer();
  703. src.append("public void test(java.lang.String[] strValues)\n");
  704. src.append("{\n");
  705. src.append("\tObject[] values = new Object[2];");
  706. src.append("\tvalues[0] = strValues;");
  707. src.append("\tvalues[1] = strValues;");
  708. src.append("\tstrValues = (String[])values[0];");
  709. src.append("}\n");
  710. CtMethod m = CtNewMethod.make(src.toString(), cc);
  711. }
  712. static final long svUID = 6006955401253799668L;
  713. public void testSerialVUID() throws Exception {
  714. CtClass cc = sloader.get("test1.MySerializableClass");
  715. assertEquals(svUID, SerialVersionUID.calculateDefault(cc));
  716. SerialVersionUID.setSerialVersionUID(cc);
  717. cc.writeFile();
  718. }
  719. public void testInvokeInt() throws Exception {
  720. CtClass cc = sloader.get("test1.InvokeInt");
  721. CtMethod m1 = cc.getDeclaredMethod("check");
  722. m1.instrument(new ExprEditor() {
  723. public void edit(MethodCall m) throws CannotCompileException {
  724. m.replace("$_ = $proceed($$) + k(1);");
  725. }
  726. });
  727. cc.writeFile();
  728. Object obj = make(cc.getName());
  729. assertEquals(6, invoke(obj, "run"));
  730. }
  731. public void testSubtypeOf() throws Exception {
  732. testSubtypeOf2("java.lang.Object", "int", false);
  733. testSubtypeOf2("int[]", "java.lang.Object", true);
  734. testSubtypeOf2("int[]", "java.lang.Cloneable", true);
  735. testSubtypeOf2("java.lang.Object", "int[]", false);
  736. testSubtypeOf2("java.lang.Integer", "java.lang.Number", true);
  737. testSubtypeOf2("java.lang.Number", "java.lang.Integer", false);
  738. testSubtypeOf2("java.lang.Integer[]", "java.lang.Number[]", true);
  739. testSubtypeOf2("java.lang.Number[]", "java.lang.Integer[]", false);
  740. testSubtypeOf2("java.lang.Integer", "java.io.Serializable", true);
  741. testSubtypeOf2("java.lang.Integer", "java.lang.Object", true);
  742. }
  743. private void testSubtypeOf2(String s, String t, boolean b)
  744. throws Exception
  745. {
  746. assertTrue(sloader.get(s).subtypeOf(sloader.get(t)) == b);
  747. }
  748. public void testMakeInterface() throws Exception {
  749. CtClass cc = sloader.makeInterface("test1.MkInterface");
  750. CtMethod m = CtNewMethod.make("public abstract void ready();", cc);
  751. cc.addMethod(m);
  752. cc.writeFile();
  753. // cloader.loadClass(cc.getName());
  754. java.io.File genDir = new java.io.File(".");
  755. java.net.URLClassLoader ucl = new java.net.URLClassLoader(
  756. new java.net.URL[] { genDir.toURI().toURL() }, null);
  757. Class intf = ucl.loadClass("test1.MkInterface");
  758. }
  759. public void testCodeConv() throws Exception {
  760. CtClass cc = sloader.get("test1.CodeConv");
  761. CtClass pc = sloader.get("test1.CodeConvP");
  762. CodeConverter conv = new CodeConverter();
  763. conv.replaceFieldRead(pc.getDeclaredField("a1"), cc, "getA1");
  764. conv.replaceFieldRead(pc.getDeclaredField("a2"), cc, "getA2");
  765. conv.redirectFieldAccess(pc.getDeclaredField("a3"), cc, "a4");
  766. conv.replaceFieldWrite(pc.getDeclaredField("b1"), cc, "putB1");
  767. cc.instrument(conv);
  768. cc.writeFile();
  769. Object obj = make(cc.getName());
  770. assertEquals(51, invoke(obj, "run"));
  771. }
  772. public void testTryCatch() throws Exception {
  773. CtClass cc = sloader.get("test1.TryCatch");
  774. CtMethod m1 = cc.getDeclaredMethod("m1");
  775. m1.instrument(new ExprEditor() {
  776. public void edit(MethodCall m) throws CannotCompileException {
  777. m.replace(
  778. "try { doit(); }"
  779. + "catch(NullPointerException e){ init(); doit(); }");
  780. }
  781. });
  782. final String src =
  783. "try { doit(); }"
  784. + "catch(NullPointerException e){ init(); doit(); return a; }";
  785. CtMethod p1 = cc.getDeclaredMethod("p1");
  786. p1.insertAfter(src, true);
  787. cc.writeFile();
  788. Object obj = make(cc.getName());
  789. assertEquals(4, invoke(obj, "run"));
  790. Object obj2 = make(cc.getName());
  791. assertEquals(4, invoke(obj2, "p1"));
  792. }
  793. private CtClass[] throwablesList = null;
  794. public void testGetThrowables() throws Exception {
  795. CtClass cc = sloader.get("test1.GetThrowables");
  796. CtMethod m1 = cc.getDeclaredMethod("run");
  797. m1.instrument(new ExprEditor() {
  798. public void edit(MethodCall m) throws CannotCompileException {
  799. throwablesList = m.mayThrow();
  800. }
  801. });
  802. System.out.println(throwablesList[0].getName());
  803. System.out.println(throwablesList[1].getName());
  804. assertEquals(2, throwablesList.length);
  805. }
  806. public void testArrayAccess() throws Exception {
  807. CtClass cc = sloader.get("test1.ArrayAccess");
  808. CtMethod m1 = cc.getDeclaredMethod("test");
  809. m1.insertBefore("{ ia[0] += 1; iaa[1] = iaa[0]; }");
  810. cc.writeFile();
  811. Object obj = make(cc.getName());
  812. assertEquals(8, invoke(obj, "test"));
  813. }
  814. public void testClinit() throws Exception {
  815. CtClass cc = sloader.get("test1.Clinit");
  816. CtConstructor clinit = cc.getClassInitializer();
  817. assertTrue(clinit != null);
  818. try {
  819. clinit.insertBeforeBody(";");
  820. assertTrue(false);
  821. }
  822. catch (CannotCompileException e) {
  823. print(e.toString());
  824. assertEquals("class initializer", e.getReason());
  825. }
  826. CtConstructor[] init = cc.getConstructors();
  827. assertEquals(1, init.length);
  828. clinit.insertAfter("j += 1;");
  829. cc.writeFile();
  830. Object obj = make(cc.getName());
  831. assertEquals(457, invoke(obj, "run"));
  832. }
  833. public void testClinit2() throws Exception {
  834. CtClass cc = sloader.get("test1.Clinit2");
  835. CtConstructor clinit = cc.makeClassInitializer();
  836. clinit.insertAfter("j = 7;");
  837. cc.writeFile();
  838. Object obj = make(cc.getName());
  839. assertEquals(7, invoke(obj, "run"));
  840. }
  841. // by yamazaki
  842. public void testCondExpr() throws Exception {
  843. CtClass cc = sloader.makeClass("test1.CondExpr");
  844. CtMethod methodM = new CtMethod(CtClass.intType, "m",
  845. new CtClass[]{ CtClass.intType }, cc);
  846. methodM.setModifiers(methodM.getModifiers() | Modifier.STATIC);
  847. methodM.setBody("{if($1 <= 0) return 1; else return 0;}");
  848. cc.addMethod(methodM);
  849. cc.writeFile();
  850. Object obj = make(cc.getName());
  851. assertEquals(0, invoke(obj, "m", 3));
  852. }
  853. // by yamazaki
  854. public void testCondExpr2() throws Exception {
  855. CtClass cc = sloader.makeClass("test1.CondExpr2");
  856. CtMethod methodM = new CtMethod(CtClass.intType, "m",
  857. new CtClass[]{ CtClass.intType }, cc);
  858. methodM.setModifiers(methodM.getModifiers() | Modifier.STATIC);
  859. methodM.setBody("{return ($1 <= 0) ? 1 : (m($1 - 1) * $1);}");
  860. cc.addMethod(methodM);
  861. cc.writeFile();
  862. Object obj = make(cc.getName());
  863. assertEquals(6, invoke(obj, "m", 3));
  864. }
  865. // by yamazaki
  866. public void testCondExpr3() throws Exception {
  867. CtClass cc = sloader.makeClass("test1.CondExpr3");
  868. CtMethod methodM = CtNewMethod.make(
  869. "public abstract int m(int i);", cc);
  870. CtMethod methodN = CtNewMethod.make(
  871. "public abstract int n(int i);", cc);
  872. cc.addMethod(methodM);
  873. cc.addMethod(methodN);
  874. methodM.setBody("{return ($1 <= 0) ? 1 : (n($1 - 1) * $1);}");
  875. methodN.setBody("{return m($1);}");
  876. cc.setModifiers(cc.getModifiers() & ~Modifier.ABSTRACT);
  877. cc.writeFile();
  878. Object obj = make(cc.getName());
  879. assertEquals(6, invoke(obj, "m", 3));
  880. }
  881. public void testDelegator() throws Exception {
  882. CtClass cc = sloader.get("test1.Delegator");
  883. assertEquals("test1.SuperDelegator", cc.getSuperclass().getName());
  884. CtMethod f = sloader.getMethod("test1.SuperDelegator", "f");
  885. CtMethod g = sloader.getMethod("test1.SuperDelegator", "g");
  886. cc.addMethod(CtNewMethod.delegator(f, cc));
  887. cc.addMethod(CtNewMethod.delegator(g, cc));
  888. cc.writeFile();
  889. Object obj = make(cc.getName());
  890. assertEquals(15, invoke(obj, "run"));
  891. }
  892. public void testSetName() throws Exception {
  893. CtClass cc = sloader.get("test1.SetName");
  894. CtMethod m0 = cc.getDeclaredMethod("foo");
  895. cc.setName("test1.SetName2");
  896. assertEquals(cc, sloader.get("test1.SetName2"));
  897. assertEquals("foo(Ltest1/SetName2;)", m0.getStringRep());
  898. CtClass cc2 = sloader.makeClass("test1.SetName3");
  899. CtMethod m = CtNewMethod.make(
  900. "public int m(test1.SetName2 obj) { return ((test1.SetName2)obj).i; }",
  901. cc2);
  902. cc2.addMethod(m);
  903. cc.writeFile();
  904. cc2.writeFile();
  905. }
  906. public void testFieldModifier() throws Exception {
  907. CtClass cc = sloader.get("test1.FieldMod");
  908. CtField f = cc.getField("text");
  909. f.setModifiers(Modifier.PUBLIC);
  910. f = cc.getField("i");
  911. f.setName("j");
  912. cc.writeFile();
  913. Object obj = make(cc.getName());
  914. assertEquals(java.lang.reflect.Modifier.PUBLIC,
  915. obj.getClass().getField("text").getModifiers());
  916. assertTrue(obj.getClass().getField("j") != null);
  917. }
  918. public void testToString() throws Exception {
  919. System.out.println(sloader.get("test1.FieldMod"));
  920. System.out.println(sloader.get("java.lang.Object"));
  921. }
  922. public void testPackage() throws Exception {
  923. Object obj = new Loader().loadClass("test1.Pac").getConstructor().newInstance();
  924. assertEquals(1, invoke(obj, "run"));
  925. }
  926. public void testHoward() throws Exception {
  927. String head =
  928. "public Object lookup() throws java.rmi.RemoteException ";
  929. String src =
  930. "{ if (_remote != null) return _remote;"
  931. + " test1.HowardHome h = (test1.HowardHome)lookup(\"Howard\");"
  932. + " try { _remote = h.create(); }"
  933. + " catch (java.io.IOException e) { throw new java.rmi.RemoteException(e.getMessage(), e); }"
  934. + " return _remote; }";
  935. String src2 =
  936. "public void lookup2() {"
  937. + " try {}"
  938. + " catch (java.io.IOException e) { throw new Exception(e); }"
  939. + "}";
  940. CtClass cc = sloader.get("test1.Howard");
  941. CtMethod m = CtNewMethod.make(head + src, cc);
  942. cc.addMethod(m);
  943. try {
  944. CtMethod m2 = CtNewMethod.make(src2, cc);
  945. cc.addMethod(m2);
  946. assertTrue(false);
  947. }
  948. catch (CannotCompileException e) {}
  949. m = new CtMethod(sloader.get("java.lang.Object"),
  950. "lookup3", null, cc);
  951. m.setBody(src);
  952. m.setModifiers(Modifier.PUBLIC);
  953. m.setExceptionTypes(new CtClass[] {
  954. sloader.get("java.rmi.RemoteException") });
  955. cc.addMethod(m);
  956. cc.writeFile();
  957. Object target = make(cc.getName());
  958. Method mth = target.getClass().getMethod("lookup", new Class[0]);
  959. Object res = mth.invoke(target, new Object[0]);
  960. assertEquals("howard4", res);
  961. mth = target.getClass().getMethod("lookup3", new Class[0]);
  962. res = mth.invoke(target, new Object[0]);
  963. assertEquals("howard4", res);
  964. }
  965. public void testLoop() throws Exception {
  966. CtClass cc = sloader.makeClass("test1.Loop");
  967. CtMethod m = CtNewMethod.make(
  968. "public int run(int i) { int k = 0;"
  969. + "while (true) { if (k++ > 10) return i; } }",
  970. cc);
  971. cc.addMethod(m);
  972. cc.writeFile();
  973. Object obj = make(cc.getName());
  974. assertEquals(3, invoke(obj, "run", 3));
  975. }
  976. public static Test suite() {
  977. TestSuite suite = new TestSuite("Javassist Tests");
  978. suite.addTestSuite(JvstTest.class);
  979. suite.addTestSuite(JvstTest2.class);
  980. suite.addTestSuite(JvstTest3.class);
  981. suite.addTestSuite(JvstTest4.class);
  982. suite.addTestSuite(JvstTest5.class);
  983. suite.addTestSuite(LoaderTestByRandall.class);
  984. suite.addTestSuite(javassist.bytecode.BytecodeTest.class);
  985. suite.addTestSuite(javassist.bytecode.StackMapTest.class);
  986. suite.addTestSuite(javassist.compiler.CompTest.class);
  987. suite.addTestSuite(javassist.SetterTest.class);
  988. suite.addTestSuite(javassist.bytecode.InsertGap0.class);
  989. suite.addTestSuite(javassist.tools.reflect.LoaderTest.class);
  990. suite.addTestSuite(testproxy.ProxyTester.class);
  991. suite.addTestSuite(testproxy.ProxyFactoryPerformanceTest.class); // remove?
  992. suite.addTestSuite(javassist.proxyfactory.ProxyFactoryTest.class);
  993. suite.addTestSuite(javassist.proxyfactory.Tester.class);
  994. suite.addTestSuite(javassist.HotswapTest.class);
  995. suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class);
  996. suite.addTestSuite(test.javassist.convert.ArrayAccessReplaceTest.class);
  997. suite.addTestSuite(test.javassist.proxy.JASSIST113RegressionTest.class);
  998. suite.addTestSuite(test.javassist.proxy.JBPAPP9257Test.class);
  999. suite.addTestSuite(test.javassist.proxy.ProxyCacheGCTest.class); // remvoe?
  1000. suite.addTestSuite(test.javassist.proxy.ProxyFactoryCompatibilityTest.class);
  1001. suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class);
  1002. suite.addTestSuite(test.javassist.proxy.ProxySimpleTest.class);
  1003. suite.addTestSuite(test.javassist.bytecode.analysis.AnalyzerTest.class);
  1004. suite.addTestSuite(test.javassist.convert.ArrayAccessReplaceTest.class);
  1005. suite.addTestSuite(test.javassist.bytecode.analysis.DomTreeTest.class);
  1006. return suite;
  1007. }
  1008. }