def testRefCountingOfReferredObjectAfterDeletingReferrer(self):
     '''Deleting the object referring to other object should decrease the reference count of the referee.'''
     d = Derived()
     o = ObjectType()
     refcount = getrefcount(o)
     d.objectTypeField = o
     self.assertEqual(getrefcount(o), refcount + 1)
     del d
     self.assertEqual(getrefcount(o), refcount)
Beispiel #2
0
 def testRefCountingOfReferredObjectAfterDeletingReferrer(self):
     '''Deleting the object referring to other object should decrease the reference count of the referee.'''
     d = Derived()
     o = ObjectType()
     refcount = getrefcount(o)
     d.objectTypeField = o
     self.assertEqual(getrefcount(o), refcount + 1)
     del d
     self.assertEqual(getrefcount(o), refcount)
Beispiel #3
0
    def testOtherOverloadedMethodCall(self):
        '''Another test to check overloaded method calling, just to double check.'''
        derived = Derived()

        result = derived.otherOverloaded(1, 2, True, 3.3)
        self.assertEqual(type(result), Derived.OtherOverloadedFuncEnum)
        self.assertEqual(result, sample.Derived.OtherOverloadedFunc_iibd)

        result = derived.otherOverloaded(1, 2.2)
        self.assertEqual(type(result), Derived.OtherOverloadedFuncEnum)
        self.assertEqual(result, Derived.OtherOverloadedFunc_id)
    def testOtherOverloadedMethodCall(self):
        '''Another test to check overloaded method calling, just to double check.'''
        derived = Derived()

        result = derived.otherOverloaded(1, 2, True, 3.3)
        self.assertEqual(type(result), Derived.OtherOverloadedFuncEnum)
        self.assertEqual(result, sample.Derived.OtherOverloadedFunc_iibd)

        result = derived.otherOverloaded(1, 2.2)
        self.assertEqual(type(result), Derived.OtherOverloadedFuncEnum)
        self.assertEqual(result, Derived.OtherOverloadedFunc_id)
    def testAccessingUsersPrimitiveTypeField(self):
        '''Reads and writes an user's primitive type (in this case an 'Complex') field.'''
        d = Derived()
        self.assertEqual(type(d.userPrimitiveField), complex)

        # attribution
        old_value = d.userPrimitiveField
        new_value = complex(1.1, 2.2)
        d.userPrimitiveField = new_value
        self.assertEqual(d.userPrimitiveField, new_value)
        self.assertNotEqual(d.userPrimitiveField, old_value)

        # attribution with invalid type
        self.assertRaises(TypeError, lambda : setattr(d, 'userPrimitiveField', None))
Beispiel #6
0
    def testAccessingUsersPrimitiveTypeField(self):
        '''Reads and writes an user's primitive type (in this case an 'Complex') field.'''
        d = Derived()
        self.assertEqual(type(d.userPrimitiveField), complex)

        # attribution
        old_value = d.userPrimitiveField
        new_value = complex(1.1, 2.2)
        d.userPrimitiveField = new_value
        self.assertEqual(d.userPrimitiveField, new_value)
        self.assertNotEqual(d.userPrimitiveField, old_value)

        # attribution with invalid type
        self.assertRaises(TypeError, lambda : setattr(d, 'userPrimitiveField', None))
    def testOverloadedMethodCall(self):
        '''Test if the correct overloaded method is being called.'''
        derived = Derived()

        result = derived.overloaded(1, 2)
        self.assertEqual(type(result), OverloadedFuncEnum)
        self.assertEqual(result, sample.OverloadedFunc_ii)

        result = derived.overloaded(3)
        self.assertEqual(type(result), OverloadedFuncEnum)
        self.assertEqual(result, sample.OverloadedFunc_ii)

        result = derived.overloaded(4.4)
        self.assertEqual(type(result), OverloadedFuncEnum)
        self.assertEqual(result, sample.OverloadedFunc_d)
