Add (de)serializeObject test
package org.aion.avm.core.persistence;
-import org.aion.avm.core.util.Helpers;
import i.IObjectDeserializer;
import i.IObjectSerializer;
import i.RuntimeAssertionError;
-import org.junit.Assert;
+import org.aion.avm.core.util.Helpers;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.Assert;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
-
public class SerializerTest {
// NOTE: Output is ONLY produced if REPORT is set to true.
private static final boolean REPORT = false;
@@ -35,6 +34,35 @@ public class SerializerTest {
this.cache = new SortedFieldCache(SerializerTest.class.getClassLoader(), serializeSelf, deserializeSelf, readIndex);
}
+ @Test
+ public void testSimpleObject() throws Exception {
+ ByteBuffer buffer = ByteBuffer.allocate(1000);
+ TestGlobalResolver resolver = new TestGlobalResolver();
+ TestNameMapper classNameMapper = new TestNameMapper();
+
+ TargetRoot.root = new TargetRoot();
+ TargetRoot.root.counter = 1;
+ TargetLeaf next = new TargetLeaf();
+ next.counter = 2;
+ next.left = TargetRoot.root;
+ next.right = next;
+ TargetRoot.root.next = next;
+
+ Serializer.serializeObject(buffer, TargetRoot.root, resolver, this.cache,
+ classNameMapper);
+ byte[] finalBytes = new byte[buffer.position()];
+ System.arraycopy(buffer.array(), 0, finalBytes, 0, finalBytes.length);
+ ByteBuffer rbuffer = ByteBuffer.wrap(finalBytes);
+ TargetRoot root = (TargetRoot) Deserializer.deserializeObject(rbuffer,
+ resolver, this.cache, classNameMapper);
+
+ Assert.assertEquals(1, root.counter);
+ TargetLeaf checkNext = (TargetLeaf) root.next;
+ Assert.assertEquals(2, checkNext.counter);
+ Assert.assertTrue(root == checkNext.left);
+ Assert.assertTrue(checkNext == checkNext.right);
+ }
+
@Test
public void testSimpleCase() throws Exception {
ByteBuffer buffer = ByteBuffer.allocate(1000);
@@ -387,12 +415,14 @@ public class SerializerTest {
? ((Class<?>) target).getName()
: null;
}
+
@Override
public int getAsConstant(Object target) {
return (TEST_CONSTANT == target)
? 1
: 0;
}
+
@Override
public Object getClassObjectForInternalName(String internalClassName) {
try {
@@ -402,6 +432,7 @@ public class SerializerTest {
throw RuntimeAssertionError.unexpected(e);
}
}
+
@Override
public Object getConstantForIdentifier(int constantIdentifier) {
return (1 == constantIdentifier)
@@ -416,6 +447,7 @@ public class SerializerTest {
// For testing purposes, we will say that the name mapping is to the simple name.
return ourName.substring("org.aion.avm.core.persistence.".length());
}
+
@Override
public String getInternalClassName(String storageClassName) {
return "org.aion.avm.core.persistence." + storageClassName;
