1from PyObjCTools.TestSupport import * 2import objc 3import sys 4 5# Most useful systems will at least have 'NSObject'. 6#NSObject = objc.lookUpClass('NSObject') 7 8# Use a class that isn't used in the rest of the testsuite, 9# should write a native class for this! NSPortCoder 10BaseName = 'NSPortCoder' 11BaseClass = objc.lookUpClass(BaseName) 12 13if sys.maxint >= 2 ** 32: 14 # -poseAsClass: is not supported in 64-bit mode (the functionality is 15 # not present in the 64-bit runtime and will never be because it 16 # conflicts with new functionality such as non-fragile class layouts) 17 pass 18 19else: 20 class TestPosing(TestCase): 21 def testPosing(self): 22 23 class PoseClass(BaseClass): 24 __slots__ = () # Don't add instance variables, not even __dict__ 25 def testPosingMethod(self): 26 return u"<PoseClass instance>" 27 28 29 PoseClass.poseAsClass_(BaseClass) 30 31 # BaseClass still refers to the old class, if we look it up again 32 # we get to see the new value. There's not much we can do about that. 33 obj = objc.lookUpClass(BaseName).new() 34 self.assertEquals(obj.testPosingMethod(), u"<PoseClass instance>") 35 36 # XXX: next assertion fails because the runtime seems to copy the 37 # original class. 38 #self.assert_(isinstance(obj, PoseClass)) 39 self.assertNotEquals(BaseClass.__name__, BaseName) 40 self.assertEquals(PoseClass.__name__, BaseName) 41 del obj 42 43 44 45if __name__ == '__main__': 46 main() 47