Exemple #1
0
    def testMonkeyPatchOnVirtualMethod(self):
        '''Injects new 'virtualMethod0' on a VirtualMethods instance and makes C++ call it.'''
        vm = VirtualMethods()
        pt, val, cpx, b = Point(1.1, 2.2), 4, complex(3.3, 4.4), True

        result1 = vm.virtualMethod0(pt, val, cpx, b)
        result2 = vm.callVirtualMethod0(pt, val, cpx, b)
        self.assertEqual(result1, result2)
        self.assertEqual(result1,
                         VirtualMethods.virtualMethod0(vm, pt, val, cpx, b))

        def myVirtualMethod0(obj, pt, val, cpx, b):
            self.duck_method_called = True
            return VirtualMethods.virtualMethod0(obj, pt, val, cpx,
                                                 b) * self.multiplier

        vm.virtualMethod0 = MethodTypeCompat(myVirtualMethod0, vm)

        result1 = vm.callVirtualMethod0(pt, val, cpx, b)
        self.assertTrue(self.duck_method_called)

        result2 = vm.virtualMethod0(pt, val, cpx, b)
        self.assertEqual(result1, result2)
        self.assertEqual(
            result1,
            VirtualMethods.virtualMethod0(vm, pt, val, cpx, b) *
            self.multiplier)

        # This is done to decrease the refcount of the vm object
        # allowing the object wrapper to be deleted before the
        # BindingManager. This is useful when compiling Shiboken
        # for debug, since the BindingManager destructor has an
        # assert that checks if the wrapper mapper is empty.
        vm.virtualMethod0 = None
Exemple #2
0
 def testForInfiniteRecursion(self):
     def myVirtualMethod0(obj, pt, val, cpx, b):
         self.call_counter += 1
         return VirtualMethods.virtualMethod0(obj, pt, val, cpx, b)
     vm = VirtualMethods()
     vm.virtualMethod0 = MethodTypeCompat(myVirtualMethod0, vm)
     pt, val, cpx, b = Point(1.1, 2.2), 4, complex(3.3, 4.4), True
     vm.virtualMethod0(pt, val, cpx, b)
     self.assertEqual(self.call_counter, 1)
Exemple #3
0
 def testCallNonReimplementedMethodWithString(self):
     '''Calls createStr method from C++ with a Python string argument.'''
     obj = VirtualMethods()
     ok, string = obj.callCreateStr('foo')
     self.assertTrue(ok)
     self.assertEqual(string, Str('foo'))
Exemple #4
0
 def testCallNonReimplementedMethodWithNone(self):
     '''Calls createStr method from C++ with a None argument.'''
     obj = VirtualMethods()
     ok, string = obj.callCreateStr(None)
     self.assertFalse(ok)
     self.assertEqual(string, None)
Exemple #5
0
 def testSimpleCallWithString(self):
     '''Simple call to createStr method with a Python string argument.'''
     obj = VirtualMethods()
     ok, string = obj.createStr('foo')
     self.assertTrue(ok)
     self.assertEqual(string, Str('foo'))
Exemple #6
0
 def testSimpleCallWithNone(self):
     '''Simple call to createStr method with a None argument.'''
     obj = VirtualMethods()
     ok, string = obj.createStr(None)
     self.assertFalse(ok)
     self.assertEqual(string, None)
 def setUp(self):
     self.vm = VirtualMethods()
     self.evm = ExtendedVirtualMethods()