1from PyObjCTools.TestSupport import * 2 3from objc import * 4from Foundation import * 5 6try: 7 import sys 8 if sys.version_info[:2] in [(2,4), (2,5)]: 9 raise ImportError, "py2.4 hangs when a CFArray is created, bug was filed" 10 11 # These tests are only useful on MacOS X when using MacPython 12 from Carbon.CF import * 13 14 15 class TestTollFreeBridging( TestCase ): 16 def testExplicitToCF(self): 17 o = NSArray.arrayWithArray_((u"a", 1, 1.9)) 18 self.assert_(isinstance(o, NSArray)) 19 20 c = ObjectToCF(o) 21 22 # On MacOS X 'o' will actually be an instance of NSCFArray, 23 # which is a subclass of NSMutableArray! Depending on how you 24 # test for the type of 'o' you'll get a different CF type... 25 self.assert_(isinstance(c, (CFArrayRef, CFMutableArrayRef))) 26 27 def testExplictFromCF(self): 28 c = CFArrayCreateMutable(0) 29 self.assert_(isinstance(c, CFMutableArrayRef)) 30 31 o = CFToObject(c) 32 self.assert_(isinstance(o, NSMutableArray)) 33 34 def testImplicitFromCF(self): 35 c = CFArrayCreateMutable(0) 36 self.assert_(isinstance(c, CFMutableArrayRef)) 37 38 nsa = NSMutableArray.array() 39 nsa.addObject_(c) 40 41 o = nsa[0] 42 self.assert_(isinstance(o, NSMutableArray)) 43 44except ImportError: 45 pass 46 47if __name__ == '__main__': 48 main( ) 49