From 73071730b90f0366cc77a83920362cf5add0889f Mon Sep 17 00:00:00 2001 From: Fredrik Roubert Date: Tue, 15 Jul 2014 20:11:41 +0000 Subject: [PATCH] ICU-10944 Update ICUBinaryTest to test readHeader(ByteBuffer). Testing readHeader(InputStream) is no longer of any importance, as the use of that method is going away. This also exposes a bug in the test data; the size field was zero. Also add statement to actually test lenient data version. R=markus.icu@gmail.com Review URL: https://codereview.appspot.com/105670044 X-SVN-Rev: 36032 --- .../ibm/icu/dev/test/util/ICUBinaryTest.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java index 37578d27b1c..722a28dc86d 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java @@ -1,14 +1,14 @@ /* -******************************************************************************* -* Copyright (C) 1996-2010, International Business Machines Corporation and * -* others. All Rights Reserved. * -******************************************************************************* -*/ + ******************************************************************************* + * Copyright (C) 1996-2014, International Business Machines Corporation and + * others. All Rights Reserved. + ******************************************************************************* + */ package com.ibm.icu.dev.test.util; -import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.ByteBuffer; import com.ibm.icu.dev.test.TestFmwk; import com.ibm.icu.impl.ICUBinary; @@ -46,26 +46,26 @@ public final class ICUBinaryTest extends TestFmwk /** * Testing the constructors of the Tries */ - public void TestReadHeader() + public void TestReadHeader() { - byte formatid[] = {1, 2, 3, 4}; + int formatid = 0x01020304; byte array[] = { // header size - 0, 0x18, + 0, 0x18, // magic numbers - (byte)0xda, 0x27, + (byte)0xda, 0x27, // size - 0, 0, + 0, 0x14, // reserved word - 0, 0, + 0, 0, // bigendian - 1, - // charset + 1, + // charset 0, // charsize - 2, + 2, // reserved byte - 0, + 0, // data format id 1, 2, 3, 4, // dataVersion @@ -73,8 +73,8 @@ public final class ICUBinaryTest extends TestFmwk // unicodeVersion 3, 2, 0, 0 }; - ByteArrayInputStream inputstream = new ByteArrayInputStream(array); - ICUBinary.Authenticate authenticate + ByteBuffer bytes = ByteBuffer.wrap(array); + ICUBinary.Authenticate authenticate = new ICUBinary.Authenticate() { public boolean isDataVersionAcceptable(byte version[]) { @@ -83,33 +83,33 @@ public final class ICUBinaryTest extends TestFmwk }; // check full data version try { - ICUBinary.readHeader(inputstream, formatid, authenticate); + ICUBinary.readHeader(bytes, formatid, authenticate); } catch (IOException e) { errln("Failed: Lenient authenticate object should pass ICUBinary.readHeader"); } // no restriction to the data version try { - inputstream.reset(); - ICUBinary.readHeader(inputstream, formatid, null); + bytes.rewind(); + ICUBinary.readHeader(bytes, formatid, null); } catch (IOException e) { errln("Failed: Null authenticate object should pass ICUBinary.readHeader"); } // lenient data version + array[17] = 9; try { - inputstream.reset(); - ICUBinary.readHeader(inputstream, formatid, authenticate); + bytes.rewind(); + ICUBinary.readHeader(bytes, formatid, authenticate); } catch (IOException e) { errln("Failed: Lenient authenticate object should pass ICUBinary.readHeader"); } // changing the version to an incorrect one, expecting failure array[16] = 2; try { - inputstream.reset(); - ICUBinary.readHeader(inputstream, formatid, authenticate); + bytes.rewind(); + ICUBinary.readHeader(bytes, formatid, authenticate); errln("Failed: Invalid version number should not pass authenticate object"); } catch (IOException e) { logln("PASS: ICUBinary.readHeader with invalid version number failed as expected"); } } } - -- 2.40.0