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