001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.classreader;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: import junit.framework.*;
039:
040: public class TestClassfileScanner extends TestCase {
041: public static final String TEST_DIR = "tests" + File.separator
042: + "JarJarDiff";
043: public static final String TEST_FILENAME = "classes"
044: + File.separator + "test.class";
045:
046: private ClassfileScanner scanner;
047:
048: protected void setUp() throws Exception {
049: super .setUp();
050:
051: scanner = new ClassfileScanner();
052: }
053:
054: public void testOneFile() {
055: String filename = TEST_FILENAME;
056: assertTrue(filename + " missing", new File(filename).exists());
057:
058: scanner.load(Collections.singleton(filename));
059:
060: assertEquals("Number of files", 1, scanner.getNbFiles());
061: assertEquals("Number of classes", 1, scanner.getNbClasses());
062: }
063:
064: public void testOneLevelZip() {
065: String filename = TEST_DIR + File.separator + "onelevel.zip";
066: assertTrue(filename + " missing", new File(filename).exists());
067:
068: scanner.load(Collections.singleton(filename));
069:
070: assertEquals("Number of files", 31, scanner.getNbFiles());
071: assertEquals("Number of classes", 14, scanner.getNbClasses());
072: }
073:
074: public void testOneLevelJar() {
075: String filename = TEST_DIR + File.separator + "onelevel.jar";
076: assertTrue(filename + " missing", new File(filename).exists());
077:
078: scanner.load(Collections.singleton(filename));
079:
080: assertEquals("Number of files", 33, scanner.getNbFiles());
081: assertEquals("Number of classes", 14, scanner.getNbClasses());
082: }
083:
084: public void testOneLevelMiscellaneous() {
085: String filename = TEST_DIR + File.separator + "onelevel.mis";
086: assertTrue(filename + " missing", new File(filename).exists());
087:
088: scanner.load(Collections.singleton(filename));
089:
090: assertEquals("Number of files", 31, scanner.getNbFiles());
091: assertEquals("Number of classes", 14, scanner.getNbClasses());
092: }
093:
094: public void testTwoLevelZip() {
095: String filename = TEST_DIR + File.separator + "twolevel.zip";
096: assertTrue(filename + " missing", new File(filename).exists());
097:
098: scanner.load(Collections.singleton(filename));
099:
100: assertEquals("Number of files", 32, scanner.getNbFiles());
101: assertEquals("Number of classes", 14, scanner.getNbClasses());
102: }
103:
104: public void testTwoLevelJar() {
105: String filename = TEST_DIR + File.separator + "twolevel.jar";
106: assertTrue(filename + " missing", new File(filename).exists());
107:
108: scanner.load(Collections.singleton(filename));
109:
110: assertEquals("Number of files", 34, scanner.getNbFiles());
111: assertEquals("Number of classes", 14, scanner.getNbClasses());
112: }
113:
114: public void testTwoLevelMiscellaneous() {
115: String filename = TEST_DIR + File.separator + "twolevel.mis";
116: assertTrue(filename + " missing", new File(filename).exists());
117:
118: scanner.load(Collections.singleton(filename));
119:
120: assertEquals("Number of files", 32, scanner.getNbFiles());
121: assertEquals("Number of classes", 14, scanner.getNbClasses());
122: }
123: }
|