mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 10:19:51 +00:00
edit Packer and Unpacker classes, and move org.msgpack.util.annotation.*.java to org.msgpack.util.codegen.*.java
This commit is contained in:
parent
ee1ba5c0f2
commit
2736b88dd5
20 changed files with 766 additions and 74 deletions
|
|
@ -0,0 +1,51 @@
|
|||
package org.msgpack.util.codegen;
|
||||
|
||||
import static org.msgpack.Templates.tString;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.msgpack.MessagePacker;
|
||||
import org.msgpack.Packer;
|
||||
import org.msgpack.ReflectionPacker;
|
||||
import org.msgpack.ReflectionTemplate;
|
||||
import org.msgpack.Template;
|
||||
import org.msgpack.Unpacker;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class TestDynamicCodeGenPacker extends TestCase {
|
||||
public static class StringFieldClass {
|
||||
public String s1;
|
||||
public String s2;
|
||||
public StringFieldClass() { }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackConvert() throws Exception {
|
||||
tString(); // FIXME link StringTemplate
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicCodeGenPacker.create(StringFieldClass.class);
|
||||
|
||||
StringFieldClass src = new StringFieldClass();
|
||||
|
||||
src.s1 = "kumofs";
|
||||
src.s2 = "frsyuki";
|
||||
|
||||
packer.pack(new Packer(out), src);
|
||||
|
||||
Template tmpl = ReflectionTemplate.create(StringFieldClass.class);
|
||||
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
|
||||
Object obj = tmpl.unpack(new Unpacker(in));
|
||||
assertEquals(obj.getClass(), StringFieldClass.class);
|
||||
|
||||
StringFieldClass dst = (StringFieldClass)obj;
|
||||
assertEquals(src.s1, dst.s1);
|
||||
assertEquals(src.s2, dst.s2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.msgpack.util.annotation;
|
||||
package org.msgpack.util.codegen;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
@ -16,6 +16,9 @@ import org.msgpack.MessagePackObject;
|
|||
import org.msgpack.MessageUnpackable;
|
||||
import org.msgpack.Packer;
|
||||
import org.msgpack.Unpacker;
|
||||
import org.msgpack.util.codegen.MessagePackUnpackable;
|
||||
import org.msgpack.util.codegen.PackUnpackUtil;
|
||||
import org.msgpack.util.codegen.DynamicCodeGenException;
|
||||
|
||||
public class TestMessagePackUnpackable extends TestCase {
|
||||
|
||||
|
|
@ -350,7 +353,7 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(NoDefaultConstructorClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
|
|
@ -358,7 +361,7 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
PackUnpackUtil
|
||||
.newEnhancedInstance(PrivateDefaultConstructorClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
|
|
@ -366,7 +369,7 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
PackUnpackUtil
|
||||
.newEnhancedInstance(ProtectedDefaultConstructorClass.class);
|
||||
assertTrue(true);
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
fail();
|
||||
}
|
||||
assertTrue(true);
|
||||
|
|
@ -374,7 +377,7 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
PackUnpackUtil
|
||||
.newEnhancedInstance(PackageDefaultConstructorClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
|
|
@ -409,21 +412,21 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(PrivateModifierClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(ProtectedModifierClass.class);
|
||||
assertTrue(true);
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
fail();
|
||||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(PackageModifierClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
|
|
@ -448,14 +451,14 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(FinalModifierClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(AbstractModifierClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
|
|
@ -474,14 +477,14 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(SampleInterface.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(SampleEnum.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
Loading…
Add table
Add a link
Reference in a new issue