From 5caf7bfe1dcfb7defacd54346b9da977bc9d130f Mon Sep 17 00:00:00 2001 From: Syn Wee Quek Date: Thu, 10 Oct 2002 05:16:14 +0000 Subject: [PATCH] ICU-2079 testing icubinary new data version leniency authentication X-SVN-Rev: 10012 --- icu4j/src/com/ibm/icu/dev/test/TestAll.java | 9 +- .../ibm/icu/dev/test/util/ICUBinaryTest.java | 119 ++++++++++++++++++ 2 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 icu4j/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java diff --git a/icu4j/src/com/ibm/icu/dev/test/TestAll.java b/icu4j/src/com/ibm/icu/dev/test/TestAll.java index cd1e20fe69..c14d581e37 100755 --- a/icu4j/src/com/ibm/icu/dev/test/TestAll.java +++ b/icu4j/src/com/ibm/icu/dev/test/TestAll.java @@ -5,8 +5,8 @@ ******************************************************************************* * * $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestAll.java,v $ - * $Date: 2002/09/17 19:12:42 $ - * $Revision: 1.39 $ + * $Date: 2002/10/10 05:16:14 $ + * $Revision: 1.40 $ * ***************************************************************************************** */ @@ -219,4 +219,9 @@ public class TestAll extends TestFmwk { new DiagBigDecimal(), }); } + public void TestICUBinary() throws Exception{ + run( new TestFmwk[]{ + new com.ibm.icu.dev.test.util.ICUBinaryTest(), + }); + } } diff --git a/icu4j/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java b/icu4j/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java new file mode 100644 index 0000000000..9f26f3e543 --- /dev/null +++ b/icu4j/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java @@ -0,0 +1,119 @@ +/** +******************************************************************************* +* Copyright (C) 1996-2002, International Business Machines Corporation and * +* others. All Rights Reserved. * +******************************************************************************* +* +* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/ICUBinaryTest.java,v $ +* $Date: 2002/10/10 05:16:13 $ +* $Revision: 1.1 $ +* +******************************************************************************* +*/ + +package com.ibm.icu.dev.test.util; + +import com.ibm.icu.dev.test.TestFmwk; +import com.ibm.icu.impl.ICUBinary; +import java.io.IOException; +import java.io.ByteArrayInputStream; + +/** +* Testing class for Trie. Tests here will be simple, since both CharTrie and +* IntTrie are very similar and are heavily used in other parts of ICU4J. +* Codes using Tries are expected to have detailed tests. +* @author Syn Wee Quek +* @since release 2.1 Jan 01 2002 +*/ +public final class ICUBinaryTest extends TestFmwk +{ + // constructor --------------------------------------------------- + + /** + * Constructor + */ + public ICUBinaryTest() + { + } + + // public methods ----------------------------------------------- + + public static void main(String arg[]) + { + ICUBinaryTest test = new ICUBinaryTest(); + try { + test.run(arg); + } catch (Exception e) { + test.errln("Error testing icubinarytest"); + } + } + + /** + * Testing the constructors of the Tries + */ + public void TestReadHeader() + { + byte formatid[] = {1, 2, 3, 4}; + byte array[] = { + // header size + 0, 0x18, + // magic numbers + (byte)0xda, 0x27, + // size + 0, 0, + // reserved word + 0, 0, + // bigendian + 1, + // charset + 0, + // charsize + 2, + // reserved byte + 0, + // data format id + 1, 2, 3, 4, + // dataVersion + 1, 2, 3, 4, + // unicodeVersion + 3, 2, 0, 0 + }; + ByteArrayInputStream inputstream = new ByteArrayInputStream(array); + ICUBinary.Authenticate authenticate + = new ICUBinary.Authenticate() { + public boolean isDataVersionAcceptable(byte version[]) + { + return version[0] == 1; + }; + }; + // check full data version + try { + ICUBinary.readHeader(inputstream, 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); + } catch (IOException e) { + errln("Failed: Null authenticate object should pass ICUBinary.readHeader"); + } + // lenient data version + try { + inputstream.reset(); + ICUBinary.readHeader(inputstream, 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); + errln("Failed: Invalid version number should not pass authenticate object"); + } catch (IOException e) { + } + } +} +