Beispiel #8
0
    def testOverloadedMethodCall(self):
        '''Test if the correct overloaded method is being called.'''
        derived = Derived()

        result = derived.overloaded(1, 2)
        self.assertEqual(type(result), OverloadedFuncEnum)
        self.assertEqual(result, sample.OverloadedFunc_ii)

        result = derived.overloaded(3)
        self.assertEqual(type(result), OverloadedFuncEnum)
        self.assertEqual(result, sample.OverloadedFunc_ii)

        result = derived.overloaded(4.4)
        self.assertEqual(type(result), OverloadedFuncEnum)
        self.assertEqual(result, sample.OverloadedFunc_d)
    def testAccessingUnsignedIntBitField(self):
        d = Derived()

        # attribution
        old_value = d.bitField
        new_value = 1
        d.bitField = new_value
        self.assertEqual(d.bitField, new_value)
        self.assertNotEqual(d.bitField, old_value)

        # attribution with a convertible type
        value = 1.2
        d.bitField = value
        self.assertEqual(d.bitField, int(value))

        # attribution with invalid type
        self.assertRaises(TypeError, lambda: setattr(d, 'bitField', None))
Beispiel #10
0
    def testAccessingUnsignedIntBitField(self):
        d = Derived()

        # attribution
        old_value = d.bitField
        new_value = 1
        d.bitField= new_value
        self.assertEqual(d.bitField, new_value)
        self.assertNotEqual(d.bitField, old_value)

        # attribution with a convertible type
        value = 1.2
        d.bitField = value
        self.assertEqual(d.bitField, int(value))

        # attribution with invalid type
        self.assertRaises(TypeError, lambda : setattr(d, 'bitField', None))
Beispiel #11
0
    def testAccessingObjectTypeField(self):
        '''Reads and writes a object type (in this case an 'ObjectType') field.'''
        d = Derived()

        # attribution
        old_value = d.objectTypeField
        new_value = ObjectType()
        d.objectTypeField = new_value
        self.assertEqual(d.objectTypeField, new_value)
        self.assertNotEqual(d.objectTypeField, old_value)

        # attribution with a convertible type
        value = None
        d.objectTypeField = value
        self.assertEqual(d.objectTypeField, value)

        # attribution with invalid type
        self.assertRaises(TypeError, lambda : setattr(d, 'objectTypeField', 123))
    def testAccessingObjectTypeField(self):
        '''Reads and writes a object type (in this case an 'ObjectType') field.'''
        d = Derived()

        # attribution
        old_value = d.objectTypeField
        new_value = ObjectType()
        d.objectTypeField = new_value
        self.assertEqual(d.objectTypeField, new_value)
        self.assertNotEqual(d.objectTypeField, old_value)

        # attribution with a convertible type
        value = None
        d.objectTypeField = value
        self.assertEqual(d.objectTypeField, value)

        # attribution with invalid type
        self.assertRaises(TypeError, lambda : setattr(d, 'objectTypeField', 123))
Beispiel #13
0
    def testRefCountingAccessingObjectTypeField(self):
        '''Accessing a object type field should respect the reference counting rules.'''
        d = Derived()

        # attributing object to instance's field should increase its reference count
        o1 = ObjectType()
        refcount1 = getrefcount(o1)
        d.objectTypeField = o1
        self.assertEqual(d.objectTypeField, o1)
        self.assertEqual(getrefcount(d.objectTypeField), refcount1 + 1)

        # attributing a new object to instance's field should decrease the previous object's reference count
        o2 = ObjectType()
        refcount2 = getrefcount(o2)
        d.objectTypeField = o2
        self.assertEqual(d.objectTypeField, o2)
        self.assertEqual(getrefcount(o1), refcount1)
        self.assertEqual(getrefcount(d.objectTypeField), refcount2 + 1)
    def testRefCountingAccessingObjectTypeField(self):
        '''Accessing a object type field should respect the reference counting rules.'''
        d = Derived()

        # attributing object to instance's field should increase its reference count
        o1 = ObjectType()
        refcount1 = getrefcount(o1)
        d.objectTypeField = o1
        self.assertEqual(d.objectTypeField, o1)
        self.assertEqual(getrefcount(d.objectTypeField), refcount1 + 1)

        # attributing a new object to instance's field should decrease the previous object's reference count
        o2 = ObjectType()
        refcount2 = getrefcount(o2)
        d.objectTypeField = o2
        self.assertEqual(d.objectTypeField, o2)
        self.assertEqual(getrefcount(o1), refcount1)
        self.assertEqual(getrefcount(d.objectTypeField), refcount2 + 1)
