mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 18:29:53 +00:00
java: add the code for checking a null pointer to DynamicCodeGen.java
This commit is contained in:
parent
3f5ac54bf5
commit
c10eb2c17b
5 changed files with 730 additions and 94 deletions
|
|
@ -26,7 +26,7 @@ import org.msgpack.annotation.MessagePackOrdinalEnum;
|
|||
public class TestDynamicCodeGenPackerConverter extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTypeFields() throws Exception {
|
||||
public void testPrimitiveTypeField00s() throws Exception {
|
||||
PrimitiveTypeFieldsClass src = new PrimitiveTypeFieldsClass();
|
||||
src.f0 = (byte) 0;
|
||||
src.f1 = 1;
|
||||
|
|
@ -40,8 +40,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
.create(PrimitiveTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(PrimitiveTypeFieldsClass.class);
|
||||
Template tmpl = DynamicTemplate.create(PrimitiveTypeFieldsClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
|
|
@ -58,6 +57,50 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTypeFields01() throws Exception {
|
||||
PrimitiveTypeFieldsClass src = new PrimitiveTypeFieldsClass();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(PrimitiveTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(PrimitiveTypeFieldsClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
||||
.convert(mpo);
|
||||
assertEquals(src.f0, dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertEquals(src.f2, dst.f2);
|
||||
assertEquals(src.f3, dst.f3);
|
||||
assertEquals(src.f4, dst.f4);
|
||||
assertEquals(src.f5, dst.f5);
|
||||
assertEquals(src.f6, dst.f6);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTypeFields02() throws Exception {
|
||||
PrimitiveTypeFieldsClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(PrimitiveTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(PrimitiveTypeFieldsClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
||||
.convert(mpo);
|
||||
assertEquals(src, dst);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public static class PrimitiveTypeFieldsClass {
|
||||
public byte f0;
|
||||
public short f1;
|
||||
|
|
@ -72,7 +115,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGeneralReferenceTypeFieldsClass() throws Exception {
|
||||
public void testGeneralReferenceTypeFieldsClass00() throws Exception {
|
||||
GeneralReferenceTypeFieldsClass src = new GeneralReferenceTypeFieldsClass();
|
||||
src.f0 = 0;
|
||||
src.f1 = 1;
|
||||
|
|
@ -111,6 +154,65 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void XtestGeneralReferenceTypeFieldsClass01() throws Exception {
|
||||
GeneralReferenceTypeFieldsClass src = new GeneralReferenceTypeFieldsClass();
|
||||
src.f0 = null;
|
||||
src.f1 = null;
|
||||
src.f2 = null;
|
||||
src.f3 = null;
|
||||
src.f4 = null;
|
||||
src.f5 = null;
|
||||
src.f6 = null;
|
||||
src.f7 = null;
|
||||
src.f8 = null;
|
||||
src.f9 = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(GeneralReferenceTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(GeneralReferenceTypeFieldsClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
GeneralReferenceTypeFieldsClass dst = (GeneralReferenceTypeFieldsClass) tmpl
|
||||
.convert(mpo);
|
||||
assertEquals(src.f0, dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertEquals(src.f2, dst.f2);
|
||||
assertEquals(src.f3, dst.f3);
|
||||
assertEquals(src.f4, dst.f4);
|
||||
assertEquals(src.f5, dst.f5);
|
||||
assertEquals(src.f6, dst.f6);
|
||||
assertEquals(src.f7, dst.f7);
|
||||
assertEquals(src.f8, dst.f8);
|
||||
assertEquals(src.f9, dst.f9);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void XtestGeneralReferenceTypeFieldsClass02() throws Exception {
|
||||
GeneralReferenceTypeFieldsClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(GeneralReferenceTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(GeneralReferenceTypeFieldsClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
GeneralReferenceTypeFieldsClass dst = (GeneralReferenceTypeFieldsClass) tmpl
|
||||
.convert(mpo);
|
||||
assertEquals(src, dst);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public static class GeneralReferenceTypeFieldsClass {
|
||||
public Byte f0;
|
||||
public Short f1;
|
||||
|
|
@ -127,7 +229,8 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testListTypes() throws Exception {
|
||||
@Test
|
||||
public void testListTypes00() throws Exception {
|
||||
SampleListTypes src = new SampleListTypes();
|
||||
src.f0 = new ArrayList<Integer>();
|
||||
src.f1 = new ArrayList<Integer>();
|
||||
|
|
@ -146,8 +249,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
slnt.f1 = "muga";
|
||||
src.f4.add(slnt);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(SampleListTypes.class);
|
||||
MessagePacker packer = DynamicPacker.create(SampleListTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleListTypes.class);
|
||||
|
|
@ -185,6 +287,49 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListTypes01() throws Exception {
|
||||
SampleListTypes src = new SampleListTypes();
|
||||
src.f0 = new ArrayList<Integer>();
|
||||
src.f1 = null;
|
||||
src.f2 = new ArrayList<String>();
|
||||
src.f3 = null;
|
||||
src.f4 = new ArrayList<SampleListNestedType>();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleListTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleListTypes.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
SampleListTypes dst = (SampleListTypes) tmpl.convert(mpo);
|
||||
assertEquals(src.f0.size(), dst.f0.size());
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertEquals(src.f2.size(), dst.f2.size());
|
||||
assertEquals(src.f3, dst.f3);
|
||||
assertEquals(src.f4.size(), dst.f4.size());
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListTypes02() throws Exception {
|
||||
SampleListTypes src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleListTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleListTypes.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
SampleListTypes dst = (SampleListTypes) tmpl.convert(mpo);
|
||||
assertEquals(src, dst);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public static class SampleListTypes {
|
||||
public List<Integer> f0;
|
||||
public List<Integer> f1;
|
||||
|
|
@ -205,7 +350,8 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testMapTypes() throws Exception {
|
||||
@Test
|
||||
public void testMapTypes00() throws Exception {
|
||||
SampleMapTypes src = new SampleMapTypes();
|
||||
src.f0 = new HashMap<Integer, Integer>();
|
||||
src.f1 = new HashMap<Integer, Integer>();
|
||||
|
|
@ -217,8 +363,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
src.f2.put("k2", 2);
|
||||
src.f2.put("k3", 3);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(SampleMapTypes.class);
|
||||
MessagePacker packer = DynamicPacker.create(SampleMapTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleMapTypes.class);
|
||||
|
|
@ -249,6 +394,45 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapTypes01() throws Exception {
|
||||
SampleMapTypes src = new SampleMapTypes();
|
||||
src.f0 = new HashMap<Integer, Integer>();
|
||||
src.f1 = null;
|
||||
src.f2 = new HashMap<String, Integer>();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleMapTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleMapTypes.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
SampleMapTypes dst = (SampleMapTypes) tmpl.convert(mpo);
|
||||
assertEquals(src.f0.size(), dst.f0.size());
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertEquals(src.f2.size(), dst.f2.size());
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapTypes02() throws Exception {
|
||||
SampleMapTypes src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleMapTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleMapTypes.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
SampleMapTypes dst = (SampleMapTypes) tmpl.convert(mpo);
|
||||
assertEquals(src, dst);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public static class SampleMapTypes {
|
||||
public Map<Integer, Integer> f0;
|
||||
public Map<Integer, Integer> f1;
|
||||
|
|
@ -307,8 +491,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
DynamicTemplate
|
||||
.create(ProtectedDefaultConstructorClass.class);
|
||||
DynamicTemplate.create(ProtectedDefaultConstructorClass.class);
|
||||
fail();
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
|
|
@ -479,17 +662,15 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEnumTypeForOrdinal() throws Exception {
|
||||
public void testEnumTypeForOrdinal00() throws Exception {
|
||||
SampleEnumFieldClass src = new SampleEnumFieldClass();
|
||||
src.f0 = 0;
|
||||
src.f1 = SampleEnum.ONE;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(SampleEnumFieldClass.class);
|
||||
MessagePacker packer = DynamicPacker.create(SampleEnumFieldClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(SampleEnumFieldClass.class);
|
||||
Template tmpl = DynamicTemplate.create(SampleEnumFieldClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
|
|
@ -497,6 +678,43 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl.convert(mpo);
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertTrue(src.f1 == dst.f1);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumTypeForOrdinal01() throws Exception {
|
||||
SampleEnumFieldClass src = new SampleEnumFieldClass();
|
||||
src.f1 = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleEnumFieldClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleEnumFieldClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl.convert(mpo);
|
||||
assertEquals(src.f0, dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumTypeForOrdinal02() throws Exception {
|
||||
SampleEnumFieldClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleEnumFieldClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleEnumFieldClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl.convert(mpo);
|
||||
assertEquals(src, dst);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public static class SampleEnumFieldClass {
|
||||
|
|
@ -521,12 +739,10 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
src.f3 = 3;
|
||||
src.f4 = 4;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(FieldModifiersClass.class);
|
||||
MessagePacker packer = DynamicPacker.create(FieldModifiersClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(FieldModifiersClass.class);
|
||||
Template tmpl = DynamicTemplate.create(FieldModifiersClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
|
|
@ -552,7 +768,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testNestedFieldClass() throws Exception {
|
||||
public void testNestedFieldClass00() throws Exception {
|
||||
MessagePacker packer2 = DynamicPacker.create(NestedClass.class);
|
||||
CustomPacker.register(NestedClass.class, packer2);
|
||||
MessagePacker packer1 = DynamicPacker.create(BaseClass.class);
|
||||
|
|
@ -581,6 +797,57 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedFieldClass01() throws Exception {
|
||||
MessagePacker packer2 = DynamicPacker.create(NestedClass.class);
|
||||
CustomPacker.register(NestedClass.class, packer2);
|
||||
MessagePacker packer1 = DynamicPacker.create(BaseClass.class);
|
||||
CustomPacker.register(BaseClass.class, packer1);
|
||||
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
||||
CustomUnpacker.register(NestedClass.class, tmpl2);
|
||||
CustomConverter.register(NestedClass.class, tmpl2);
|
||||
Template tmpl1 = DynamicTemplate.create(BaseClass.class);
|
||||
CustomUnpacker.register(BaseClass.class, tmpl1);
|
||||
CustomConverter.register(BaseClass.class, tmpl1);
|
||||
BaseClass src = new BaseClass();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
packer1.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
BaseClass dst = (BaseClass) tmpl1.convert(mpo);
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedFieldClass02() throws Exception {
|
||||
MessagePacker packer2 = DynamicPacker.create(NestedClass.class);
|
||||
CustomPacker.register(NestedClass.class, packer2);
|
||||
MessagePacker packer1 = DynamicPacker.create(BaseClass.class);
|
||||
CustomPacker.register(BaseClass.class, packer1);
|
||||
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
||||
CustomUnpacker.register(NestedClass.class, tmpl2);
|
||||
CustomConverter.register(NestedClass.class, tmpl2);
|
||||
Template tmpl1 = DynamicTemplate.create(BaseClass.class);
|
||||
CustomUnpacker.register(BaseClass.class, tmpl1);
|
||||
CustomConverter.register(BaseClass.class, tmpl1);
|
||||
BaseClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
packer1.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
BaseClass dst = (BaseClass) tmpl1.convert(mpo);
|
||||
assertEquals(src, dst);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public static class BaseClass {
|
||||
public int f0;
|
||||
public NestedClass f1;
|
||||
|
|
@ -597,7 +864,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMessagePackMessageFieldClass() throws Exception {
|
||||
public void testMessagePackMessageFieldClass00() throws Exception {
|
||||
BaseClass2 src = new BaseClass2();
|
||||
MessagePackMessageClass2 src2 = new MessagePackMessageClass2();
|
||||
src.f0 = 0;
|
||||
|
|
@ -618,6 +885,41 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessagePackMessageFieldClass01() throws Exception {
|
||||
BaseClass2 src = new BaseClass2();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(BaseClass2.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
Template tmpl = DynamicTemplate.create(BaseClass2.class);
|
||||
BaseClass2 dst = (BaseClass2) tmpl.convert(mpo);
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessagePackMessageFieldClass02() throws Exception {
|
||||
BaseClass2 src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(BaseClass2.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
Template tmpl = DynamicTemplate.create(BaseClass2.class);
|
||||
BaseClass2 dst = (BaseClass2) tmpl.convert(mpo);
|
||||
assertEquals(src, dst);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public static class BaseClass2 {
|
||||
public int f0;
|
||||
public MessagePackMessageClass2 f1;
|
||||
|
|
@ -635,7 +937,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testExtendedClass() throws Exception {
|
||||
public void testExtendedClass00() throws Exception {
|
||||
SampleSubClass src = new SampleSubClass();
|
||||
src.f0 = 0;
|
||||
src.f2 = 2;
|
||||
|
|
@ -645,8 +947,7 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
src.f8 = 8;
|
||||
src.f9 = 9;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(SampleSubClass.class);
|
||||
MessagePacker packer = DynamicPacker.create(SampleSubClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleSubClass.class);
|
||||
|
|
@ -667,6 +968,23 @@ public class TestDynamicCodeGenPackerConverter extends TestCase {
|
|||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendedClass01() throws Exception {
|
||||
SampleSubClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleSubClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleSubClass.class);
|
||||
Unpacker pac = new Unpacker(in);
|
||||
Iterator<MessagePackObject> it = pac.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
MessagePackObject mpo = it.next();
|
||||
SampleSubClass dst = (SampleSubClass) tmpl.convert(mpo);
|
||||
assertEquals(src, dst);
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public static class SampleSubClass extends SampleSuperClass {
|
||||
public int f0;
|
||||
public final int f1 = 1;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import junit.framework.TestCase;
|
|||
public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTypeFields() throws Exception {
|
||||
public void testPrimitiveTypeFields00() throws Exception {
|
||||
PrimitiveTypeFieldsClass src = new PrimitiveTypeFieldsClass();
|
||||
src.f0 = (byte) 0;
|
||||
src.f1 = 1;
|
||||
|
|
@ -39,8 +39,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
.create(PrimitiveTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(PrimitiveTypeFieldsClass.class);
|
||||
Template tmpl = DynamicTemplate.create(PrimitiveTypeFieldsClass.class);
|
||||
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertEquals(src.f0, dst.f0);
|
||||
|
|
@ -52,6 +51,40 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
assertEquals(src.f6, dst.f6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTypeFields01() throws Exception {
|
||||
PrimitiveTypeFieldsClass src = new PrimitiveTypeFieldsClass();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(PrimitiveTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(PrimitiveTypeFieldsClass.class);
|
||||
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertEquals(src.f0, dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertEquals(src.f2, dst.f2);
|
||||
assertEquals(src.f3, dst.f3);
|
||||
assertEquals(src.f4, dst.f4);
|
||||
assertEquals(src.f5, dst.f5);
|
||||
assertEquals(src.f6, dst.f6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveTypeFields02() throws Exception {
|
||||
PrimitiveTypeFieldsClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(PrimitiveTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(PrimitiveTypeFieldsClass.class);
|
||||
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
public static class PrimitiveTypeFieldsClass {
|
||||
public byte f0;
|
||||
public short f1;
|
||||
|
|
@ -66,7 +99,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGeneralReferenceTypeFieldsClass() throws Exception {
|
||||
public void testGeneralReferenceTypeFieldsClass00() throws Exception {
|
||||
GeneralReferenceTypeFieldsClass src = new GeneralReferenceTypeFieldsClass();
|
||||
src.f0 = 0;
|
||||
src.f1 = 1;
|
||||
|
|
@ -100,6 +133,55 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
assertEquals(src.f9[1], dst.f9[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneralReferenceTypeFieldsClass01() throws Exception {
|
||||
GeneralReferenceTypeFieldsClass src = new GeneralReferenceTypeFieldsClass();
|
||||
src.f0 = null;
|
||||
src.f1 = null;
|
||||
src.f2 = null;
|
||||
src.f3 = null;
|
||||
src.f4 = null;
|
||||
src.f5 = null;
|
||||
src.f6 = null;
|
||||
src.f7 = null;
|
||||
src.f8 = null;
|
||||
src.f9 = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(GeneralReferenceTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(GeneralReferenceTypeFieldsClass.class);
|
||||
GeneralReferenceTypeFieldsClass dst = (GeneralReferenceTypeFieldsClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertEquals(src.f0, dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertEquals(src.f2, dst.f2);
|
||||
assertEquals(src.f3, dst.f3);
|
||||
assertEquals(src.f4, dst.f4);
|
||||
assertEquals(src.f5, dst.f5);
|
||||
assertEquals(src.f6, dst.f6);
|
||||
assertEquals(src.f7, dst.f7);
|
||||
assertEquals(src.f8, dst.f8);
|
||||
assertEquals(src.f9, dst.f9);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneralReferenceTypeFieldsClass02() throws Exception {
|
||||
GeneralReferenceTypeFieldsClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(GeneralReferenceTypeFieldsClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(GeneralReferenceTypeFieldsClass.class);
|
||||
GeneralReferenceTypeFieldsClass dst = (GeneralReferenceTypeFieldsClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
public static class GeneralReferenceTypeFieldsClass {
|
||||
public Byte f0;
|
||||
public Short f1;
|
||||
|
|
@ -116,7 +198,8 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testListTypes() throws Exception {
|
||||
@Test
|
||||
public void testListTypes00() throws Exception {
|
||||
SampleListTypes src = new SampleListTypes();
|
||||
src.f0 = new ArrayList<Integer>();
|
||||
src.f1 = new ArrayList<Integer>();
|
||||
|
|
@ -135,8 +218,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
slnt.f1 = "muga";
|
||||
src.f4.add(slnt);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(SampleListTypes.class);
|
||||
MessagePacker packer = DynamicPacker.create(SampleListTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleListTypes.class);
|
||||
|
|
@ -169,6 +251,39 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListTypes01() throws Exception {
|
||||
SampleListTypes src = new SampleListTypes();
|
||||
src.f0 = new ArrayList<Integer>();
|
||||
src.f1 = null;
|
||||
src.f2 = new ArrayList<String>();
|
||||
src.f3 = new ArrayList<List<String>>();
|
||||
src.f4 = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleListTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleListTypes.class);
|
||||
SampleListTypes dst = (SampleListTypes) tmpl.unpack(new Unpacker(in));
|
||||
assertEquals(src.f0.size(), dst.f0.size());
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertEquals(src.f2.size(), dst.f2.size());
|
||||
assertEquals(src.f3.size(), dst.f3.size());
|
||||
assertEquals(src.f4, dst.f4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListTypes02() throws Exception {
|
||||
SampleListTypes src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleListTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleListTypes.class);
|
||||
SampleListTypes dst = (SampleListTypes) tmpl.unpack(new Unpacker(in));
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
public static class SampleListTypes {
|
||||
public List<Integer> f0;
|
||||
public List<Integer> f1;
|
||||
|
|
@ -189,7 +304,8 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testMapTypes() throws Exception {
|
||||
@Test
|
||||
public void testMapTypes00() throws Exception {
|
||||
SampleMapTypes src = new SampleMapTypes();
|
||||
src.f0 = new HashMap<Integer, Integer>();
|
||||
src.f1 = new HashMap<Integer, Integer>();
|
||||
|
|
@ -201,8 +317,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
src.f2.put("k2", 2);
|
||||
src.f2.put("k3", 3);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(SampleMapTypes.class);
|
||||
MessagePacker packer = DynamicPacker.create(SampleMapTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleMapTypes.class);
|
||||
|
|
@ -228,6 +343,35 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapTypes01() throws Exception {
|
||||
SampleMapTypes src = new SampleMapTypes();
|
||||
src.f0 = new HashMap<Integer, Integer>();
|
||||
src.f1 = null;
|
||||
src.f2 = new HashMap<String, Integer>();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleMapTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleMapTypes.class);
|
||||
SampleMapTypes dst = (SampleMapTypes) tmpl.unpack(new Unpacker(in));
|
||||
assertEquals(src.f0.size(), dst.f0.size());
|
||||
assertEquals(src.f1, dst.f1);
|
||||
assertEquals(src.f2.size(), dst.f2.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapTypes02() throws Exception {
|
||||
SampleMapTypes src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleMapTypes.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleMapTypes.class);
|
||||
SampleMapTypes dst = (SampleMapTypes) tmpl.unpack(new Unpacker(in));
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
public static class SampleMapTypes {
|
||||
public Map<Integer, Integer> f0;
|
||||
public Map<Integer, Integer> f1;
|
||||
|
|
@ -238,7 +382,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultConstructorModifiers01() throws Exception {
|
||||
public void testDefaultConstructorModifiers00() throws Exception {
|
||||
try {
|
||||
DynamicPacker.create(NoDefaultConstructorClass.class);
|
||||
fail();
|
||||
|
|
@ -270,7 +414,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultConstructorModifiers02() throws Exception {
|
||||
public void testDefaultConstructorModifiers01() throws Exception {
|
||||
try {
|
||||
DynamicUnpacker.create(NoDefaultConstructorClass.class);
|
||||
fail();
|
||||
|
|
@ -286,8 +430,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
DynamicUnpacker
|
||||
.create(ProtectedDefaultConstructorClass.class);
|
||||
DynamicUnpacker.create(ProtectedDefaultConstructorClass.class);
|
||||
fail();
|
||||
} catch (DynamicCodeGenException e) {
|
||||
assertTrue(true);
|
||||
|
|
@ -323,7 +466,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testClassModifiers01() throws Exception {
|
||||
public void testClassModifiers00() throws Exception {
|
||||
try {
|
||||
DynamicPacker.create(PrivateModifierClass.class);
|
||||
fail();
|
||||
|
|
@ -348,7 +491,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testClassModifiers02() throws Exception {
|
||||
public void testClassModifiers01() throws Exception {
|
||||
try {
|
||||
DynamicUnpacker.create(PrivateModifierClass.class);
|
||||
fail();
|
||||
|
|
@ -384,7 +527,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFinalClassAndAbstractClass01() throws Exception {
|
||||
public void testFinalClassAndAbstractClass00() throws Exception {
|
||||
try {
|
||||
DynamicPacker.create(FinalModifierClass.class);
|
||||
assertTrue(true);
|
||||
|
|
@ -402,7 +545,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFinalClassAndAbstractClass02() throws Exception {
|
||||
public void testFinalClassAndAbstractClass01() throws Exception {
|
||||
try {
|
||||
DynamicUnpacker.create(FinalModifierClass.class);
|
||||
assertTrue(true);
|
||||
|
|
@ -426,7 +569,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInterfaceType01() throws Exception {
|
||||
public void testInterfaceType00() throws Exception {
|
||||
try {
|
||||
DynamicPacker.create(SampleInterface.class);
|
||||
fail();
|
||||
|
|
@ -437,7 +580,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInterfaceType02() throws Exception {
|
||||
public void testInterfaceType01() throws Exception {
|
||||
try {
|
||||
DynamicUnpacker.create(SampleInterface.class);
|
||||
fail();
|
||||
|
|
@ -451,23 +594,49 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEnumTypeForOrdinal() throws Exception {
|
||||
public void testEnumTypeForOrdinal00() throws Exception {
|
||||
SampleEnumFieldClass src = new SampleEnumFieldClass();
|
||||
src.f0 = 0;
|
||||
src.f1 = SampleEnum.ONE;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(SampleEnumFieldClass.class);
|
||||
MessagePacker packer = DynamicPacker.create(SampleEnumFieldClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(SampleEnumFieldClass.class);
|
||||
Template tmpl = DynamicTemplate.create(SampleEnumFieldClass.class);
|
||||
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertTrue(src.f1 == dst.f1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumTypeForOrdinal01() throws Exception {
|
||||
SampleEnumFieldClass src = new SampleEnumFieldClass();
|
||||
src.f1 = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleEnumFieldClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleEnumFieldClass.class);
|
||||
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumTypeForOrdinal02() throws Exception {
|
||||
SampleEnumFieldClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleEnumFieldClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleEnumFieldClass.class);
|
||||
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
public static class SampleEnumFieldClass {
|
||||
public int f0;
|
||||
|
||||
|
|
@ -490,12 +659,10 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
src.f3 = 3;
|
||||
src.f4 = 4;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(FieldModifiersClass.class);
|
||||
MessagePacker packer = DynamicPacker.create(FieldModifiersClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate
|
||||
.create(FieldModifiersClass.class);
|
||||
Template tmpl = DynamicTemplate.create(FieldModifiersClass.class);
|
||||
FieldModifiersClass dst = (FieldModifiersClass) tmpl
|
||||
.unpack(new Unpacker(in));
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
|
|
@ -517,7 +684,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testNestedFieldClass() throws Exception {
|
||||
public void testNestedFieldClass00() throws Exception {
|
||||
MessagePacker packer2 = DynamicPacker.create(NestedClass.class);
|
||||
CustomPacker.register(NestedClass.class, packer2);
|
||||
MessagePacker packer1 = DynamicPacker.create(BaseClass.class);
|
||||
|
|
@ -541,6 +708,48 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
assertTrue(src.f1.f2 == dst.f1.f2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedFieldClass01() throws Exception {
|
||||
MessagePacker packer2 = DynamicPacker.create(NestedClass.class);
|
||||
CustomPacker.register(NestedClass.class, packer2);
|
||||
MessagePacker packer1 = DynamicPacker.create(BaseClass.class);
|
||||
CustomPacker.register(BaseClass.class, packer1);
|
||||
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
||||
CustomUnpacker.register(NestedClass.class, tmpl2);
|
||||
CustomConverter.register(NestedClass.class, tmpl2);
|
||||
Template tmpl1 = DynamicTemplate.create(BaseClass.class);
|
||||
CustomUnpacker.register(BaseClass.class, tmpl1);
|
||||
CustomConverter.register(BaseClass.class, tmpl1);
|
||||
BaseClass src = new BaseClass();
|
||||
src.f1 = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
packer1.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
BaseClass dst = (BaseClass) tmpl1.unpack(new Unpacker(in));
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertTrue(src.f1 == dst.f1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedFieldClass02() throws Exception {
|
||||
MessagePacker packer2 = DynamicPacker.create(NestedClass.class);
|
||||
CustomPacker.register(NestedClass.class, packer2);
|
||||
MessagePacker packer1 = DynamicPacker.create(BaseClass.class);
|
||||
CustomPacker.register(BaseClass.class, packer1);
|
||||
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
||||
CustomUnpacker.register(NestedClass.class, tmpl2);
|
||||
CustomConverter.register(NestedClass.class, tmpl2);
|
||||
Template tmpl1 = DynamicTemplate.create(BaseClass.class);
|
||||
CustomUnpacker.register(BaseClass.class, tmpl1);
|
||||
CustomConverter.register(BaseClass.class, tmpl1);
|
||||
BaseClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
packer1.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
BaseClass dst = (BaseClass) tmpl1.unpack(new Unpacker(in));
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
public static class BaseClass {
|
||||
public int f0;
|
||||
public NestedClass f1;
|
||||
|
|
@ -557,7 +766,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMessagePackMessageFieldClass() throws Exception {
|
||||
public void testMessagePackMessageFieldClass00() throws Exception {
|
||||
BaseClass2 src = new BaseClass2();
|
||||
MessagePackMessageClass2 src2 = new MessagePackMessageClass2();
|
||||
src.f0 = 0;
|
||||
|
|
@ -573,6 +782,32 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
assertTrue(src.f1.f2 == dst.f1.f2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessagePackMessageFieldClass01() throws Exception {
|
||||
BaseClass2 src = new BaseClass2();
|
||||
src.f1 = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(BaseClass2.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(BaseClass2.class);
|
||||
BaseClass2 dst = (BaseClass2) tmpl.unpack(new Unpacker(in));
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertEquals(src.f1, dst.f1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessagePackMessageFieldClass02() throws Exception {
|
||||
BaseClass2 src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(BaseClass2.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(BaseClass2.class);
|
||||
BaseClass2 dst = (BaseClass2) tmpl.unpack(new Unpacker(in));
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
public static class BaseClass2 {
|
||||
public int f0;
|
||||
public MessagePackMessageClass2 f1;
|
||||
|
|
@ -590,7 +825,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testExtendedClass() throws Exception {
|
||||
public void testExtendedClass00() throws Exception {
|
||||
SampleSubClass src = new SampleSubClass();
|
||||
src.f0 = 0;
|
||||
src.f2 = 2;
|
||||
|
|
@ -600,8 +835,7 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
src.f8 = 8;
|
||||
src.f9 = 9;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker
|
||||
.create(SampleSubClass.class);
|
||||
MessagePacker packer = DynamicPacker.create(SampleSubClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleSubClass.class);
|
||||
|
|
@ -617,6 +851,18 @@ public class TestDynamicCodeGenPackerUnpacker extends TestCase {
|
|||
assertTrue(src.f9 != dst.f9);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendedClass01() throws Exception {
|
||||
SampleSubClass src = null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagePacker packer = DynamicPacker.create(SampleSubClass.class);
|
||||
packer.pack(new Packer(out), src);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Template tmpl = DynamicTemplate.create(SampleSubClass.class);
|
||||
SampleSubClass dst = (SampleSubClass) tmpl.unpack(new Unpacker(in));
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
public static class SampleSubClass extends SampleSuperClass {
|
||||
public int f0;
|
||||
public final int f1 = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue