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.

ZipTestCase.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.util.Collection;
  16. import org.aspectj.weaver.WeaverTestCase;
  17. import junit.framework.TestCase;
  18. public class ZipTestCase extends TestCase {
  19. File outDir;
  20. /**
  21. * Constructor for ZipTestCase.
  22. *
  23. * @param arg0
  24. */
  25. public ZipTestCase(String arg0) {
  26. super(arg0);
  27. }
  28. public void setUp() {
  29. outDir = WeaverTestCase.getOutdir();
  30. }
  31. public void tearDown() {
  32. WeaverTestCase.removeOutDir();
  33. outDir = null;
  34. }
  35. public void zipTest(String fileName, String aspectjar) throws IOException {
  36. zipTest(fileName, aspectjar, false);
  37. }
  38. public void zipTest(String fileName, String aspectjar, boolean isInJar) throws IOException {
  39. File inFile = new File(fileName);
  40. File outFile = new File(outDir, inFile.getName());
  41. BcelWorld world = new BcelWorld();
  42. BcelWeaver weaver = new BcelWeaver(world);
  43. long startTime = System.currentTimeMillis();
  44. // ensure that a fast cpu doesn't complete file write within 1000ms of start
  45. try {
  46. Thread.sleep(2000);
  47. } catch (InterruptedException e) {
  48. e.printStackTrace();
  49. }
  50. weaver.addJarFile(inFile, new File("."), false);
  51. if (aspectjar != null) {
  52. if (isInJar) {
  53. weaver.addJarFile(new File(aspectjar), new File("."), false);
  54. } else {
  55. weaver.addLibraryJarFile(new File(aspectjar));
  56. world.addPath(new File(aspectjar).toString());
  57. }
  58. }
  59. weaver.addLibraryJarFile(new File(WeaverTestCase.TESTDATA_PATH + "/Regex.jar")); // ???
  60. world.addPath(new File(WeaverTestCase.TESTDATA_PATH + "/Regex.jar").getPath());
  61. Collection<String> woven = weaver.weave(outFile);
  62. long stopTime = System.currentTimeMillis();
  63. System.out.println("handled " + woven.size() + " entries, in " + (stopTime - startTime) / 1000. + " seconds");
  64. // last mod times on linux (at least) are only accurate to the second.
  65. // with fast disks and a fast cpu the following test can fail if the write completes less than
  66. // 1000 milliseconds after the start of the test, hence the 1000ms delay added above.
  67. assertTrue(outFile.lastModified() > startTime);
  68. }
  69. public void testSmall() throws IOException {
  70. zipTest(WeaverTestCase.TESTDATA_PATH + "/Regex.jar", null);
  71. }
  72. public void testSmallWithAspects() throws IOException {
  73. System.out.println("could take 4 seconds...");
  74. zipTest(WeaverTestCase.TESTDATA_PATH + "/Regex.jar", WeaverTestCase.TESTDATA_PATH + "/megatrace.jar");
  75. }
  76. public void testSmallWithAspectsNoWeave() throws IOException {
  77. System.out.println("could take 4 seconds...");
  78. zipTest(WeaverTestCase.TESTDATA_PATH + "/Regex.jar", WeaverTestCase.TESTDATA_PATH + "/megatraceNoweave.jar", true);
  79. }
  80. public void testBig() throws IOException {
  81. System.out.println("could take 4 seconds...");
  82. zipTest("../lib/bcel/bcel.jar", null);
  83. }
  84. public void testBigWithEasyNoTrace() throws IOException {
  85. System.out.println("could take 4 seconds...");
  86. zipTest("../lib/bcel/bcel.jar", WeaverTestCase.TESTDATA_PATH + "/megatrace0easy.jar");
  87. }
  88. // this is something we test every now and again.
  89. public void xtestBigWithHardNoTrace() throws IOException {
  90. System.out.println("could take 24 seconds...");
  91. zipTest("../lib/bcel/bcel.jar", WeaverTestCase.TESTDATA_PATH + "/megatrace0hard.jar");
  92. }
  93. public void xtestBigWithAspects() throws IOException {
  94. System.out.println("could take 40 seconds...");
  95. zipTest("../lib/bcel/bcel.jar", WeaverTestCase.TESTDATA_PATH + "/megatrace.jar");
  96. }
  97. }