Exemplo n.º 1
0
 def testParentFromCpp(self):
     o = ObjectType()
     self.assertEqual(sys.getrefcount(o), 2)
     o.getCppParent().setObjectName('parent')
     self.assertEqual(sys.getrefcount(o), 3)
     o.getCppParent().setObjectName('parent')
     self.assertEqual(sys.getrefcount(o), 3)
     o.getCppParent().setObjectName('parent')
     self.assertEqual(sys.getrefcount(o), 3)
     o.getCppParent().setObjectName('parent')
     self.assertEqual(sys.getrefcount(o), 3)
     o.getCppParent().setObjectName('parent')
     self.assertEqual(sys.getrefcount(o), 3)
     o.destroyCppParent()
     self.assertEqual(sys.getrefcount(o), 2)
Exemplo n.º 2
0
    def testInvalidateChild(self):
        '''Invalidating method call should remove child from the care of a parent if it has one.'''
        parent = ObjectType()
        child1 = ObjectType(parent)
        child1.setObjectName('child1')
        child2 = ObjectType.create()
        child2.setParent(parent)
        child2.setObjectName('child2')

        self.assertEqual(parent.children(), [child1, child2])

        bbox = BlackBox()

        # This method steals ownership from Python to C++.
        bbox.keepObjectType(child1)
        self.assertEqual(parent.children(), [child2])

        bbox.keepObjectType(child2)
        self.assertEqual(parent.children(), [])

        del parent

        self.assertEqual(child1.objectName(), 'child1')
        self.assertRaises(RuntimeError, child2.objectName)
    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))
Exemplo n.º 4
0
    def testImplicitConversions(self):
        '''Test if overloaded function call decisor takes implicit conversions into account.'''
        ic = ImplicitConv.implicitConvCommon(ImplicitConv())
        self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorNone)

        ic = ImplicitConv.implicitConvCommon(3)
        self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorOne)
        self.assertEqual(ic.objId(), 3)

        ic = ImplicitConv.implicitConvCommon(ImplicitConv.CtorThree)
        self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorThree)

        obj = ObjectType()
        ic = ImplicitConv.implicitConvCommon(obj)
        self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorObjectTypeReference)

        ic = ImplicitConv.implicitConvCommon(42.42)
        self.assertEqual(ic.value(), 42.42)
Exemplo n.º 5
0
 def testProtectedObjectTypeProperty(self):
     '''Writes and reads a protected object type property.'''
     obj = ObjectType()
     self.obj.protectedObjectTypeProperty = obj
     self.assertEqual(self.obj.protectedObjectTypeProperty, obj)
Exemplo n.º 6
0
 def testLShiftWithExpectedType(self):
     '''Collector << ObjectType # libsample << operator'''
     collector = Collector()
     obj = ObjectType()
     collector << obj
     self.assertEqual(collector.items()[0], obj.identifier())
Exemplo n.º 7
0
    def testWithInt(self):
        '''Overload with Enums and ints with default value'''
        o = ObjectType()

        self.assertEqual(o.callWithEnum('', Event.ANY_EVENT, 9), 81)
        self.assertEqual(o.callWithEnum('', 9), 9)
 def testOneArgument(self):
     p = ObjectType()
     o = ObjectType(parent=p)
     self.assertEqual(o.parent(), p)
Exemplo n.º 9
0
    def testNextInFocusChainCycle(self):
        parent = ObjectType()
        child = ObjectType(parent)
        next_focus = child.nextInFocusChain()

        shiboken.invalidate(parent)
Exemplo n.º 10
0
 def testNullOverload(self):
     o = ObjectType()
     o.setObject(None)
     self.assertEqual(o.callId(), 0)
     o.setNullObject(None)
     self.assertEqual(o.callId(), 1)
Exemplo n.º 11
0
 def testObjectTypeSetObjectNameWithPythonString(self):
     '''ObjectType.setObjectName with Python string as argument.'''
     o = ObjectType()
     o.setObjectName('object name')
     self.assertEqual(str(o.objectName()), 'object name')
Exemplo n.º 12
0
 def testObjectTypeSetObjectNameWithStrInstantiation(self):
     '''ObjectType.setObjectName with Str instantiation as argument.'''
     s = 'object name'
     o = ObjectType()
     o.setObjectName(Str(s))
     self.assertEqual(str(o.objectName()), s)
Exemplo n.º 13
0
 def testObjectTypeSetObjectNameWithStrVariable(self):
     '''ObjectType.setObjectName with Str variable as argument.'''
     s = Str('object name')
     o = ObjectType()
     o.setObjectName(s)
     self.assertEqual(str(o.objectName()), str(s))
 def testBasic(self):
     '''ObjectType weakref'''
     obj = ObjectType()
     ref = weakref.ref(obj, self.cb)
     del obj
     self.assertTrue(self.called)
Exemplo n.º 15
0
 def testCallWithError(self):
     o = ObjectType()
     warnings.simplefilter("error")
     self.assertRaises(DeprecationWarning, o.deprecatedFunction)
Exemplo n.º 16
0
 def testBasic(self):
     '''Collector << ObjectType # greedy collector'''
     collector = Collector()
     obj = ObjectType()
     collector << obj
     self.assertEqual(collector.items()[0], obj.identifier())