You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JvstTest.java 44KB

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