Commits

Tuukka Norri committed d7b1e14

Small changes
- Changed tests so that each test has its own database object model storage. This way the tests shouldn't influence each other.
- Each test is now run with its own NSAutoreleasePool.
- Fixed memory leaks.

Comments (0)

Files changed (6)

UnitTests/Sources/BXModificationTests.m

     NSUInteger count = [array count];
     
     //Create an object into the array using another connection.
-    BXDatabaseContext* context2 = [[BXDatabaseContext alloc] initWithDatabaseURI: [self databaseURI]];
+	BXDatabaseContext *context2 = [[[BXDatabaseContext alloc] init] autorelease];
+	[context2 setDatabaseObjectModelStorage: mStorage];
+	[context2 setDatabaseURI: [self databaseURI]];
 	[context2 setDelegate: self];
     [context2 setAutocommits: NO];
     MKCAssertNotNil (context2);
     MKCAssertEquals (count, [array count]);
 	
 	[context2 disconnect];
-	[context2 release];
 }
 
 
 	MKCAssertNotNil (entity);
 
 	{
-		context2 = [[BXDatabaseContext alloc] initWithDatabaseURI: [self databaseURI]];
+		context2 = [[[BXDatabaseContext alloc] init] autorelease];
+		[context2 setDatabaseObjectModelStorage: mStorage];
+		[context2 setDatabaseURI: [self databaseURI]];
 		[context2 setDelegate: self];
 		[context2 setAutocommits: YES];
 		MKCAssertNotNil (context2);

UnitTests/Sources/BXTestCase.h

 
 @interface BXTestCase : SenTestCase <BXDatabaseContextDelegate>
 {
+	NSAutoreleasePool *mPool;
 }
 - (NSURL *) databaseURI;
 - (NSDictionary *) connectionDictionary;
 @end
 
 
+
 @interface BXDatabaseTestCase: BXTestCase
 {
-	BXDatabaseContext* mContext;
+	BXDatabaseContext *mContext;
+	BXDatabaseObjectModelStorage *mStorage;
 }
 @end

UnitTests/Sources/BXTestCase.m

 }
 
 
+
 @interface SenTestCase (UndocumentedMethods)
 - (void) logException:(NSException *) anException;
 @end
 
 
+
 @implementation BXTestCase
 static void
 bx_test_failed (NSException* exception)
 	abort ();
 }
 
+
 - (void) logAndCallBXTestFailed: (NSException *) exception
 {
 	[self logException: exception];
 	bx_test_failed (exception);
 }
 
+
 - (id) initWithInvocation: (NSInvocation *) anInvocation
 {
 	if ((self = [super initWithInvocation: anInvocation]))
 	return self;
 }
 
+
 - (NSURL *) databaseURI
 {
 	return [NSURL URLWithString: @"pgsql://baseten_test_user@localhost/basetentest"];
 }
 
+
 - (NSDictionary *) connectionDictionary
 {
 	NSDictionary* connectionDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
 {
 	return kBXSSLModeDisable;
 }
+
+
+- (void) setUp
+{
+	[super setUp];
+	mPool = [[NSAutoreleasePool alloc] init];
+}
+
+
+- (void) tearDown
+{
+	[mPool drain];
+	[super tearDown];
+}
 @end
 
 
+
 @implementation BXDatabaseTestCase
 - (void) setUp
 {
 	[super setUp];
+	mStorage = [[BXDatabaseObjectModelStorage alloc] init];
 	
 	NSURL* databaseURI = [self databaseURI];
-
 	mContext = [[BXDatabaseContext alloc] init];
+	[mContext setDatabaseObjectModelStorage: mStorage];
 	[mContext setDatabaseURI: databaseURI];
 	[mContext setAutocommits: NO];
 	[mContext setDelegate: self];
 	MKCAssertFalse ([mContext autocommits]);
 }
 
+
 - (void) tearDown
 {
 	[mContext disconnect];
 	[mContext release];
+	[mStorage release];
 	[super tearDown];
 }
 @end

UnitTests/Sources/EntityTests.m

 	BXEntityDescription* entity = [[mContext databaseObjectModel] entityForTable: entityName inSchema: schemaName];
 	MKCAssertNotNil (entity);
 	
-	BXDatabaseContext* ctx2 = [BXDatabaseContext contextWithDatabaseURI: [mContext databaseURI]];
+	BXDatabaseContext* ctx2 = [[[BXDatabaseContext alloc] init] autorelease];
+	[ctx2 setDatabaseObjectModelStorage: mStorage];
+	[ctx2 setDatabaseURI: [mContext databaseURI]];
 	[ctx2 setDelegate: self];
 	BXEntityDescription* entity2 = [[ctx2 databaseObjectModel] entityForTable: entityName inSchema: schemaName];
 	MKCAssertNotNil (entity2);

UnitTests/Sources/ObjectIDTests.m

 	MKCAssertNotNil (uri);
 	
 	//Change the URI back to a object id
-	BXDatabaseContext* ctx2 = [BXDatabaseContext contextWithDatabaseURI: [mContext databaseURI]];
+	BXDatabaseContext* ctx2 = [[[BXDatabaseContext alloc] init] autorelease];
+	[ctx2 setDatabaseObjectModelStorage: mStorage];
+	[ctx2 setDatabaseURI: [mContext databaseURI]];
 	[ctx2 setDelegate: self];
 	BXDatabaseObjectID* objectID2 = [[[BXDatabaseObjectID alloc] initWithURI: uri context: ctx2] autorelease];
 	MKCAssertNotNil (objectID2);
 
 - (void) testObjectIDFromAnotherContext
 {
-	BXDatabaseContext* ctx2 = [[[BXDatabaseContext alloc] initWithDatabaseURI: [mContext databaseURI]] autorelease];
+	BXDatabaseContext *ctx2 = [[[BXDatabaseContext alloc] init] autorelease];
+	[ctx2 setDatabaseObjectModelStorage: mStorage];
+	[ctx2 setDatabaseURI: [mContext databaseURI]];
 	[ctx2 setDelegate: self];
 	MKCAssertNotNil (ctx2);
 	

UnitTests/Sources/PGTSInvocationRecorderTests.m

 	NSString *b = @"b";
 	OCMockObject *callbackTarget = [OCMockObject mockForProtocol: @protocol (PGTSInvocationRecorderTestCallback)];
 	
-	PGTSCallbackInvocationRecorder *recorder = [[PGTSCallbackInvocationRecorder alloc] init];
+	PGTSCallbackInvocationRecorder *recorder = [[[PGTSCallbackInvocationRecorder alloc] init] autorelease];
 	[recorder setCallback: @selector (myCallback:userInfo:)];
 	[recorder setCallbackTarget: callbackTarget];
 	[recorder setUserInfo: b];