def test_execute_multiple_fields(self): from VM import VM vm = VM() c = ClassDefinition() c.namespace = 'a' c.name = 'b' v = Variable() v.name = 'abc' v.type = Types.Int32 v2 = Variable() v2.name = 'def' v2.type = Types.Int32 c.fieldDefinitions.append(v2) r = ReferenceType() t = Types.register_custom_type(c) r.type = t r.add_field(v) r.add_field(v2) vm.stack.push(r) x = ldfld('int32 ConsoleApplication1.foo::def') x.execute(vm) self.assertEqual(vm.stack.count(), 1) self.assertEqual(r.fields[1], vm.stack.pop())
def test_execute_reference_type_parameter(self): from VM import VM vm = VM() foo = ClassDefinition() foo.namespace = 'ConsoleApplication1' foo.name = 'foo' fooType = Types.register_custom_type(foo) fooObject = ReferenceType() fooObject.name = 'f' fooObject.type = fooType fooObject.value = Variable(3333) bar = ClassDefinition() bar.namespace = 'ConsoleApplication1' bar.name = 'bar' barType = Types.register_custom_type(bar) barObject = ReferenceType() barObject.type = barType field = ReferenceType() field.name = 'f' field.type = fooType barObject.add_field(field) vm.stack.push(barObject) x = ldfld('class ConsoleApplication1.foo ConsoleApplication1.bar::f') x.execute(vm) self.assertEqual(vm.stack.count(), 1) self.assertEqual(barObject.fields[0], vm.stack.pop())
def test_execute_int_parameter(self): from VM import VM vm = VM() c = ClassDefinition() c.namespace = 'a' c.name = 'b' v = Variable() v.name = 'xyz' v.type = Types.Int32 r = ReferenceType() t = Types.register_custom_type(c) r.type = t r.add_field(v) vm.stack.push(r) vm.stack.push(Variable(9876)) x = stfld('int32 a.b::xyz') x.execute(vm) self.assertEqual(vm.stack.count(), 0) self.assertEqual(r.fields[0].value, 9876)
def test_execute_single_field(self): from VM import VM vm = VM() c = ClassDefinition() c.namespace = 'ConsoleApplication1' c.name = 'foo' v = Variable() v.name = 'z' v.type = Types.Int32 r = ReferenceType() t = Types.register_custom_type(c) r.type = t r.add_field(v) vm.stack.push(r) x = ldfld('int32 ConsoleApplication1.foo::z') x.execute(vm) self.assertEqual(vm.stack.count(), 1) self.assertEqual(r.fields[0], vm.stack.pop())