use of java.io.ObjectStreamClass in project j2objc by google.
the class MyObjectInputStream method test_getType_MockObjectInputStream.
/**
* java.io.ObjectStreamField#getType()
*/
public void test_getType_MockObjectInputStream() throws IOException, ClassNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(new SerializableObject());
oos.close();
baos.close();
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
MockObjectInputStream ois = new MockObjectInputStream(bais);
ois.readObject();
ObjectStreamClass oc = ois.getObjectStreamClass();
ObjectStreamField field = oc.getField("i");
assertEquals(Object.class, field.getType());
}
use of java.io.ObjectStreamClass in project j2objc by google.
the class MyObjectInputStream method test_isUnshared.
public void test_isUnshared() throws Exception {
SerializableObject2 obj = new SerializableObject2();
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
oos.close();
baos.close();
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
SerializableObject2 newObj = (SerializableObject2) ois.readObject();
ObjectInputStream.GetField getField = newObj.getGetField();
ObjectStreamClass objectStreamClass = getField.getObjectStreamClass();
assertTrue(objectStreamClass.getField("i").isUnshared());
assertFalse(objectStreamClass.getField("d").isUnshared());
assertTrue(objectStreamClass.getField("s").isUnshared());
assertEquals(1000, getField.get("i", null));
assertEquals(SerializableObject2.today, getField.get("d", null));
assertEquals("Richard", getField.get("s", null));
assertTrue(objectStreamClass.getField("s").getTypeString() == "Ljava/lang/String;");
assertEquals(0, objectStreamClass.getField("d").getOffset());
assertEquals(1, objectStreamClass.getField("i").getOffset());
assertEquals(2, objectStreamClass.getField("s").getOffset());
}
use of java.io.ObjectStreamClass in project j2objc by google.
the class ObjectStreamClassTest method test_getFieldLjava_lang_String.
/**
* java.io.ObjectStreamClass#getField(java.lang.String)
*/
public void test_getFieldLjava_lang_String() {
ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
assertEquals("getField did not return correct field", 'J', osc.getField("bam").getTypeCode());
assertNull("getField did not null for non-existent field", osc.getField("wham"));
}
use of java.io.ObjectStreamClass in project j2objc by google.
the class ObjectStreamClassTest method test_forClass.
/**
* java.io.ObjectStreamClass#forClass()
*/
public void test_forClass() {
// Need to test during serialization to be sure an instance is
// returned
ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
assertEquals("forClass returned an object: " + osc.forClass(), DummyClass.class, osc.forClass());
}
use of java.io.ObjectStreamClass in project j2objc by google.
the class ObjectStreamClassTest method test_getFields.
/**
* java.io.ObjectStreamClass#getFields()
*/
public void test_getFields() {
ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
ObjectStreamField[] osfArray = osc.getFields();
assertTrue("Array of fields should be of length 2 but is instead of length: " + osfArray.length, osfArray.length == 2);
}
Aggregations