mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-4094 Add API/Method Coverage tests for ICU4J
X-SVN-Rev: 16672
This commit is contained in:
parent
917180dab9
commit
6937e9e405
1 changed files with 45 additions and 0 deletions
|
@ -17,6 +17,7 @@ import java.util.Set;
|
|||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
import com.ibm.icu.util.ByteArrayWrapper;
|
||||
|
||||
/**
|
||||
* @test
|
||||
|
@ -102,6 +103,50 @@ public class UtilityTest extends TestFmwk {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This test indends to test the utility class ByteArrayWrapper
|
||||
// Seems that the class is somewhat incomplete, for example
|
||||
// - getHashCode(Object) is weird
|
||||
// - PatternMatch feature(search part of array within the whole one) lacks
|
||||
public void TestByteArrayWrapper()
|
||||
{
|
||||
byte[] ba = {0x00, 0x01, 0x02};
|
||||
java.nio.ByteBuffer buffer = java.nio.ByteBuffer.wrap(ba);
|
||||
ByteArrayWrapper x = new ByteArrayWrapper(buffer);
|
||||
|
||||
ByteArrayWrapper y = new ByteArrayWrapper(ba, 0, ba.length);
|
||||
ByteArrayWrapper z = new ByteArrayWrapper(x);
|
||||
|
||||
// test equality
|
||||
if (!x.equals(y) || !x.equals(z))
|
||||
errln("FAIL: test (operator ==): Failed!");
|
||||
if (x.getHashCode(null)!=y.getHashCode(null)) //not know why getHashCode with an arg
|
||||
errln("FAIL: identical objects have different hash codes.");
|
||||
if (x.getHashCode(null)!=z.getHashCode(null))
|
||||
errln("FAIL: identical objects have different hash codes.");
|
||||
|
||||
// test non-equality
|
||||
y = new ByteArrayWrapper(ba, 0, 2);
|
||||
if (x.equals(y))
|
||||
errln("FAIL: test (operator !=): Failed!");
|
||||
|
||||
// appent operation
|
||||
y.append(new ByteArrayWrapper(new byte[]{0x02}, 0, 1));
|
||||
if (!x.equals(y))
|
||||
errln("FAIL: 2nd test (operator ==): Failed!");
|
||||
|
||||
// retrieve a byte array from ByteArrayWrapper
|
||||
byte[] target = new byte[5];
|
||||
try {
|
||||
x.get(target, 0, 5);
|
||||
errln("FAIL: No exception thrown when limit too long.");
|
||||
} catch (Exception e) {
|
||||
//we should come here
|
||||
}
|
||||
x.get(target, 1, 3);
|
||||
// output it
|
||||
logln("target: " + new ByteArrayWrapper(target, 0, 5).toString());
|
||||
}
|
||||
|
||||
private int compareLongUnsigned(int x, int y)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue