From 8baab51469e6fe1ea62ce9203d8ef2fe643879d7 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Fri, 13 Nov 2009 23:35:07 +0000 Subject: Tidy up and fix unit tests. --- UnitTests/mcpKitTest.h | 6 ++-- UnitTests/mcpKitTest.m | 62 ++++++++++++++++----------------- UnitTests/stringCategoryAdditionsTest.h | 1 - UnitTests/stringCategoryAdditionsTest.m | 10 +++--- 4 files changed, 39 insertions(+), 40 deletions(-) (limited to 'UnitTests') diff --git a/UnitTests/mcpKitTest.h b/UnitTests/mcpKitTest.h index 8e5fd508..14f263bd 100644 --- a/UnitTests/mcpKitTest.h +++ b/UnitTests/mcpKitTest.h @@ -20,14 +20,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // More info at -// #import -#import + +@class MCPConnection; @interface mcpKitTest : SenTestCase { - MCPConnection *mySQLConnection; + MCPConnection *connection; } @end diff --git a/UnitTests/mcpKitTest.m b/UnitTests/mcpKitTest.m index 8af68c64..49c02eb8 100644 --- a/UnitTests/mcpKitTest.m +++ b/UnitTests/mcpKitTest.m @@ -20,7 +20,8 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // More info at -// + +#import #import "mcpKitTest.h" @@ -28,58 +29,55 @@ - (void)setUp { - // for now, we try an find the following database in the local connection - // if the connection fails for any reasons, tests are not run. + // For now, we try an find the following database in the local connection. + // If the connection fails for any reasons, tests are not run. // http://downloads.mysql.com/docs/sakila-db.zip - // set up a user called 'sakila' with no password that has all privs on the - // database 'sakila' + // + // Set up a user called 'sakila' with no password that has all privs on the + // database 'sakila'. + + connection = [[MCPConnection alloc] initToSocket:@"/var/mysql/mysql.sock" withLogin:@"sakila"]; - mySQLConnection = [[MCPConnection alloc] initToSocket:@"/var/mysql/mysql.sock" - withLogin:@"sakila" - password:@""]; + // Set the 'sakila' user's password + [connection setPassword:@""]; - if ( ![mySQLConnection isConnected] ) { - [mySQLConnection dealloc]; - mySQLConnection = nil; - STFail(@"unable to connect with server. No tests run!"); - } else { - if ( ! [mySQLConnection selectDB:@"sakila"]) { - [mySQLConnection dealloc]; - mySQLConnection = nil; - STFail(@"unable to use `sakila` database. No tests run!"); + if (![connection isConnected]) { + [connection dealloc]; + connection = nil; + STFail(@"Error connecting to database server. No tests were run."); + } + else { + if (![connection selectDB:@"sakila"]) { + [connection dealloc]; + connection = nil; + STFail(@"Error selecting database 'sakila'. No tests were run."); } } } - (void)tearDown { - if( mySQLConnection != nil ) { - [mySQLConnection disconnect]; - [mySQLConnection dealloc]; + if (connection != nil) { + [connection disconnect]; + [connection dealloc]; } } - (void)testServerVersion { - if( mySQLConnection == nil ) - return; + if (connection == nil) return; - STAssertTrue( [mySQLConnection serverMajorVersion] != 0, @"server version"); - STAssertTrue( [mySQLConnection serverMajorVersion] != 0, @"server version"); + STAssertTrue([connection serverMajorVersion] != 0, @"server version"); + STAssertTrue([connection serverMajorVersion] != 0, @"server version"); } - - (void)testTableList { - if( mySQLConnection == nil ) - return; - - MCPResult *theResult; + if (connection == nil) return; - NSString *pQuery = @"SELECT * FROM actor"; - theResult = [mySQLConnection queryString:pQuery]; + MCPResult *queryResult = [connection queryString:@"SELECT * FROM actor"]; - STAssertEquals([theResult numOfRows],(my_ulonglong)200, @"actors table count" ); + STAssertEquals([queryResult numOfRows], (my_ulonglong)200, @"actors table count"); } @end diff --git a/UnitTests/stringCategoryAdditionsTest.h b/UnitTests/stringCategoryAdditionsTest.h index 2fc611be..d995a29e 100644 --- a/UnitTests/stringCategoryAdditionsTest.h +++ b/UnitTests/stringCategoryAdditionsTest.h @@ -20,7 +20,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // More info at -// #import diff --git a/UnitTests/stringCategoryAdditionsTest.m b/UnitTests/stringCategoryAdditionsTest.m index cff13ac9..11a4a49b 100644 --- a/UnitTests/stringCategoryAdditionsTest.m +++ b/UnitTests/stringCategoryAdditionsTest.m @@ -20,7 +20,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // More info at -// #import "stringCategoryAdditionsTest.h" #import "SPStringAdditions.h" @@ -40,14 +39,17 @@ - (void)testStringByRemovingCharactersInSet { NSCharacterSet *junk = [NSCharacterSet characterSetWithCharactersInString:@"abc',ü"]; + NSString *s = @"this is big, crazy st'ring"; NSString *expect = @"this is ig rzy string"; - STAssertEqualObjects( [s stringByRemovingCharactersInSet:junk], expect, @"stringByRemovingCharactersInSet" ); - // check UTF + STAssertEqualObjects([s stringByRemovingCharactersInSet:junk], expect, @"stringByRemovingCharactersInSet"); + + // Check UTF s = @"In der Kürze liegt die Würz"; expect = @"In der Krze liegt die Wrz"; - STAssertEqualObjects( [s stringByRemovingCharactersInSet:junk], expect, @"stringByRemovingCharactersInSet" ); + + STAssertEqualObjects([s stringByRemovingCharactersInSet:junk], expect, @"stringByRemovingCharactersInSet"); } @end -- cgit v1.2.3