diff options
| author | Kazuki Ohta <kazuki.ohta@gmail.com> | 2010-04-17 21:16:32 +0900 |
|---|---|---|
| committer | Kazuki Ohta <kazuki.ohta@gmail.com> | 2010-04-17 21:16:32 +0900 |
| commit | 08b716c96d02e281cc096783cbe64932f70919ef (patch) | |
| tree | 100eb309f7574da39d27266b06527c46db6cd8aa /java | |
| parent | b4b1f0a2c961529cdabd705b2581350323952f74 (diff) | |
| download | msgpack-python-08b716c96d02e281cc096783cbe64932f70919ef.tar.gz | |
java: add TestPackUnpack for int
Diffstat (limited to 'java')
| -rw-r--r-- | java/build.xml | 8 | ||||
| -rw-r--r-- | java/test/org/msgpack/TestPackUnpack.java | 52 |
2 files changed, 58 insertions, 2 deletions
diff --git a/java/build.xml b/java/build.xml index 35ee2fe..baecd01 100644 --- a/java/build.xml +++ b/java/build.xml @@ -14,6 +14,7 @@ <property name="java.src.dir" value="${src.dir}/"/> <property name="build.dir" value="${basedir}/build"/> <property name="lib.dir" value="${basedir}/lib"/> + <property name="dist.dir" value="${basedir}/dist"/> <property name="test.count" value="100"/> <property name="test.junit.output.format" value="plain"/> @@ -64,6 +65,9 @@ <fileset dir="${ivy.test.lib}"> <include name="**/*.jar" /> </fileset> + <fileset dir="${dist.dir}"> + <include name="**/*.jar" /> + </fileset> </path> <path id="test.java.classpath"> <pathelement location="${test.java.classes}" /> @@ -146,7 +150,7 @@ </javac> </target> <target name="jar" depends="compile"> - <jar jarfile="dist/msgpack-0.0.1.jar" basedir="build" /> + <jar jarfile="${dist.dir}/msgpack-0.0.1.jar" basedir="build" /> </target> <!-- test --> @@ -178,7 +182,7 @@ <fail if="tests.failed">Tests Failed!</fail> </sequential> </macrodef> - <target name="compile-test" depends="ivy-retrieve-test,compile"> + <target name="compile-test" depends="ivy-retrieve-test,jar"> <java-compiler dest="${test.java.classes}" classpath="test.java.classpath"> <src path="${test.java.src.dir}/org" /> diff --git a/java/test/org/msgpack/TestPackUnpack.java b/java/test/org/msgpack/TestPackUnpack.java new file mode 100644 index 0000000..f8eeae7 --- /dev/null +++ b/java/test/org/msgpack/TestPackUnpack.java @@ -0,0 +1,52 @@ +package org.msgpack; + +import org.msgpack.*; +import java.io.*; +import java.util.*; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class TestPackUnpack { + public Object unpackOne(ByteArrayOutputStream out) { + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker upk = new Unpacker(in); + Iterator<Object> it = upk.iterator(); + assertEquals(true, it.hasNext()); + Object obj = it.next(); + assertEquals(false, it.hasNext()); + return obj; + } + + @Test + public void testInt() throws Exception { + testInt(0); + testInt(-1); + testInt(1); + testInt(Integer.MIN_VALUE); + testInt(Integer.MAX_VALUE); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) + testInt(rand.nextInt()); + } + public void testInt(int val) throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer pk = new Packer(out); + pk.pack(val); + Object obj = unpackOne(out); + int val2 = -1; + if (obj instanceof Byte) + val2 = ((Byte)obj).intValue(); + else if (obj instanceof Integer) + val2 = ((Integer)obj).intValue(); + else if (obj instanceof Short) + val2 = ((Short)obj).intValue(); + else if (obj instanceof Long) + val2 = ((Long)obj).intValue(); + else { + System.out.println("obj = " + obj.getClass()); + assertTrue(false); + } + assertEquals(val, val2); + } +}; |
