001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.harmony.pack200.tests;
018:
019: import java.io.File;
020: import java.io.FileOutputStream;
021: import java.io.IOException;
022: import java.io.InputStream;
023: import java.util.jar.JarOutputStream;
024:
025: import junit.framework.TestCase;
026:
027: import org.apache.harmony.pack200.Archive;
028:
029: /**
030: * Tests for org.apache.harmony.pack200.Archive, which is the main class for unpack200.
031: */
032: public class ArchiveTest extends TestCase {
033:
034: InputStream in;
035: JarOutputStream out;
036:
037: public void testJustResourcesGZip() throws Exception {
038: in = Archive.class
039: .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack.gz");
040: out = new JarOutputStream(new FileOutputStream(File
041: .createTempFile("Just", "ResourcesGz.jar")));
042: Archive archive = new Archive(in, out);
043: archive.unpack();
044: }
045:
046: // Test with an archive containing Harmony's SQL module, packed with -E1
047: public void testWithSqlE1() throws Exception {
048: in = Archive.class
049: .getResourceAsStream("/org/apache/harmony/pack200/tests/sql-e1.pack.gz");
050: out = new JarOutputStream(new FileOutputStream(File
051: .createTempFile("sql-e1", ".jar")));
052: Archive archive = new Archive(in, out);
053: archive.unpack();
054: }
055:
056: // Test with an archive containing Harmony's SQL module
057: public void testWithSql() throws Exception {
058: in = Archive.class
059: .getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");
060: out = new JarOutputStream(new FileOutputStream(File
061: .createTempFile("sql", ".jar")));
062: Archive archive = new Archive(in, out);
063: archive.unpack();
064: }
065:
066: // Test with an archive containing Harmony's Pack200 module, packed with -E1
067: public void testWithPack200E1() throws Exception {
068: in = Archive.class
069: .getResourceAsStream("/org/apache/harmony/pack200/tests/pack200-e1.pack.gz");
070: out = new JarOutputStream(new FileOutputStream(File
071: .createTempFile("pack", "200-e1.jar")));
072: Archive archive = new Archive(in, out);
073: archive.unpack();
074: }
075:
076: // Test with an archive containing Harmony's Pack200 module
077: public void testWithPack200() throws Exception {
078: in = Archive.class
079: .getResourceAsStream("/org/apache/harmony/pack200/tests/pack200.pack.gz");
080: out = new JarOutputStream(new FileOutputStream(File
081: .createTempFile("pack", "200.jar")));
082: Archive archive = new Archive(in, out);
083: archive.unpack();
084: }
085:
086: // Test with an archive containing Harmony's JNDI module
087: public void testWithJNDIE1() throws Exception {
088: in = Archive.class
089: .getResourceAsStream("/org/apache/harmony/pack200/tests/jndi-e1.pack.gz");
090: out = new JarOutputStream(new FileOutputStream(File
091: .createTempFile("jndi", "-e1.jar")));
092: Archive archive = new Archive(in, out);
093: archive.unpack();
094: }
095:
096: // Test with an archive containing Annotations
097: public void testWithAnnotations() throws Exception {
098: in = Archive.class
099: .getResourceAsStream("/org/apache/harmony/pack200/tests/annotations.pack.gz");
100: out = new JarOutputStream(new FileOutputStream(File
101: .createTempFile("ann", "otations.jar")));
102: Archive archive = new Archive(in, out);
103: archive.unpack();
104: }
105:
106: // Test with an archive packed with the -E0 option
107: public void testWithE0() throws Exception {
108: in = Archive.class
109: .getResourceAsStream("/org/apache/harmony/pack200/tests/simple-E0.pack.gz");
110: out = new JarOutputStream(new FileOutputStream(File
111: .createTempFile("simpleE0", ".jar")));
112: Archive archive = new Archive(in, out);
113: archive.unpack();
114: }
115:
116: protected void tearDown() throws Exception {
117: super .tearDown();
118: try {
119: if (in != null) {
120: try {
121: in.close();
122: } catch (IOException e) {
123: e.printStackTrace();
124: }
125: }
126: } finally {
127: try {
128: if (out != null) {
129: out.close();
130: }
131: } catch (IOException e) {
132: e.printStackTrace();
133: }
134: }
135: }
136:
137: }
|