2 *******************************************************************************
\r
3 * Copyright (C) 1996-2008, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.dev.test.util;
\r
10 import com.ibm.icu.dev.test.TestFmwk;
\r
11 import com.ibm.icu.impl.ICUBinary;
\r
12 import java.io.IOException;
\r
13 import java.io.ByteArrayInputStream;
\r
16 * Testing class for Trie. Tests here will be simple, since both CharTrie and
\r
17 * IntTrie are very similar and are heavily used in other parts of ICU4J.
\r
18 * Codes using Tries are expected to have detailed tests.
\r
19 * @author Syn Wee Quek
\r
20 * @since release 2.1 Jan 01 2002
\r
22 public final class ICUBinaryTest extends TestFmwk
\r
24 // constructor ---------------------------------------------------
\r
29 public ICUBinaryTest()
\r
33 // public methods -----------------------------------------------
\r
35 public static void main(String arg[])
\r
37 ICUBinaryTest test = new ICUBinaryTest();
\r
40 } catch (Exception e) {
\r
41 test.errln("Error testing icubinarytest");
\r
46 * Testing the constructors of the Tries
\r
48 public void TestReadHeader()
\r
50 byte formatid[] = {1, 2, 3, 4};
\r
75 ByteArrayInputStream inputstream = new ByteArrayInputStream(array);
\r
76 ICUBinary.Authenticate authenticate
\r
77 = new ICUBinary.Authenticate() {
\r
78 public boolean isDataVersionAcceptable(byte version[])
\r
80 return version[0] == 1;
\r
83 // check full data version
\r
85 ICUBinary.readHeader(inputstream, formatid, authenticate);
\r
86 } catch (IOException e) {
\r
87 errln("Failed: Lenient authenticate object should pass ICUBinary.readHeader");
\r
89 // no restriction to the data version
\r
91 inputstream.reset();
\r
92 ICUBinary.readHeader(inputstream, formatid, null);
\r
93 } catch (IOException e) {
\r
94 errln("Failed: Null authenticate object should pass ICUBinary.readHeader");
\r
96 // lenient data version
\r
98 inputstream.reset();
\r
99 ICUBinary.readHeader(inputstream, formatid, authenticate);
\r
100 } catch (IOException e) {
\r
101 errln("Failed: Lenient authenticate object should pass ICUBinary.readHeader");
\r
103 // changing the version to an incorrect one, expecting failure
\r
106 inputstream.reset();
\r
107 ICUBinary.readHeader(inputstream, formatid, authenticate);
\r
108 errln("Failed: Invalid version number should not pass authenticate object");
\r
109 } catch (IOException e) {
\r
110 logln("PASS: ICUBinary.readHeader with invalid version number failed as expected");
\r