Commits

Tuukka Norri committed 6796edd

Removed badly written tests and made others work (fixes #221)

Comments (0)

Files changed (5)

UnitTests/Sources/BXDatabaseObjectTests.m

 {    
     MKCAssertEqualObjects (@"value", [mObject cachedValueForKey: @"key"]);
 }
-
-#if 0
-- (void) testRegistrationPrimitiveAndFault
-{
-    //Registration
-    [mObject registerWithContext: mContext entity: mEntity];
-
-    //Primitive
-    MKCAssertEqualObjects ([NSNumber numberWithInt: 1], 
-                           [mObject primitiveValueForKey: @"id"]);
-    
-    //Fault
-    MKCAssertTrue (0 == [mObject isFaultKey: @"id"]);
-    MKCAssertTrue (0 == [mObject isFaultKey: @"key"]);
-}
-#endif
-
-#if 0
-- (void) testFaultingAndObserving
-{    
-    //We need an objectID for -[BXDatabaseObject isEqual:].
-    [mObject registerWithContext: mContext entity: mEntity];
-
-    id observer = [OCMockObject mockForClass: [NSObject class]];
-    [[observer expect] observeValueForKeyPath: @"key" ofObject: mObject change: OCMOCK_ANY context: OCMOCK_ANY];
-
-    MKCAssertTrue (0 == [mObject isFaultKey: @"key"]);
-    [mObject addObserver: observer forKeyPath: @"key" options: 0 context: NULL];
-    [mObject faultKey: @"key"];
-    //We'd require an object id for testing 0 == isFaultKey.
-    MKCAssertTrue (-1 == [mObject isFaultKey: @"key"]);
-    
-    [observer verify];
-}
-#endif
-
-#if 0
-- (void) testNullValidation
-{
-    //We need an entity for this.
-    [mObject registerWithContext: mContext entity: mEntity];
-    
-    id value = nil;
-    NSError* error = nil;
-    MKCAssertFalse ([mObject validateValue: &value forKey: @"id" error: &error]);
-    MKCAssertNotNil (error);
-    
-    error = nil;
-    MKCAssertTrue ([mObject validateValue: &value forKey: @"key" error: &error]);
-    STAssertNil (error, [error description]);
-}
-#endif
-
-#if 0
-- (void) testStatusInfo
-{
-    //We need an objectID for -[BXDatabaseObject isEqual:].
-    [mObject registerWithContext: mContext entity: mEntity];
-
-    enum BXObjectLockStatus status = kBXObjectNoLockStatus;
-    id statusInfo = [mObject statusInfo];
-    id observer = [OCMockObject mockForClass: [NSObject class]];
-    
-    [statusInfo addObserver: observer forKeyPath: @"id" options: 0 context: NULL];
-    
-    [[statusInfo valueForKey: @"id"] getValue: &status];
-    MKCAssertTrue (status == kBXObjectNoLockStatus);
-
-    //Key path will be statusInfo instead of the actual key.
-    [[observer expect] observeValueForKeyPath: OCMOCK_ANY ofObject: mObject change: OCMOCK_ANY context: NULL];
-    [mObject setLockedForKey: @"id"];
-    [observer verify];
-    [[statusInfo valueForKey: @"id"] getValue: &status];
-    MKCAssertTrue (status == kBXObjectLockedStatus);
-    
-    [[observer expect] observeValueForKeyPath: OCMOCK_ANY ofObject: mObject change: OCMOCK_ANY context: NULL];
-    [mObject setDeleted: kBXObjectDeletePending];
-    [observer verify];
-    [[statusInfo valueForKey: @"id"] getValue: &status];
-    MKCAssertTrue (status == kBXObjectDeletedStatus);
-    
-    [[observer expect] observeValueForKeyPath: OCMOCK_ANY ofObject: mObject change: OCMOCK_ANY context: NULL];
-    [mObject setDeleted: kBXObjectExists];
-    [observer verify];
-    [[observer expect] observeValueForKeyPath: OCMOCK_ANY ofObject: mObject change: OCMOCK_ANY context: NULL];
-    [mObject lockForDelete];
-    [observer verify];
-    [[statusInfo valueForKey: @"id"] getValue: &status];
-    MKCAssertTrue (status == kBXObjectDeletedStatus);
-}
-#endif
 @end

UnitTests/Sources/BXPredicateTests.m

 #import <BaseTen/BXPGInterface.h>
 #import <BaseTen/BXPGQueryBuilder.h>
 #import <BaseTen/BXPredicateVisitor.h>
+#import <BaseTen/BXAttributeDescriptionPrivate.h>
+#import <OCMock/OCMock.h>
 
 
 @implementation BXPredicateTests
 	
 	BXDatabaseContext* ctx = [[BXDatabaseContext alloc] initWithDatabaseURI: [self databaseURI]];
 	[ctx setDelegate: self];
+	
 	BXEntityDescription* entity = [ctx entityForTable: @"test" inSchema: @"public" error: NULL];
-	[mQueryBuilder addPrimaryRelationForEntity: entity];
+	OCMockObject *entityMock = [OCMockObject partialMockForObject: entity];
+	BXAttributeDescription *attr = [BXAttributeDescription attributeWithName: @"id" entity: (id) entityMock];
+	[[[entityMock stub] andReturn: [NSDictionary dictionaryWithObject: attr forKey: @"id"]] attributesByName];
+	  
+	[mQueryBuilder addPrimaryRelationForEntity: (id) entityMock];
 	
 	BXPGInterface* interface = (id)[ctx databaseInterface];
 	[interface prepareForConnecting];
 	MKCAssertEqualObjects (parameters, expected);
 }
 
