jdk/test/java/util/jar/TestExtra.java
author jlahoda
Wed, 12 Dec 2012 20:26:56 +0100
changeset 14803 88347e495d34
parent 5506 202f599c92aa
child 17910 82d10099a8a6
permissions -rw-r--r--
8004504: ListBuffer could reuse List.nil() as the sentinel element Summary: ListBuffer.last now points to the last elements with client data, or null if none. Reviewed-by: jjg, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6480504
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that client-provided data in the extra field is written and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * read correctly, taking into account the JAR_MAGIC written into the extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * field of the first entry of JAR files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @author Dave Bristor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.jar.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.zip.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Tests that the get/set operations on extra data in zip and jar files work
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * as advertised.  The base class tests ZIP files, the member class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * TestJarExtra checks JAR files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class TestExtra {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    final static int JAR_MAGIC = 0xcafe; // private IN JarOutputStream.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    final static int TEST_HEADER = 0xbabe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    final static Charset ascii = Charset.forName("ASCII");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // ZipEntry extra data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    final static byte[][] extra = new byte[][] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        ascii.encode("hello, world").array(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        ascii.encode("foo bar").array()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // For naming entries in JAR/ZIP streams
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    int count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // Use byte arrays instead of files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    ByteArrayOutputStream baos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // JAR/ZIP content written here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    ZipOutputStream zos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static void realMain(String[] args) throws Throwable{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        new TestExtra().testHeaderPlusData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        new TestJarExtra().testHeaderPlusData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        new TestJarExtra().testHeaderOnly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        new TestJarExtra().testClientJarMagic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    TestExtra() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            baos = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            zos = getOutputStream(baos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            unexpected(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /** Test that a header + data set by client works. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    void testHeaderPlusData() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        for (byte[] b : extra) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            ZipEntry ze = getEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            byte[] data = new byte[b.length + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            set16(data, 0, TEST_HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            set16(data, 2, b.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            for (int i = 0; i < b.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                data[i + 4] = b[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            ze.setExtra(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            zos.putNextEntry(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        zos.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        ZipInputStream zis = getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        ZipEntry ze = zis.getNextEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        checkEntry(ze, 0, extra[0].length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        ze = zis.getNextEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        checkEntry(ze, 1, extra[1].length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /** Test that a header only (i.e., no extra "data") set by client works. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    void testHeaderOnly() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        ZipEntry ze = getEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        byte[] data = new byte[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        set16(data, 0, TEST_HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        set16(data, 2, 0); // Length of data is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        ze.setExtra(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        zos.putNextEntry(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        zos.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        ZipInputStream zis = getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        ze = zis.getNextEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        byte[] e = ze.getExtra();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        check(e.length == 8, "expected extra length is 8, got " + e.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        checkEntry(ze, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /** Tests the client providing extra data which uses JAR_MAGIC header. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    void testClientJarMagic() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        ZipEntry ze = getEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        byte[] data = new byte[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        set16(data, 0, TEST_HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        set16(data, 2, 0); // Length of data is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        set16(data, 4, JAR_MAGIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        set16(data, 6, 0); // Length of data is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        ze.setExtra(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        zos.putNextEntry(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        zos.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        ZipInputStream zis = getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        ze = zis.getNextEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        byte[] e = ze.getExtra();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        check(e.length == 8, "expected extra length is 8, got " + e.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        checkEntry(ze, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /** Check that the entry's extra data is correct. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    void checkEntry(ZipEntry ze, int count, int dataLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        byte[] extraData = ze.getExtra();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        byte[] data = getField(TEST_HEADER, extraData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (!check(data != null, "unexpected null data for TEST_HEADER")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (dataLength == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            check(data.length == 0, "unexpected non-zero data length for TEST_HEADER");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            check(Arrays.equals(extra[count], data),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                  "failed to get entry " + ze.getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                  + ", expected " + new String(extra[count]) + ", got '" + new String(data) + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /** Look up descriptor in data, returning corresponding byte[]. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    static byte[] getField(int descriptor, byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        byte[] rc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            while (i < data.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if (get16(data, i) == descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    int length = get16(data, i + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    rc = new byte[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    for (int j = 0; j < length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        rc[j] = data[i + 4 + j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                i += get16(data, i + 2) + 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } catch (ArrayIndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            // descriptor not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    ZipInputStream getInputStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return new ZipInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            new ByteArrayInputStream(baos.toByteArray()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    ZipOutputStream getOutputStream(ByteArrayOutputStream baos) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return new ZipOutputStream(baos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    ZipInputStream getInputStream(ByteArrayInputStream bais) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return new ZipInputStream(bais);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    ZipEntry getEntry() { return new ZipEntry("zip" + count++ + ".txt"); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static int get16(byte[] b, int off) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    private static void set16(byte[] b, int off, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        b[off+0] = (byte)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        b[off+1] = (byte)(value >> 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /** Test extra field of a JAR file. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    static class TestJarExtra extends TestExtra {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        ZipOutputStream getOutputStream(ByteArrayOutputStream baos) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return new JarOutputStream(baos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        ZipInputStream getInputStream(ByteArrayInputStream bais) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return new JarInputStream(bais);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        ZipEntry getEntry() { return new ZipEntry("jar" + count++ + ".txt"); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        void checkEntry(ZipEntry ze, int count, int dataLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            // zeroth entry should have JAR_MAGIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if (count == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                byte[] extraData = ze.getExtra();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                byte[] data = getField(JAR_MAGIC, extraData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                if (!check(data != null, "unexpected null data for JAR_MAGIC")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    check(data.length != 0, "unexpected non-zero data length for JAR_MAGIC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            // In a jar file, the first ZipEntry should have both JAR_MAGIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // and the TEST_HEADER, so check that also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            super.checkEntry(ze, count, dataLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    //--------------------- Infrastructure ---------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    static volatile int passed = 0, failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    static void pass() {passed++;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    static void fail() {failed++; Thread.dumpStack();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    static void fail(String msg) {System.out.println(msg); fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    static void check(boolean cond) {if (cond) pass(); else fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    static boolean check(boolean cond, String msg) {if (cond) pass(); else fail(msg); return cond; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    static void equal(Object x, Object y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (x == null ? y == null : x.equals(y)) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        else fail(x + " not equal to " + y);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public static void main(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        System.out.println("\nPassed = " + passed + " failed = " + failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (failed > 0) throw new Error("Some tests failed");}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}