Commits

Ronald Oussoren committed 15a6500

Slight reworking of these tests, avoids warnings from Cocoa.

  • Participants
  • Parent commits e580a70
  • Branches pyobjc-ancient

Comments (0)

Files changed (2)

File Lib/objc/test/test_identity.py

         container = OC_TestIdentity.alloc().init()
 
         cls = objc.lookUpClass("Object")
-        container.setStoredObjectAnInstanceOf_(cls)
+        container.setStoredObjectAnInstanceOfClassic_(cls)
         v = container.storedObject()
         self.assert_(container.isSameObjectAsStored_(v), repr(v))
         self.assert_(isinstance(v, cls))
         container = OC_TestIdentity.alloc().init()
 
         cls = objc.lookUpClass("Object")
-        container.setStoredObjectAnInstanceOf_(cls)
+        container.setStoredObjectAnInstanceOfClassic_(cls)
         self.assertFetchingTwice(container, "object")
 
     def dont_testNSNumber(self):

File Modules/objc/test/identity.m

 @interface OC_TestIdentity : NSObject
 {
 	NSObject* storedObject;
+	int       isClassic;
 }
 
 -(NSObject*)storedObject;
+-(void)setStoredClassicObject:(NSObject*)object;
 -(void)setStoredObject:(NSObject*)object;
 -(void)dealloc;
 
 -(int)isSameObjectAsStored:(NSObject*)value;
 -(void)setStoredObjectToAProtocol;
 -(void)setStoredObjectAnInstanceOf:(Class) cls;
+-(void)setStoredObjectAnInstanceOfClassic:(Class) cls;
 
 -(void)writeStoredObjecToFile:(NSString*)fname;
 
 @implementation OC_TestIdentity
 -(void)dealloc
 {
-	[storedObject release];
+	if (isClassic) {
+		/* pass, we could call free but why bother? */
+	} else {
+		[storedObject release];
+	}
 }
 
 -(NSObject*)storedObject
 {
-	return [[storedObject retain] autorelease];
+	if (isClassic) {
+		return storedObject;
+	} else {
+		return [[storedObject retain] autorelease];
+	}
 }
 
 -(void)setStoredObject:(NSObject*)object
 {
+	if (!isClassic) {
+		[storedObject release];
+	}
 	[object retain];
-	[storedObject release];
 	storedObject = object;
+	isClassic = 0;
+}
+
+-(void)setStoredClassicObject:(NSObject*)object;
+{
+	if (!isClassic) {
+		[storedObject release];
+	}
+	storedObject = object;
+	isClassic = 1;
 }
 
 -(void)setStoredObjectToResultOf:(SEL)aSelector on:(NSObject*)object
 
 -(void)setStoredObjectToAProtocol
 {
-	[self setStoredObject: (NSObject*)@protocol(NSObject) ];
+	[self setStoredClassicObject: (NSObject*)@protocol(NSObject) ];
 }
 
 -(void)setStoredObjectAnInstanceOf:(Class) cls
 {
 	[self setStoredObject: [[cls alloc] init]];
 }
+-(void)setStoredObjectAnInstanceOfClassic:(Class)cls
+{
+	[self setStoredClassicObject:[cls new]];
+}
 
 -(void)writeStoredObjecToFile:(NSString*)fname
 {