-//We need a validated entity for this test.
-#if 0
 - (void) testAdditionWithKeyPath
 {
 	NSPredicate* predicate = [NSPredicate predicateWithFormat: @"1 + id == 2"];
-	NSString* whereClause = [mQueryBuilder whereClauseForPredicate: predicate entity: nil connection: mConnection].p_where_clause;
-	MKCAssertEqualObjects (whereClause, @"$1 = ($2 + $3)");
+	NSString* whereClause = [mQueryBuilder whereClauseForPredicate: predicate 
+															entity: [[mQueryBuilder primaryRelation] entity] 
+														connection: mConnection].p_where_clause;
+	MKCAssertEqualObjects (whereClause, @"$1 = ($2 + te1.\"id\")");
 	NSArray* parameters = [mQueryBuilder parameters];
-	NSArray* expected = [NSArray arrayWithObjects: [NSNumber numberWithInt: 3], [NSNumber numberWithInt: 1], [NSNumber numberWithInt: 2], nil];
+	NSArray* expected = [NSArray arrayWithObjects: [NSNumber numberWithInteger: 2], [NSNumber numberWithInteger: 1], nil];
 	MKCAssertEqualObjects (parameters, expected);	
 }
-#endif
 
 - (void) testDiacriticInsensitivity
 {

UnitTests/Sources/FetchTests.m

 	MKCAssertEqualObjects ([[res objectAtIndex: 0] valueForKey: @"name"], @"nzhuk");
 }
 
-#if 0
-- (void) testJoin2
-{
-	NSError* error = nil;	
-	[mContext connectIfNeeded: &error];
-	STAssertNil (error, [error description]);
-	
-	BXEntityDescription* order = [mContext entityForTable: @"order" error: &error];
-	STAssertNil (error, [error description]);
-	BXEntityDescription* supplier = [mContext entityForTable: @"supplier" error: &error];
-	STAssertNil (error, [error description]);
-	
-	BXPropertyDescription* supplierName = [[supplier attributesByName] objectForKey: @"supplier_name"];
-	BXPropertyDescription* poNumber = [[order attributesByName] objectForKey: @"po_number"];
-	BXPropertyDescription* supplierId = [[supplier attributesByName] objectForKey: @"supplier_id"];
-	BXPropertyDescription* orderSupplierId = [[order attributesByName] objectForKey: @"supplier_id"];
-	MKCAssertNotNil (supplierName);
-	MKCAssertNotNil (poNumber);
-	MKCAssertNotNil (supplierId);
-	MKCAssertNotNil (orderSupplierId);
-	
-    NSPredicate* predicate = [NSPredicate predicateWithFormat: 
-        @"%@ == %@ AND ((NOT %@ MATCHES[c] \"test\") OR %@ MATCHES[c] \"ferg\")", 
-		supplierId, orderSupplierId, poNumber, supplierName];
-    
-	NSArray* res = [mContext executeFetchForEntity: order withPredicate: predicate error: &error];
-	res = nil;
-}
-#endif
-
 - (void) testFault
 {
 	NSError* error = nil;

UnitTests/Sources/ForeignKeyModificationTests.m

 
 - (void) testModOTM
 {
+	//This doesn't work for views (mTest1v, mTest2v) because we don't provide values for the primary key.
     [self modOne: mTest1 toMany: mTest2];
 }
 
-//FIXME: this doesn't work for views because we don't provide values for the primary key.
-#if 0
-- (void) testModOTMView
-{
-    [self modOne: test1v toMany: test2v];
-}
-#endif
-
 - (void) testModOTM2
 {
     //FIXME: also write a view test?

UnitTests/Sources/TestLoader.m

 							[ToOneChangeNotificationTests class],
 							nil];
 	
-	//testClasses = [NSArray arrayWithObject: [PGTSHOMTests class]];
+	testClasses = [NSArray arrayWithObject: [BXPredicateTests class]];
 	
 	for (Class testCaseClass in testClasses)
 	{