/*
-*******************************************************************************
-* 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;
/**
* 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
// 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[])
{
};
// 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");
}
}
}
-