[freenet-cvs] r13834 - trunk/freenet/test/freenet/support
sback at freenetproject.org
sback at freenetproject.org
Fri Jun 29 22:26:14 UTC 2007
Author: sback
Date: 2007-06-29 22:26:14 +0000 (Fri, 29 Jun 2007)
New Revision: 13834
Modified:
trunk/freenet/test/freenet/support/HexUtilTest.java
Log:
Remained methods tested:
Modified: trunk/freenet/test/freenet/support/HexUtilTest.java
===================================================================
--- trunk/freenet/test/freenet/support/HexUtilTest.java 2007-06-29 22:11:50 UTC (rev 13833)
+++ trunk/freenet/test/freenet/support/HexUtilTest.java 2007-06-29 22:26:14 UTC (rev 13834)
@@ -16,6 +16,11 @@
package freenet.support;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.BitSet;
@@ -178,6 +183,64 @@
}
/**
+ * Test bitsToHexString(BitSet,int) method
+ * comparing its results to results provided
+ * by different scientific valid calculators.
+ */
+ public void testBitsToHexString() {
+ BitSet methodBitSet = new BitSet(8);
+ String expectedString = "00";
+ assertEquals(HexUtil.bitsToHexString(methodBitSet,8),expectedString);
+ methodBitSet.set(0,7,true); /*0x7f*/
+ expectedString = "7f";
+ assertEquals(HexUtil.bitsToHexString(methodBitSet,8),expectedString);
+ methodBitSet.set(0,9,true); /*0xff*/
+ expectedString = "ff";
+ assertEquals(HexUtil.bitsToHexString(methodBitSet,8),expectedString);
+ }
+
+ /**
+ * Tests hexToBits(String,BitSet,int) method
+ */
+ public void testHexToBits() {
+ String methodStringToStore = "00";
+ BitSet methodBitSet = new BitSet(8);
+ HexUtil.hexToBits(methodStringToStore,methodBitSet,methodBitSet.size());
+ assertTrue(methodBitSet.cardinality()==0);
+ BitSet expectedBitSet = new BitSet(8);
+ expectedBitSet.set(0,7,true); /*0x7f*/
+ methodStringToStore = "7f";
+ methodBitSet = new BitSet(8);
+ HexUtil.hexToBits(methodStringToStore,methodBitSet,methodBitSet.size());
+ assertTrue(methodBitSet.intersects(expectedBitSet));
+ expectedBitSet.set(0,9,true); /*0xff*/
+ methodStringToStore = "ff";
+ methodBitSet = new BitSet(8);
+ HexUtil.hexToBits(methodStringToStore,methodBitSet,methodBitSet.size());
+ assertTrue(methodBitSet.intersects(expectedBitSet));
+ }
+
+ /**
+ * Tests writeBigInteger(BigInteger,DataOutputStream)
+ * and readBigInteger(DataInputStream) comparing a
+ * BigInteger after writing it to a Stream and
+ * reading it from the writing result.
+ */
+ public void testWriteAndReadBigInteger() {
+ BigInteger methodBigInteger = new BigInteger("999999999999999");
+ ByteArrayOutputStream methodByteArrayOutStream = new ByteArrayOutputStream();
+ DataOutputStream methodDataOutStream = new DataOutputStream(methodByteArrayOutStream);
+ try {
+ HexUtil.writeBigInteger(methodBigInteger,methodDataOutStream);
+ ByteArrayInputStream methodByteArrayInStream =
+ new ByteArrayInputStream(methodByteArrayOutStream.toByteArray());
+ DataInputStream methodDataInStream = new DataInputStream(methodByteArrayInStream);
+ assertTrue(methodBigInteger.compareTo(HexUtil.readBigInteger(methodDataInStream))==0);
+ } catch (IOException aException) {
+ fail("Not expected exception thrown : " + aException.getMessage()); }
+ }
+
+ /**
* Test bytesToHex(byte[],int,int) method
* with a too long starting offset. The tested
* method should raise an exception.
More information about the cvs
mailing list