summaryrefslogtreecommitdiff
path: root/java/src/test
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@users.sourceforge.jp>2010-08-18 23:37:47 +0900
committerfrsyuki <frsyuki@users.sourceforge.jp>2010-08-18 23:37:47 +0900
commit40dc9de6c9bc90a95e55d5d2999f7e45d34cabc8 (patch)
treec67cb7e474d382d7ba9dc59d05b92a732f8d7b6d /java/src/test
parentd7469e469490b00f83b61d04e02cef856c805b93 (diff)
downloadmsgpack-python-40dc9de6c9bc90a95e55d5d2999f7e45d34cabc8.tar.gz
java: supports packing/unpacking of BigInteger less than 0xffffffffffffffff
Diffstat (limited to 'java/src/test')
-rw-r--r--java/src/test/java/org/msgpack/TestPackUnpack.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/java/src/test/java/org/msgpack/TestPackUnpack.java b/java/src/test/java/org/msgpack/TestPackUnpack.java
index ca3d235..75c5fe7 100644
--- a/java/src/test/java/org/msgpack/TestPackUnpack.java
+++ b/java/src/test/java/org/msgpack/TestPackUnpack.java
@@ -3,6 +3,7 @@ package org.msgpack;
import org.msgpack.*;
import java.io.*;
import java.util.*;
+import java.math.BigInteger;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -36,6 +37,32 @@ public class TestPackUnpack {
testInt(rand.nextInt());
}
+ public void testBigInteger(BigInteger val) throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ new Packer(out).pack(val);
+ MessagePackObject obj = unpackOne(out);
+ if(!val.equals(obj.asBigInteger())) {
+ System.out.println("expect: "+val);
+ System.out.println("but : "+obj.asBigInteger());
+ }
+ assertEquals(val, obj.asBigInteger());
+ }
+ @Test
+ public void testBigInteger() throws Exception {
+ testBigInteger(BigInteger.valueOf(0));
+ testBigInteger(BigInteger.valueOf(-1));
+ testBigInteger(BigInteger.valueOf(1));
+ testBigInteger(BigInteger.valueOf(Integer.MIN_VALUE));
+ testBigInteger(BigInteger.valueOf(Integer.MAX_VALUE));
+ testBigInteger(BigInteger.valueOf(Long.MIN_VALUE));
+ testBigInteger(BigInteger.valueOf(Long.MAX_VALUE));
+ BigInteger max = BigInteger.valueOf(Long.MAX_VALUE).setBit(63);
+ testBigInteger(max);
+ Random rand = new Random();
+ for (int i = 0; i < 1000; i++)
+ testBigInteger( max.subtract(BigInteger.valueOf( Math.abs(rand.nextLong()) )) );
+ }
+
public void testFloat(float val) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
new Packer(out).pack(val);