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)
Example #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)
Example #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))
Example #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)
Example #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))
Example #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))
Example #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))
Example #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)
Example #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))
Example #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))
Example #19
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)
Example #20
0
 def testSingleArgument(self):
     '''Test singleArgument call.'''
     d = Derived()
     self.assert_(d.singleArgument(False))
     self.assert_(not d.singleArgument(True))
Example #21
0
 def testVirtualMethodCallString(self):
     '''Test virtual method call returning string.'''
     d = Derived()
     self.assertEqual(d.className(), 'Derived')
     self.assertEqual(d.getClassName(), 'Derived')
Example #22
0
 def testVirtualMethodCallString(self):
     '''Test virtual method call returning string.'''
     d = Derived()
     self.assertEqual(d.className(), 'Derived')
     self.assertEqual(d.getClassName(), 'Derived')
Example #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)
Example #24
0
 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()
Example #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)
Example #28
0
 def testAnotherImpossibleTypeDiscovery(self):
     a = Derived.triggerAnotherImpossibleTypeDiscovery()
     self.assertEqual(type(a), Derived)
Example #29
0
 def __init__(self):
     Derived.__init__(self)
     self.pure_virtual_called = False
     self.unpure_virtual_called = False
Example #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)
Example #31
0
 def testCallToMethodWithAbstractArgument(self):
     '''Call to method that expects an Abstract argument.'''
     objId = 123
     d = Derived(objId)
     self.assertEqual(Abstract.getObjectId(d), objId)
Example #32
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)
Example #33
0
 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)
Example #34
0
 def testPureVirtualsOfImpossibleTypeDiscovery(self):
     a = Derived.triggerImpossibleTypeDiscovery()
     self.assertEqual(type(a), Abstract)
     # call some pure virtual method
     a.pureVirtual()
Example #35
0
 def testSingleArgument(self):
     '''Test singleArgument call.'''
     d = Derived()
     self.assert_(d.singleArgument(False))
     self.assert_(not d.singleArgument(True))
Example #36
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)
Example #37
0
 def __init__(self):
     Derived.__init__(self, 42)
     Number.__init__(self, 42)
Example #38
0
 def testInstaciate(self):
     d = Derived.SomeInnerClass()
 def __init__(self):
     Derived.__init__(self, 42)
     Number.__init__(self, 42)