Commits

Ronald Oussoren  committed 9bfc7cd

- Add a testcase for 'copy' (and indirectly for 'copyWithZone:'). This testcase
causes a crash at the moment because all methods implemetned in Python
return borrowed references, whereas copy should return a new reference.

  • Participants
  • Parent commits 4cdf6b3

Comments (0)

Files changed (2)

File pyobjc/Lib/objc/test/test_subclass.py

 import unittest
 import objc
+from testbndl import PyObjC_TestClass3
 
 # Most usefull systems will at least have 'NSObject'.
 NSObject = objc.lookUpClass('NSObject')
 
         self.assert_(repr(SelectorRepr.foo).startswith('<unbound selector foo of SelectorRepr at'))
 
+
+class TestCopying (unittest.TestCase):
+
+    def testCopy(self):
+        class MyCopyClass (NSObject):
+            def copyWithZone_(self, zone):
+                o = super(MyCopyClass, self).copyWithZone_(zone)
+                o.foobar = 2
+                return o
+
+        o = MyCopyClass.alloc().init()
+        o.foobar = 1
+
+        self.assertEquals(o.foobar, 1)
+
+        c = PyObjC_TestClass3.makeACopy_(o)
+        
+        self.assert_(isinstance(c, MyCopyClass))
+        self.assertEquals(c.foobar, 2)
+
 if __name__ == '__main__':
     unittest.main()

File pyobjc/Lib/objc/test/testbndl.m

 /*
+ * XXX: TestClass3 is contains some test-code that is not replicated in 
+ *      testbndl2.m, the rest should be removed after checking that 
+ *      testbndl2.m really does contain all tests in this file!.
+ *
  * This file implements a (number of) class(es) that are used to test
  * method calling with PyObjC (both python -> ObjC and back)
  *
 @end
 
 
+/*============================================================================*/
+
+@interface PyObjC_TestClass3 : NSObject
+{
+}
++makeACopy:source;
+@end
+
+@implementation PyObjC_TestClass3
+
++makeACopy:source
+{
+	id theCopy;
+	id pool;
+
+	/* Copy the source, bracketed by the creation and
+	 * destruction of an autorelease pool. This should
+	 * cause a core-dump if the copy is not a 'new'
+	 * object.
+	 */
+	pool = [[NSAutoreleasePool alloc] init];
+	theCopy = [source copy];
+	[pool release];
+	pool = nil;
+	
+	return theCopy;
+}
+
+@end
+
+
 
 static PyMethodDef no_methods[] = {
 	{ 0, 0, 0, 0 }
 		PyObjCClass_New([OC_TestClass1 class]));
 	PyModule_AddObject(m, "OC_TestClass2", 
 		PyObjCClass_New([OC_TestClass2 class]));
+	PyModule_AddObject(m, "PyObjC_TestClass3", 
+		PyObjCClass_New([PyObjC_TestClass3 class]));
+	
 	
 }