[zipdiff-cvs] zipdiff/src/test/zipdiff AbstractTestCase.java,NONE,1.1 DifferenceCalculatorTest.java,
Status: Alpha
Brought to you by:
sullis
From: Sean S. <su...@us...> - 2004-06-19 20:14:03
|
Update of /cvsroot/zipdiff/zipdiff/src/test/zipdiff In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17992/src/test/zipdiff Modified Files: DifferenceCalculatorTest.java Added Files: AbstractTestCase.java Log Message: --- NEW FILE: AbstractTestCase.java --- /* * Created on Jun 9, 2004 * */ package zipdiff; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import junit.framework.TestCase; /** * * * @author jastewart * @author Sean C. Sullivan * */ abstract class AbstractTestCase extends TestCase { protected static String ENTRYA = "A"; protected static String ENTRYB = "B"; protected static String ENTRYC = "C"; public static final String SYSTEM_TMP_DIR_PROPERTY = "java.io.tmpdir"; public static final String TEST_DIR_POSTFIX = File.separator + "UnitTestsDifferenceCalculatorTest"; protected static String testDirPathName; // naming convention The Capital letter denotes the entry so A will be the same as A // OneEntry denotes that the jar has one entry protected static String testJarOneEmpty; protected static String testJarTwoEmpty; protected static String testJarOneEntryA1Filename; protected static String testJarOneEntryA2Filename; protected static String testJarOneEntryB1Filename; protected static String testJarTwoEntryAB1Filename; protected static String testJarTwoEntryAC2Filename; protected static String testJarOneEntryAContentsChangedFilename; // // static initializer // static { testDirPathName = System.getProperty(System.getProperty(SYSTEM_TMP_DIR_PROPERTY)); if(testDirPathName == null) { testDirPathName = File.separator + "temp" + TEST_DIR_POSTFIX; } testJarOneEmpty = testDirPathName + File.separator + "testJarOneEmpty.jar"; testJarTwoEmpty = testDirPathName + File.separator + "testJarTwoEmpty.jar"; testJarOneEntryA1Filename = testDirPathName + File.separator + "testJarOneEntryA1Filename.jar"; testJarOneEntryA2Filename = testDirPathName + File.separator + "testJarOneEntryA2Filename.jar"; testJarOneEntryB1Filename = testDirPathName + File.separator + "testJarOneEntryB1Filename.jar"; testJarTwoEntryAB1Filename = testDirPathName + File.separator + "testJarTwoEntryAB1Filename.jar"; testJarTwoEntryAB1Filename = testDirPathName + File.separator + "testJarTwoEntryAB1Filename.jar"; testJarTwoEntryAC2Filename = testDirPathName + File.separator + "testJarTwoEntryAC2Filename.jar"; testJarOneEntryAContentsChangedFilename = testDirPathName + File.separator + "testJarOneEntryAContentsChangedFilename.jar"; } /** * Create a jar with only one entry in it. That entry being A * @throws FileNotFoundException * @throws IOException */ protected void createJarOneEntryA1() throws FileNotFoundException, IOException { // create a jar file with no duplicates File testDir = new File(testDirPathName); testDir.mkdirs(); JarOutputStream testJarOS = new JarOutputStream( new BufferedOutputStream( new FileOutputStream(testJarOneEntryA1Filename))); // ad an entry JarEntry entry1 = new JarEntry(ENTRYA); testJarOS.putNextEntry(entry1); byte data1[] = new byte[2048]; for (int i=0; i < data1.length; i++) { data1[i]='a'; } testJarOS.write(data1); testJarOS.flush(); testJarOS.close(); } /** * Create a jar with only one entry in it. That entry being A * @throws FileNotFoundException * @throws IOException */ protected void createJarOneEntryA2() throws FileNotFoundException, IOException { // create a jar file with no duplicates File testDir = new File(testDirPathName); testDir.mkdirs(); JarOutputStream testJarOS = new JarOutputStream( new BufferedOutputStream( new FileOutputStream(testJarOneEntryA2Filename))); // ad an entry JarEntry entry1 = new JarEntry(ENTRYA); testJarOS.putNextEntry(entry1); byte data1[] = new byte[2048]; for (int i=0; i < data1.length; i++) { data1[i]='a'; } testJarOS.write(data1); testJarOS.flush(); testJarOS.close(); } /** * Create a jar with only one entry in it. That entry being A * @throws FileNotFoundException * @throws IOException */ protected void createJarOneEntryAContentsChanged() throws FileNotFoundException, IOException { // create a jar file with no duplicates File testDir = new File(testDirPathName); testDir.mkdirs(); JarOutputStream testJarOS = new JarOutputStream( new BufferedOutputStream( new FileOutputStream(testJarOneEntryAContentsChangedFilename))); // ad an entry JarEntry entry1 = new JarEntry(ENTRYA); testJarOS.putNextEntry(entry1); byte data1[] = new byte[2048]; for (int i=0; i < data1.length; i++) { data1[i]='a'; } // set a different content so that it will come up as changed data1[data1.length-1] = 'b'; testJarOS.write(data1); testJarOS.flush(); testJarOS.close(); } /** * Create a jar with only one entry in it. That entry being A * @throws FileNotFoundException * @throws IOException */ protected void createJarOneEntryB1() throws FileNotFoundException, IOException { // create a jar file with no duplicates File testDir = new File(testDirPathName); testDir.mkdirs(); JarOutputStream testJarOS = new JarOutputStream( new BufferedOutputStream( new FileOutputStream(testJarOneEntryB1Filename))); // ad an entry JarEntry entry1 = new JarEntry(ENTRYB); testJarOS.putNextEntry(entry1); byte data1[] = new byte[2048]; for (int i=0; i < data1.length; i++) { data1[i]='b'; } testJarOS.write(data1); testJarOS.flush(); testJarOS.close(); } } Index: DifferenceCalculatorTest.java =================================================================== RCS file: /cvsroot/zipdiff/zipdiff/src/test/zipdiff/DifferenceCalculatorTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DifferenceCalculatorTest.java 12 Jun 2004 13:58:46 -0000 1.2 --- DifferenceCalculatorTest.java 19 Jun 2004 20:13:53 -0000 1.3 *************** *** 24,178 **** * @author jastewart */ ! public class DifferenceCalculatorTest extends TestCase { ! private static String ENTRYA = "A"; ! private static String ENTRYB = "B"; ! private static String ENTRYC = "C"; ! public static final String SYSTEM_TMP_DIR_PROPERTY = "java.io.tmpdir"; ! public static final String TEST_DIR_POSTFIX = File.separator + "UnitTestsDifferenceCalculatorTest"; ! private static String testDirPathName; ! // naming convention The Capital letter denotes the entry so A will be the same as A ! // OneEntry denotes that the jar has one entry ! private static String testJarOneEmpty; ! private static String testJarTwoEmpty; ! private static String testJarOneEntryA1Filename; ! private static String testJarOneEntryA2Filename; ! private static String testJarOneEntryB1Filename; ! private static String testJarTwoEntryAB1Filename; ! private static String testJarTwoEntryAC2Filename; ! private static String testJarOneEntryAContentsChangedFilename; ! { ! testDirPathName = ! System.getProperty(System.getProperty(SYSTEM_TMP_DIR_PROPERTY)); ! if(testDirPathName == null) { ! testDirPathName = File.separator + "temp" + TEST_DIR_POSTFIX; ! } ! testJarOneEmpty = testDirPathName + File.separator + "testJarOneEmpty.jar"; ! testJarTwoEmpty = testDirPathName + File.separator + "testJarTwoEmpty.jar"; ! testJarOneEntryA1Filename = testDirPathName + File.separator + "testJarOneEntryA1Filename.jar"; ! testJarOneEntryA2Filename = testDirPathName + File.separator + "testJarOneEntryA2Filename.jar"; ! testJarOneEntryB1Filename = testDirPathName + File.separator + "testJarOneEntryB1Filename.jar"; ! testJarTwoEntryAB1Filename = testDirPathName + File.separator + "testJarTwoEntryAB1Filename.jar"; ! testJarTwoEntryAB1Filename = testDirPathName + File.separator + "testJarTwoEntryAB1Filename.jar"; ! testJarTwoEntryAC2Filename = testDirPathName + File.separator + "testJarTwoEntryAC2Filename.jar"; ! testJarOneEntryAContentsChangedFilename = testDirPathName + File.separator + "testJarOneEntryAContentsChangedFilename.jar"; ! } ! ! /** ! * Constructor for DifferenceCalculatorTest. ! * @param arg0 ! */ ! public DifferenceCalculatorTest(String arg0) { ! super(arg0); ! } ! ! /** ! * Create a jar with only one entry in it. That entry being A ! * @throws FileNotFoundException ! * @throws IOException ! */ ! public void createJarOneEntryA1() throws FileNotFoundException, IOException { ! // create a jar file with no duplicates ! File testDir = new File(testDirPathName); ! testDir.mkdirs(); ! JarOutputStream testJarOS = ! new JarOutputStream( ! new BufferedOutputStream( ! new FileOutputStream(testJarOneEntryA1Filename))); ! ! // ad an entry ! JarEntry entry1 = new JarEntry(ENTRYA); ! testJarOS.putNextEntry(entry1); ! byte data1[] = new byte[2048]; ! for (int i=0; i < data1.length; i++) { ! data1[i]='a'; ! } ! testJarOS.write(data1); ! ! testJarOS.flush(); ! testJarOS.close(); ! } ! ! /** ! * Create a jar with only one entry in it. That entry being A ! * @throws FileNotFoundException ! * @throws IOException ! */ ! public void createJarOneEntryA2() throws FileNotFoundException, IOException { ! // create a jar file with no duplicates ! File testDir = new File(testDirPathName); ! testDir.mkdirs(); ! JarOutputStream testJarOS = ! new JarOutputStream( ! new BufferedOutputStream( ! new FileOutputStream(testJarOneEntryA2Filename))); ! ! // ad an entry ! JarEntry entry1 = new JarEntry(ENTRYA); ! testJarOS.putNextEntry(entry1); ! byte data1[] = new byte[2048]; ! for (int i=0; i < data1.length; i++) { ! data1[i]='a'; ! } ! testJarOS.write(data1); ! ! testJarOS.flush(); ! testJarOS.close(); ! } ! ! /** ! * Create a jar with only one entry in it. That entry being A ! * @throws FileNotFoundException ! * @throws IOException ! */ ! public void createJarOneEntryAContentsChanged() throws FileNotFoundException, IOException { ! // create a jar file with no duplicates ! File testDir = new File(testDirPathName); ! testDir.mkdirs(); ! JarOutputStream testJarOS = ! new JarOutputStream( ! new BufferedOutputStream( ! new FileOutputStream(testJarOneEntryAContentsChangedFilename))); ! ! // ad an entry ! JarEntry entry1 = new JarEntry(ENTRYA); ! testJarOS.putNextEntry(entry1); ! byte data1[] = new byte[2048]; ! for (int i=0; i < data1.length; i++) { ! data1[i]='a'; ! } ! // set a different content so that it will come up as changed ! data1[data1.length-1] = 'b'; ! testJarOS.write(data1); ! ! testJarOS.flush(); ! testJarOS.close(); ! } ! ! /** ! * Create a jar with only one entry in it. That entry being A ! * @throws FileNotFoundException ! * @throws IOException ! */ ! public void createJarOneEntryB1() throws FileNotFoundException, IOException { ! // create a jar file with no duplicates ! File testDir = new File(testDirPathName); ! testDir.mkdirs(); ! JarOutputStream testJarOS = ! new JarOutputStream( ! new BufferedOutputStream( ! new FileOutputStream(testJarOneEntryB1Filename))); ! ! // ad an entry ! JarEntry entry1 = new JarEntry(ENTRYB); ! testJarOS.putNextEntry(entry1); ! byte data1[] = new byte[2048]; ! for (int i=0; i < data1.length; i++) { ! data1[i]='b'; ! } ! testJarOS.write(data1); ! ! testJarOS.flush(); ! testJarOS.close(); ! } --- 24,28 ---- * @author jastewart */ ! public class DifferenceCalculatorTest extends AbstractTestCase { *************** *** 192,195 **** --- 42,46 ---- Map changedEntries = differences.getChanged(); assertTrue(changedEntries.size() == 0); + } *************** *** 249,251 **** --- 100,103 ---- } + } |