aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/PostgresKit/Tests/PGDataTypeTests.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2013-01-16 22:52:09 +0000
committerstuconnolly <stuart02@gmail.com>2013-01-16 22:52:09 +0000
commitf5e507a38ba2a73619cfc3349257507c445464af (patch)
tree41e45a2b66f843592f0ccc759a10b96be2f826b2 /Frameworks/PostgresKit/Tests/PGDataTypeTests.m
parentc2d9b3fd35e64cbb307cc04fb6789dc4656f9ca3 (diff)
downloadsequelpro-f5e507a38ba2a73619cfc3349257507c445464af.tar.gz
sequelpro-f5e507a38ba2a73619cfc3349257507c445464af.tar.bz2
sequelpro-f5e507a38ba2a73619cfc3349257507c445464af.zip
PostgresKit: Fix the integration tests as well as some issues that they highlighted.
Diffstat (limited to 'Frameworks/PostgresKit/Tests/PGDataTypeTests.m')
-rw-r--r--Frameworks/PostgresKit/Tests/PGDataTypeTests.m38
1 files changed, 17 insertions, 21 deletions
diff --git a/Frameworks/PostgresKit/Tests/PGDataTypeTests.m b/Frameworks/PostgresKit/Tests/PGDataTypeTests.m
index 8bea485e..b334c9f6 100644
--- a/Frameworks/PostgresKit/Tests/PGDataTypeTests.m
+++ b/Frameworks/PostgresKit/Tests/PGDataTypeTests.m
@@ -67,7 +67,7 @@ static NSUInteger PGTestDatabasePort = 5432;
[self _addTestForField:@"int" withExpectedResult:[NSNumber numberWithInt:12345] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"smallint" withExpectedResult:[NSNumber numberWithInt:2] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"bigint" withExpectedResult:[NSNumber numberWithInt:123456789] connection:connection toTestSuite:testSuite];
- [self _addTestForField:@"bool" withExpectedResult:[NSNumber numberWithBool:YES] connection:connection toTestSuite:testSuite];
+ [self _addTestForField:@"bool" withExpectedResult:[NSNumber numberWithInteger:1] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"float" withExpectedResult:[NSNumber numberWithFloat:12345.678] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"numeric" withExpectedResult:[NSNumber numberWithDouble:12345.678] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"char" withExpectedResult:@"CHAR" connection:connection toTestSuite:testSuite];
@@ -103,17 +103,10 @@ static NSUInteger PGTestDatabasePort = 5432;
#pragma mark Setup & Teardown
- (void)setUp
-{
- PGPostgresResult *queryResult = [_connection executeWithFormat:@"SELECT \"%@\" FROM \"data_types\"", _field];
+{
+ PGPostgresResult *queryResult = [_connection executeWithFormat:@"SELECT \"%@_field\" FROM \"data_types\"", _field];
- _result = [[queryResult row] objectForKey:_field];
-}
-
-- (void)tearDown
-{
- if (_connection && [_connection isConnected]) {
- [_connection disconnect];
- }
+ [self setResult:[[queryResult row] objectForKey:[NSString stringWithFormat:@"%@_field", _field]]];
}
#pragma mark -
@@ -125,32 +118,31 @@ static NSUInteger PGTestDatabasePort = 5432;
}
- (void)testResultIsOfCorrectType
-{
+{
STAssertTrue([_result isKindOfClass:[_expectedResult class]], @"");
}
- (void)testResultHasCorrectValue
-{
- STAssertEquals(_result, _expectedResult, @"");
+{
+ STAssertEqualObjects(_result, _expectedResult, @"");
}
-#pragma mark -
+#pragma mark -r
#pragma mark Private API
- (void)_establishConnection
{
+ [_connection setDelegate:self];
+
[_connection setHost:PGTestDatabaseHost];
[_connection setUser:PGTestDatabaseUser];
[_connection setPort:PGTestDatabasePort];
[_connection setDatabase:PGTestDatabaseName];
[_connection setPassword:PGTestDatabasePassword];
- do {
- sleep(0.1);
- }
- while (![_connection isConnected]);
-
- if (![_connection isConnected]) STFail(@"Unable to establish connection to local database. All tests will fail.");
+ if (![_connection connect] || ![_connection isConnected]) {
+ STFail(@"Unable to establish connection to local database. All tests will fail.");
+ }
}
+ (void)_addTestForField:(NSString *)field
@@ -172,6 +164,10 @@ static NSUInteger PGTestDatabasePort = 5432;
- (void)dealloc
{
+ if (_connection && [_connection isConnected]) {
+ [_connection disconnect];
+ }
+
if (_result) [_result release], _result = nil;
if (_field) [_field release], _field = nil;
if (_connection) [_connection release], _connection = nil;