TestExtra.java revision 2362
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6480504
* @summary Test that client-provided data in the extra field is written and
* read correctly, taking into account the JAR_MAGIC written into the extra
* field of the first entry of JAR files.
* @author Dave Bristor
*/
/**
* as advertised. The base class tests ZIP files, the member class
* TestJarExtra checks JAR files.
*/
public class TestExtra {
final static int TEST_HEADER = 0xbabe;
// ZipEntry extra data
final static byte[][] extra = new byte[][] {
};
int count = 1;
// Use byte arrays instead of files
new TestExtra().testHeaderPlusData();
new TestJarExtra().testHeaderPlusData();
new TestJarExtra().testHeaderOnly();
new TestJarExtra().testClientJarMagic();
}
TestExtra() {
try {
baos = new ByteArrayOutputStream();
} catch (Throwable t) {
unexpected(t);
}
}
/** Test that a header + data set by client works. */
void testHeaderPlusData() throws IOException {
for (byte[] b : extra) {
for (int i = 0; i < b.length; i++) {
data[i + 4] = b[i];
}
}
}
/** Test that a header only (i.e., no extra "data") set by client works. */
void testHeaderOnly() throws IOException {
byte[] data = new byte[4];
}
/** Tests the client providing extra data which uses JAR_MAGIC header. */
void testClientJarMagic() throws IOException {
byte[] data = new byte[8];
}
/** Check that the entry's extra data is correct. */
return;
}
if (dataLength == 0) {
} else {
}
}
/** Look up descriptor in data, returning corresponding byte[]. */
try {
int i = 0;
for (int j = 0; j < length; j++) {
}
return rc;
}
}
} catch (ArrayIndexOutOfBoundsException e) {
// descriptor not found
}
return rc;
}
return new ZipInputStream(
}
return new ZipOutputStream(baos);
}
return new ZipInputStream(bais);
}
}
}
/** Test extra field of a JAR file. */
static class TestJarExtra extends TestExtra {
return new JarOutputStream(baos);
}
return new JarInputStream(bais);
}
// zeroth entry should have JAR_MAGIC
if (count == 0) {
}
}
// 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);}
}