2 *******************************************************************************
\r
3 * Copyright (C) 1996-2010, 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 java.io.ByteArrayInputStream;
\r
11 import java.io.IOException;
\r
13 import com.ibm.icu.dev.test.TestFmwk;
\r
14 import com.ibm.icu.impl.ICUBinary;
\r
17 * Testing class for Trie. Tests here will be simple, since both CharTrie and
\r
18 * IntTrie are very similar and are heavily used in other parts of ICU4J.
\r
19 * Codes using Tries are expected to have detailed tests.
\r
20 * @author Syn Wee Quek
\r
21 * @since release 2.1 Jan 01 2002
\r
23 public final class ICUBinaryTest extends TestFmwk
\r
25 // constructor ---------------------------------------------------
\r
30 public ICUBinaryTest()
\r
34 // public methods -----------------------------------------------
\r
36 public static void main(String arg[])
\r
38 ICUBinaryTest test = new ICUBinaryTest();
\r
41 } catch (Exception e) {
\r
42 test.errln("Error testing icubinarytest");
\r
47 * Testing the constructors of the Tries
\r
49 public void TestReadHeader()
\r
51 byte formatid[] = {1, 2, 3, 4};
\r
76 ByteArrayInputStream inputstream = new ByteArrayInputStream(array);
\r
77 ICUBinary.Authenticate authenticate
\r
78 = new ICUBinary.Authenticate() {
\r
79 public boolean isDataVersionAcceptable(byte version[])
\r
81 return version[0] == 1;
\r
84 // check full data version
\r
86 ICUBinary.readHeader(inputstream, formatid, authenticate);
\r
87 } catch (IOException e) {
\r
88 errln("Failed: Lenient authenticate object should pass ICUBinary.readHeader");
\r
90 // no restriction to the data version
\r
92 inputstream.reset();
\r
93 ICUBinary.readHeader(inputstream, formatid, null);
\r
94 } catch (IOException e) {
\r
95 errln("Failed: Null authenticate object should pass ICUBinary.readHeader");
\r
97 // lenient data version
\r
99 inputstream.reset();
\r
100 ICUBinary.readHeader(inputstream, formatid, authenticate);
\r
101 } catch (IOException e) {
\r
102 errln("Failed: Lenient authenticate object should pass ICUBinary.readHeader");
\r
104 // changing the version to an incorrect one, expecting failure
\r
107 inputstream.reset();
\r
108 ICUBinary.readHeader(inputstream, formatid, authenticate);
\r
109 errln("Failed: Invalid version number should not pass authenticate object");
\r
110 } catch (IOException e) {
\r
111 logln("PASS: ICUBinary.readHeader with invalid version number failed as expected");
\r