mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 10:19:51 +00:00
fixed several bugs of a verify error within annotation-utilities
This commit is contained in:
parent
95b820305a
commit
c7f8b94ccd
2 changed files with 270 additions and 60 deletions
|
|
@ -3,6 +3,8 @@ package org.msgpack.util.annotation;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -14,7 +16,7 @@ import org.msgpack.Unpacker;
|
|||
public class TestMessagePackUnpackable extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testGeneralPrimitiveTypeFieldsClass() throws Exception {
|
||||
public void testGeneralPrimitiveTypeFields() throws Exception {
|
||||
GeneralPrimitiveTypeFieldsClass src = (GeneralPrimitiveTypeFieldsClass) PackUnpackUtil
|
||||
.newEnhancedInstance(GeneralPrimitiveTypeFieldsClass.class);
|
||||
src.f0 = (byte) 0;
|
||||
|
|
@ -101,8 +103,21 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testListAndMap() throws Exception {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@MessagePackUnpackable
|
||||
public static class ListAndMapClass {
|
||||
public List<String> f0;
|
||||
public Map<String, String> f1;
|
||||
|
||||
public ListAndMapClass() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublicDefaultConstructorClass() throws Exception {
|
||||
public void testDefaultConstructorModifiers() throws Exception {
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(NoDefaultConstructorClass.class);
|
||||
fail();
|
||||
|
|
@ -111,21 +126,24 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(PrivateDefaultConstructorClass.class);
|
||||
PackUnpackUtil
|
||||
.newEnhancedInstance(PrivateDefaultConstructorClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(ProtectedDefaultConstructorClass.class);
|
||||
PackUnpackUtil
|
||||
.newEnhancedInstance(ProtectedDefaultConstructorClass.class);
|
||||
assertTrue(true);
|
||||
} catch (PackUnpackUtilException e) {
|
||||
fail();
|
||||
}
|
||||
assertTrue(true);
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(PackageDefaultConstructorClass.class);
|
||||
PackUnpackUtil
|
||||
.newEnhancedInstance(PackageDefaultConstructorClass.class);
|
||||
fail();
|
||||
} catch (PackUnpackUtilException e) {
|
||||
assertTrue(true);
|
||||
|
|
@ -158,7 +176,7 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPublicModifierClass() throws Exception {
|
||||
public void testClassModifiers() throws Exception {
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(PrivateModifierClass.class);
|
||||
fail();
|
||||
|
|
@ -197,7 +215,7 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFinalAndAbstractModifierClass() throws Exception {
|
||||
public void testFinalClassAndAbstractClass() throws Exception {
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(FinalModifierClass.class);
|
||||
fail();
|
||||
|
|
@ -223,7 +241,7 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInterfaceAndEnum() throws Exception {
|
||||
public void testInterfaceAndEnumType() throws Exception {
|
||||
try {
|
||||
PackUnpackUtil.newEnhancedInstance(SampleInterface.class);
|
||||
fail();
|
||||
|
|
@ -249,32 +267,128 @@ public class TestMessagePackUnpackable extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFinalFieldClass() throws Exception {
|
||||
|
||||
public void testFieldModifiers() throws Exception {
|
||||
FieldModifiersClass src = (FieldModifiersClass) PackUnpackUtil
|
||||
.newEnhancedInstance(FieldModifiersClass.class);
|
||||
src.f0 = 0;
|
||||
src.f2 = 2;
|
||||
src.f3 = 3;
|
||||
src.f4 = 4;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
new Packer(out).pack(src);
|
||||
FieldModifiersClass dst = (FieldModifiersClass) PackUnpackUtil
|
||||
.newEnhancedInstance(FieldModifiersClass.class);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Unpacker pac = new Unpacker(in);
|
||||
pac.unpack((MessageUnpackable) dst);
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertTrue(src.f1 == dst.f1);
|
||||
assertTrue(src.f2 != dst.f2);
|
||||
assertTrue(src.f3 == dst.f3);
|
||||
assertTrue(src.f4 != dst.f4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrivateFieldClass() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtectedFieldClass() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonModifierFieldClass() throws Exception {
|
||||
@MessagePackUnpackable
|
||||
public static class FieldModifiersClass {
|
||||
public int f0;
|
||||
public final int f1 = 1;
|
||||
private int f2;
|
||||
protected int f3;
|
||||
int f4;
|
||||
|
||||
public FieldModifiersClass() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedAnnotatedFieldClass() throws Exception {
|
||||
NestedClass src2 = (NestedClass) PackUnpackUtil
|
||||
.newEnhancedInstance(NestedClass.class);
|
||||
BaseClass src = (BaseClass) PackUnpackUtil
|
||||
.newEnhancedInstance(BaseClass.class);
|
||||
src.f0 = 0;
|
||||
src2.f2 = 2;
|
||||
src.f1 = src2;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
new Packer(out).pack(src);
|
||||
NestedClass dst2 = (NestedClass) PackUnpackUtil
|
||||
.newEnhancedInstance(NestedClass.class);
|
||||
BaseClass dst = (BaseClass) PackUnpackUtil
|
||||
.newEnhancedInstance(BaseClass.class);
|
||||
dst.f1 = dst2;
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Unpacker pac = new Unpacker(in);
|
||||
pac.unpack((MessageUnpackable) dst);
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertTrue(src2.f2 == dst.f1.f2);
|
||||
}
|
||||
|
||||
@MessagePackUnpackable
|
||||
public static class BaseClass {
|
||||
public int f0;
|
||||
public NestedClass f1;
|
||||
|
||||
public BaseClass() {
|
||||
}
|
||||
}
|
||||
|
||||
@MessagePackUnpackable
|
||||
public static class NestedClass {
|
||||
public int f2;
|
||||
|
||||
public NestedClass() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuperClass() throws Exception {
|
||||
public void testExtendedClass() throws Exception {
|
||||
SampleSubClass src = (SampleSubClass) PackUnpackUtil
|
||||
.newEnhancedInstance(SampleSubClass.class);
|
||||
src.f0 = 0;
|
||||
src.f2 = 2;
|
||||
src.f3 = 3;
|
||||
src.f4 = 4;
|
||||
src.f5 = 5;
|
||||
src.f8 = 8;
|
||||
src.f9 = 9;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
new Packer(out).pack(src);
|
||||
SampleSubClass dst = (SampleSubClass) PackUnpackUtil
|
||||
.newEnhancedInstance(SampleSubClass.class);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
Unpacker pac = new Unpacker(in);
|
||||
pac.unpack((MessageUnpackable) dst);
|
||||
assertTrue(src.f0 == dst.f0);
|
||||
assertTrue(src.f1 == dst.f1);
|
||||
assertTrue(src.f2 != dst.f2);
|
||||
assertTrue(src.f3 == dst.f3);
|
||||
assertTrue(src.f4 != dst.f4);
|
||||
assertTrue(src.f5 == dst.f5);
|
||||
assertTrue(src.f6 == dst.f6);
|
||||
assertTrue(src.f8 == dst.f8);
|
||||
assertTrue(src.f9 != dst.f9);
|
||||
}
|
||||
|
||||
@MessagePackUnpackable
|
||||
public static class SampleSubClass extends SampleSuperClass {
|
||||
public int f0;
|
||||
public final int f1 = 1;
|
||||
private int f2;
|
||||
protected int f3;
|
||||
int f4;
|
||||
|
||||
public SampleSubClass() {
|
||||
}
|
||||
}
|
||||
|
||||
public static class SampleSuperClass {
|
||||
public int f5;
|
||||
public final int f6 = 2;
|
||||
private int f7;
|
||||
protected int f8;
|
||||
int f9;
|
||||
|
||||
public SampleSuperClass() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue