def testNonNullableNullUnionInArray(self): s = test_unions_mojom.SmallStruct() s.pod_union_array = [ test_unions_mojom.PodUnion(f_uint32=32), None, test_unions_mojom.PodUnion(f_uint64=64), ] with self.assertRaises(serialization.SerializationException): s.Serialize()
def testUnionInMap(self): s = test_unions_mojom.SmallStruct() s.pod_union_map = { 'f_uint32': test_unions_mojom.PodUnion(f_uint32=32), 'f_uint16': test_unions_mojom.PodUnion(f_uint16=16), 'f_uint64': test_unions_mojom.PodUnion(f_uint64=64), } (data, handles) = s.Serialize() context = serialization.RootDeserializationContext(data, handles) decoded = test_unions_mojom.SmallStruct.Deserialize(context) self.assertEquals(s, decoded)
def testNullableNullUnionInArray(self): s = test_unions_mojom.SmallStruct() s.nullable_pod_union_array = [ test_unions_mojom.PodUnion(f_uint32=32), None, test_unions_mojom.PodUnion(f_uint64=64), ] (data, handles) = s.Serialize() context = serialization.RootDeserializationContext(data, handles) decoded = test_unions_mojom.SmallStruct.Deserialize(context) self.assertEquals(s, decoded)
def testUnionInObject(self): s = test_unions_mojom.SmallStruct() s.pod_union = test_unions_mojom.PodUnion(f_uint32=32) (data, handles) = s.Serialize() # This is where the data should be serialized to. size, tag, value = struct.unpack_from('<IIQ', buffer(data), 16) self.assertEquals(16, size) self.assertEquals(6, tag) self.assertEquals(32, value) context = serialization.RootDeserializationContext(data, handles) decoded = test_unions_mojom.SmallStruct.Deserialize(context) self.assertEquals(s, decoded)