def test_subclass_with_virtual_transfer_ptr(self):
        class Test(foo.SomeObject):
            def __init__(self, prefix, extra_prefix):
                super(Test, self).__init__(prefix)
                self.extra_prefix = extra_prefix

            def get_prefix(self):
                prefix = super(Test, self).get_prefix()
                return prefix + self.extra_prefix

        while gc.collect():
            pass
        count_before = foo.SomeObject.instance_count
        foo.store_some_object(Test("xxx", "yyy"))
        while gc.collect():
            pass

        ## check that SomeObject isn't prematurely deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before + 1)

        ## invoke the virtual method and check that it returns the correct value
        prefix = foo.invoke_some_object_get_prefix()
        self.assertEqual(prefix, "xxxyyy")

        ## now delete the object from the C side..
        foo.delete_some_object()
        while gc.collect():
            pass

        ## check that SomeObject was finally deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before)
示例#2
0
    def test_subclass_with_virtual_transfer_ptr(self):
        class Test(foo.SomeObject):
            def __init__(self, prefix, extra_prefix):
                super(Test, self).__init__(prefix)
                self.extra_prefix = extra_prefix
            def get_prefix(self):
                prefix = super(Test, self).get_prefix()
                return prefix + self.extra_prefix
        while gc.collect():
            pass
        count_before = foo.SomeObject.instance_count
        foo.store_some_object(Test("xxx", "yyy"))
        while gc.collect():
            pass

        ## check that SomeObject isn't prematurely deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before + 1)

        ## invoke the virtual method and check that it returns the correct value
        prefix = foo.invoke_some_object_get_prefix()
        self.assertEqual(prefix, "xxxyyy")

        ## now delete the object from the C side..
        foo.delete_some_object()
        while gc.collect():
            pass

        ## check that SomeObject was finally deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before)
示例#3
0
    def test_subclassable_transfer_ptr(self):
        while gc.collect():
            pass
        count_before = foo.SomeObject.instance_count
        obj = foo.SomeObject("xxx")
        foo.store_some_object(obj)
        del obj
        while gc.collect():
            pass
        ## check that SomeObject isn't prematurely deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before + 1)

        ## now delete the object from the C side..
        foo.delete_some_object()
        while gc.collect():
            pass
        ## check that SomeObject was finally deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before)
    def test_subclassable_transfer_ptr(self):
        while gc.collect():
            pass
        count_before = foo.SomeObject.instance_count
        obj = foo.SomeObject("xxx")
        foo.store_some_object(obj)
        del obj
        while gc.collect():
            pass
        ## check that SomeObject isn't prematurely deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before + 1)

        ## now delete the object from the C side..
        foo.delete_some_object()
        while gc.collect():
            pass
        ## check that SomeObject was finally deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before)
示例#5
0
    def test_subclassable_store_and_take_back(self):
        while gc.collect():
            pass
        count_before = foo.SomeObject.instance_count
        obj = foo.SomeObject("xxx")
        foo.store_some_object(obj)
        del obj
        while gc.collect():
            pass
        ## check that SomeObject isn't prematurely deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before + 1)

        ## now get the object back from the C side..
        obj = foo.take_some_object()
        self.assertEqual(obj.get_prefix(), "xxx")

        del obj
        while gc.collect():
            pass
        ## check that SomeObject was finally deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before)
    def test_subclassable_store_and_take_back(self):
        while gc.collect():
            pass
        count_before = foo.SomeObject.instance_count
        obj = foo.SomeObject("xxx")
        foo.store_some_object(obj)
        del obj
        while gc.collect():
            pass
        ## check that SomeObject isn't prematurely deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before + 1)

        ## now get the object back from the C side..
        obj = foo.take_some_object()
        self.assertEqual(obj.get_prefix(), "xxx")

        del obj
        while gc.collect():
            pass
        ## check that SomeObject was finally deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before)
示例#7
0
    def test_subclassed_store_and_take_back(self):
        class Test(foo.SomeObject):
            pass

        while gc.collect():
            pass
        count_before = foo.SomeObject.instance_count
        obj1 = Test("xxx")
        obj1.attribute = 123
        foo.store_some_object(obj1)

        ## now get the object back from the C side..
        obj2 = foo.take_some_object()

        self.assertTrue(obj2 is obj1)
        self.assertEqual(obj2.attribute, 123)
        self.assertEqual(obj2.get_prefix(), "xxx")

        del obj1, obj2
        while gc.collect():
            pass
        ## check that SomeObject was finally deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before)
    def test_subclassed_store_and_take_back(self):
        class Test(foo.SomeObject):
            pass

        while gc.collect():
            pass
        count_before = foo.SomeObject.instance_count
        obj1 = Test("xxx")
        obj1.attribute = 123
        foo.store_some_object(obj1)

        ## now get the object back from the C side..
        obj2 = foo.take_some_object()

        self.assertTrue(obj2 is obj1)
        self.assertEqual(obj2.attribute, 123)
        self.assertEqual(obj2.get_prefix(), "xxx")

        del obj1, obj2
        while gc.collect():
            pass
        ## check that SomeObject was finally deleted
        self.assertEqual(foo.SomeObject.instance_count, count_before)