aboutsummaryrefslogtreecommitdiffstats
path: root/UnitTests/MCPKitTest.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2011-01-27 20:38:23 +0000
committerstuconnolly <stuart02@gmail.com>2011-01-27 20:38:23 +0000
commit8db2f78294982e89fce5a162d92b2be6d9291aa1 (patch)
treeb8dc7736f4af896aa3ed3fa9a96d1f3c4bfd0e59 /UnitTests/MCPKitTest.m
parentfa7cff57548edc51420693e6909fe2adb3c18951 (diff)
parent7cc062247ff23496dd0390cf07b5d45d6bc49777 (diff)
downloadsequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.tar.gz
sequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.tar.bz2
sequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.zip
Bring outline view branch up to date with trunk (r3056:r3162).
Diffstat (limited to 'UnitTests/MCPKitTest.m')
-rw-r--r--UnitTests/MCPKitTest.m88
1 files changed, 63 insertions, 25 deletions
diff --git a/UnitTests/MCPKitTest.m b/UnitTests/MCPKitTest.m
index e347d9da..4480b0a1 100644
--- a/UnitTests/MCPKitTest.m
+++ b/UnitTests/MCPKitTest.m
@@ -27,59 +27,97 @@
#import "MCPKitTest.h"
+static const NSString *SPTestDatabaseHost = @"127.0.0.1";
+static const NSString *SPTestDatabaseName = @"sakila";
+static const NSString *SPTestDatabaseUser = @"sp_tester";
+static const NSString *SPTestDatabasePassword = @"";
+
+static const NSInteger SPTestDatabasePort = 3306;
+
@implementation MCPKitTest
+#pragma mark -
+#pragma mark Setup & tear down
+
+/**
+ * Sets up the connection for use in the test cases.
+ */
- (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.
- // 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'.
+ connection = [[MCPConnection alloc] initToHost:SPTestDatabaseHost withLogin:SPTestDatabaseUser usingPort:SPTestDatabasePort];
+
+ [connection setPassword:SPTestDatabasePassword];
- connection = [[MCPConnection alloc] initToSocket:@"/var/mysql/mysql.sock" withLogin:@"sakila"];
+ [connection setConnectionTimeout:10];
+ [connection setUseKeepAlive:1];
+ [connection setKeepAliveInterval:60];
- // Set the 'sakila' user's password
- [connection setPassword:@""];
+ [connection connect];
if (![connection isConnected]) {
- [connection dealloc];
- connection = nil;
+ [connection release], 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.");
+ if (![connection selectDB:SPTestDatabaseName]) {
+ [connection release], connection = nil;
+
+ STFail(@"Error selecting database '%@'. No tests were run.", SPTestDatabaseName);
}
}
}
+/**
+ * Disconnects the connection if connected.
+ */
- (void)tearDown
{
- if (connection != nil) {
+ if (connection && [connection isConnected]) {
[connection disconnect];
- [connection dealloc];
}
+
+ [connection release], connection = nil;
}
-- (void)testServerVersion
+#pragma mark -
+#pragma mark Tests
+
+/**
+ * Tests the connection's major version number.
+ */
+- (void)testServerMajorVersion
{
- if (connection == nil) return;
+ if ((!connection) || (![connection isConnected])) return;
- STAssertTrue([connection serverMajorVersion] != 0, @"server version");
- STAssertTrue([connection serverMajorVersion] != 0, @"server version");
+ STAssertTrue(([connection serverMajorVersion] != 0), @"server major version");
}
-- (void)testTableList
+/**
+ * Tests the connection's version string.
+ */
+- (void)testServerVersionString
{
- if (connection == nil) return;
+ if ((!connection) || (![connection isConnected])) return;
+
+ STAssertTrue(([[connection serverVersionString] length] > 0), @"server version string");
+}
+
+/**
+ * Tests the connection query execution.
+ */
+- (void)testQueryExexution
+{
+ if ((!connection) || (![connection isConnected])) return;
- MCPResult *queryResult = [connection queryString:@"SELECT * FROM actor"];
+ MCPResult *result = [connection queryString:@"SELECT * FROM actor"];
- STAssertEquals([queryResult numOfRows], (my_ulonglong)200, @"actors table count");
+ if ([connection queryErrored]) {
+ STFail(@"Query execution failed with error: %@", [connection getLastErrorMessage]);
+ }
+ else {
+ STAssertEquals([result numOfRows], (my_ulonglong)200, @"'actors' table count");
+ }
}
@end