Beispiel #15
0
    def testAccessingValueTypeField(self):
        '''Reads and writes a value type (in this case a 'Point') field.'''
        d = Derived()
        self.assertEqual(type(d.valueTypeField), Point)

        # attribution
        old_value = d.valueTypeField
        new_value = Point(-10, 537)
        d.valueTypeField = new_value
        self.assertEqual(d.valueTypeField, new_value)

        #object modify
        d.valueTypeField.setX(10)
        d.valueTypeField.setY(20)
        self.assertEqual(d.valueTypeField.x(), 10)
        self.assertEqual(d.valueTypeField.y(), 20)

        # attribution with invalid type
        self.assertRaises(TypeError, lambda : setattr(d, 'valueTypeField', 123))
    def testAccessingPrimitiveTypeField(self):
        '''Reads and writes a primitive type (in this case an 'int') field.'''
        d = Derived()
        self.assertEqual(type(d.primitiveField), int)

        # attribution
        old_value = d.primitiveField
        new_value = 2255
        d.primitiveField = new_value
        self.assertEqual(d.primitiveField, new_value)
        self.assertNotEqual(d.primitiveField, old_value)

        # attribution with a convertible type
        value = 1.2
        d.primitiveField = value
        self.assertEqual(d.primitiveField, int(value))

        # attribution with invalid type
        self.assertRaises(TypeError, lambda : setattr(d, 'primitiveField', None))
    def testAccessingValueTypeField(self):
        '''Reads and writes a value type (in this case a 'Point') field.'''
        d = Derived()
        self.assertEqual(type(d.valueTypeField), Point)

        # attribution
        old_value = d.valueTypeField
        new_value = Point(-10, 537)
        d.valueTypeField = new_value
        self.assertEqual(d.valueTypeField, new_value)

        #object modify
        d.valueTypeField.setX(10)
        d.valueTypeField.setY(20)
        self.assertEqual(d.valueTypeField.x(), 10)
        self.assertEqual(d.valueTypeField.y(), 20)

        # attribution with invalid type
        self.assertRaises(TypeError, lambda: setattr(d, 'valueTypeField', 123))
Beispiel #18
0
    def testAccessingPrimitiveTypeField(self):
        '''Reads and writes a primitive type (in this case an 'int') field.'''
        d = Derived()
        self.assertEqual(type(d.primitiveField), int)

        # attribution
        old_value = d.primitiveField
        new_value = 2255
        d.primitiveField = new_value
        self.assertEqual(d.primitiveField, new_value)
        self.assertNotEqual(d.primitiveField, old_value)

        # attribution with a convertible type
        value = 1.2
        d.primitiveField = value
        self.assertEqual(d.primitiveField, int(value))

        # attribution with invalid type
        self.assertRaises(TypeError, lambda : setattr(d, 'primitiveField', None))
 def testMethodCallWithDefaultValue(self):
     '''Test method call with default value.'''
     d = Derived()
     self.assertEqual(d.defaultValue(3), 3.1)
     self.assertEqual(d.defaultValue(), 0.1)
 def testSingleArgument(self):
     '''Test singleArgument call.'''
     d = Derived()
     self.assert_(d.singleArgument(False))
     self.assert_(not d.singleArgument(True))
 def testVirtualMethodCallString(self):
     '''Test virtual method call returning string.'''
     d = Derived()
     self.assertEqual(d.className(), 'Derived')
     self.assertEqual(d.getClassName(), 'Derived')
