TestExtra.java revision 0
1008N/A * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. 1008N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1008N/A * This code is free software; you can redistribute it and/or modify it 1008N/A * under the terms of the GNU General Public License version 2 only, as 1008N/A * published by the Free Software Foundation. 1008N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1008N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1008N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1008N/A * version 2 for more details (a copy is included in the LICENSE file that 1008N/A * You should have received a copy of the GNU General Public License version 1008N/A * 2 along with this work; if not, write to the Free Software Foundation, 1008N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1008N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1008N/A * CA 95054 USA or visit www.sun.com if you need additional information or 1008N/A * @summary Test that client-provided data in the extra field is written and 1008N/A * read correctly, taking into account the JAR_MAGIC written into the extra 1008N/A * field of the first entry of JAR files. 1008N/A * Tests that the get/set operations on extra data in zip and jar files work 1008N/A * as advertised. The base class tests ZIP files, the member class 1008N/A * TestJarExtra checks JAR files. // Use byte arrays instead of files // JAR/ZIP content written here. /** Test that a header + data set by client works. */ for (
int i =
0; i < b.
length; i++) {
/** Test that a header only (i.e., no extra "data") set by client works. */ byte[]
data =
new byte[
4];
/** Tests the client providing extra data which uses JAR_MAGIC header. */ byte[]
data =
new byte[
8];
/** Check that the entry's extra data is correct. */ if (!
check(
data !=
null,
"unexpected null data for TEST_HEADER")) {
check(
data.
length ==
0,
"unexpected non-zero data length for TEST_HEADER");
/** Look up descriptor in data, returning corresponding byte[]. */ for (
int j =
0; j <
length; j++) {
private static int get16(
byte[] b,
int off) {
return (b[
off] &
0xff) | ((b[
off+
1] &
0xff) <<
8);
/** Test extra field of a JAR file. */ // zeroth entry should have JAR_MAGIC if (!
check(
data !=
null,
"unexpected null data for JAR_MAGIC")) {
// In a jar file, the first ZipEntry should have both JAR_MAGIC // and the TEST_HEADER, so check that also. //--------------------- Infrastructure --------------------------- else fail(x +
" not equal to " + y);}