Exemplo n.º 1
0
    def testGenericFunctions(self):
        value = CoreFoundation.CFGetTypeID(CoreFoundation.kCFAllocatorMalloc)
        self.assertEqual(value, CoreFoundation.CFAllocatorGetTypeID())

        v = CoreFoundation.CFCopyTypeIDDescription(
            CoreFoundation.CFAllocatorGetTypeID())
        self.assertIsInstance(v, str)
        obj = CoreFoundation.CFURLCreateWithString(None,
                                                   "http://www.apple.com/",
                                                   None)
        i = CoreFoundation.CFGetTypeID(obj)
        self.assertIsInstance(i, int)
        i = CoreFoundation.CFGetRetainCount(obj)
        self.assertIsInstance(i, int)
        CoreFoundation.CFRetain(obj)
        self.assertEqual(CoreFoundation.CFGetRetainCount(obj), i + 1)
        CoreFoundation.CFRelease(obj)
        self.assertEqual(CoreFoundation.CFGetRetainCount(obj), i)

        CoreFoundation.CFRetain(obj)
        CoreFoundation.CFMakeCollectable(obj)

        del obj

        i = CoreFoundation.CFEqual(CoreFoundation.kCFAllocatorMalloc,
                                   CoreFoundation.kCFAllocatorNull)
        self.assertIs(i, False)
        i = CoreFoundation.CFEqual(CoreFoundation.kCFAllocatorMalloc,
                                   CoreFoundation.kCFAllocatorMalloc)
        self.assertIs(i, True)
        i = CoreFoundation.CFHash(CoreFoundation.kCFAllocatorMalloc)
        self.assertTrue(i, int)

        v = CoreFoundation.CFCopyDescription(CoreFoundation.kCFAllocatorMalloc)
        self.assertIsInstance(v, str)
        v = CoreFoundation.CFGetAllocator(CoreFoundation.kCFAllocatorMalloc)
        if v is not None:
            self.assertIsInstance(v, CoreFoundation.CFAllocatorRef)
Exemplo n.º 2
0
    def testCFAllocator(self):
        self.assertIsCFType(CoreFoundation.CFAllocatorRef)

        self.assertIsInstance(CoreFoundation.CFAllocatorGetTypeID(), int)
        self.assertIsInstance(
            CoreFoundation.kCFAllocatorDefault,
            (CoreFoundation.CFAllocatorRef, type(None)),
        )
        self.assertIsInstance(CoreFoundation.kCFAllocatorSystemDefault,
                              CoreFoundation.CFAllocatorRef)
        self.assertIsInstance(CoreFoundation.kCFAllocatorMalloc,
                              CoreFoundation.CFAllocatorRef)
        self.assertIsInstance(CoreFoundation.kCFAllocatorMallocZone,
                              CoreFoundation.CFAllocatorRef)
        self.assertIsInstance(CoreFoundation.kCFAllocatorNull,
                              CoreFoundation.CFAllocatorRef)
        self.assertIsInstance(CoreFoundation.kCFAllocatorUseContext,
                              CoreFoundation.CFAllocatorRef)
        r = CoreFoundation.CFAllocatorGetDefault()
        self.assertIsInstance(r, CoreFoundation.CFAllocatorRef)
        CoreFoundation.CFAllocatorSetDefault(CoreFoundation.kCFAllocatorMalloc)
        r2 = CoreFoundation.CFAllocatorGetDefault()
        self.assertIsInstance(r2, CoreFoundation.CFAllocatorRef)
        self.assertIs(r2, CoreFoundation.kCFAllocatorMalloc)
        # Restore default allocator
        CoreFoundation.CFAllocatorSetDefault(r)

        self.assertNotHasAttr(CoreFoundation, "CFAllocatorCreate")
        self.assertNotHasAttr(CoreFoundation, "CFAllocatorAllocate")
        self.assertNotHasAttr(CoreFoundation, "CFAllocatorReallocate")
        self.assertNotHasAttr(CoreFoundation, "CFAllocatorDeallocate")
        self.assertNotHasAttr(CoreFoundation, "CFAllocatorGetContext")
        r = CoreFoundation.CFAllocatorGetPreferredSizeForSize(
            CoreFoundation.kCFAllocatorDefault, 15, 0)
        self.assertIsInstance(r, int)
        self.assertGreaterEqual(r, 15)