Beispiel #22
0
 def testVirtualMethodCallString(self):
     '''Test virtual method call returning string.'''
     d = Derived()
     self.assertEqual(d.className(), 'Derived')
     self.assertEqual(d.getClassName(), 'Derived')
Beispiel #23
0
 def testMethodCallWithDefaultValue(self):
     '''Test method call with default value.'''
     d = Derived()
     self.assertEqual(d.defaultValue(3), 3.1)
     self.assertEqual(d.defaultValue(), 0.1)
 def __init__(self):
     Derived.__init__(self)
     self.pure_virtual_called = False
     self.unpure_virtual_called = False
 def testAnotherImpossibleTypeDiscovery(self):
     a = Derived.triggerAnotherImpossibleTypeDiscovery()
     self.assertEqual(type(a), Derived)
 def testPureVirtualsOfImpossibleTypeDiscovery(self):
     a = Derived.triggerImpossibleTypeDiscovery()
     self.assertEqual(type(a), Abstract)
     # call some pure virtual method
     a.pureVirtual()
Beispiel #27
0
 def testOverloadedMethodCallWithDifferentNumericTypes(self):
     '''Test if the correct overloaded method accepts a different numeric type as argument.'''
     derived = Derived()
     result = derived.overloaded(1.1, 2.2)
     self.assertEqual(type(result), OverloadedFuncEnum)
     self.assertEqual(result, sample.OverloadedFunc_ii)
Beispiel #28
0
 def testAnotherImpossibleTypeDiscovery(self):
     a = Derived.triggerAnotherImpossibleTypeDiscovery()
     self.assertEqual(type(a), Derived)
Beispiel #29
0
 def __init__(self):
     Derived.__init__(self)
     self.pure_virtual_called = False
     self.unpure_virtual_called = False
Beispiel #30
0
 def testObjectCreationWithParentType(self):
     '''Derived class creates an instance of itself in C++ and returns it as a pointer to its ancestor Abstract.'''
     obj = Derived.createObject()
     self.assertEqual(type(obj), Derived)
 def testCallToMethodWithAbstractArgument(self):
     '''Call to method that expects an Abstract argument.'''
     objId = 123
     d = Derived(objId)
     self.assertEqual(Abstract.getObjectId(d), objId)
 def testObjectCreationWithParentType(self):
     '''Derived class creates an instance of itself in C++ and returns it as a pointer to its ancestor Abstract.'''
     obj = Derived.createObject()
     self.assertEqual(type(obj), Derived)
 def testOverloadedMethodCallWithWrongNumberOfArguments(self):
     '''Test if a call to an overloaded method with the wrong number of arguments raises an exception.'''
     derived = Derived()
     self.assertRaises(TypeError, derived.otherOverloaded, 1, 2, True)
Beispiel #34
0
 def testPureVirtualsOfImpossibleTypeDiscovery(self):
     a = Derived.triggerImpossibleTypeDiscovery()
     self.assertEqual(type(a), Abstract)
     # call some pure virtual method
     a.pureVirtual()
Beispiel #35
0
 def testSingleArgument(self):
     '''Test singleArgument call.'''
     d = Derived()
     self.assert_(d.singleArgument(False))
     self.assert_(not d.singleArgument(True))
 def testOverloadedMethodCallWithDifferentNumericTypes(self):
     '''Test if the correct overloaded method accepts a different numeric type as argument.'''
     derived = Derived()
     result = derived.overloaded(1.1, 2.2)
     self.assertEqual(type(result), OverloadedFuncEnum)
     self.assertEqual(result, sample.OverloadedFunc_ii)
Beispiel #37
0
 def __init__(self):
     Derived.__init__(self, 42)
     Number.__init__(self, 42)
Beispiel #38
0
 def testInstaciate(self):
     d = Derived.SomeInnerClass()
 def __init__(self):
     Derived.__init__(self, 42)
     Number.__init__(self, 42)