aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/QueryKit/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/QueryKit/Tests')
-rw-r--r--Frameworks/QueryKit/Tests/QKQueryTests.m53
-rw-r--r--Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h40
-rw-r--r--Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m78
-rw-r--r--Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h40
-rw-r--r--Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m116
-rw-r--r--Frameworks/QueryKit/Tests/QKSelectQueryTests.h40
-rw-r--r--Frameworks/QueryKit/Tests/QKSelectQueryTests.m95
-rw-r--r--Frameworks/QueryKit/Tests/QKTestCase.h52
-rw-r--r--Frameworks/QueryKit/Tests/QKTestCase.m55
-rw-r--r--Frameworks/QueryKit/Tests/QKUpdateQueryTests.h40
-rw-r--r--Frameworks/QueryKit/Tests/QKUpdateQueryTests.m75
11 files changed, 464 insertions, 220 deletions
diff --git a/Frameworks/QueryKit/Tests/QKQueryTests.m b/Frameworks/QueryKit/Tests/QKQueryTests.m
index b014c48c..dbccb9c0 100644
--- a/Frameworks/QueryKit/Tests/QKQueryTests.m
+++ b/Frameworks/QueryKit/Tests/QKQueryTests.m
@@ -29,15 +29,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
#import "QKTestConstants.h"
+#import "QKTestCase.h"
#import <QueryKit/QueryKit.h>
#import <SenTestingKit/SenTestingKit.h>
-@interface QKQueryTests : SenTestCase
-{
- QKQuery *_query;
-}
-
+@interface QKQueryTests : QKTestCase
@end
@implementation QKQueryTests
@@ -47,21 +44,23 @@
- (void)setUp
{
- _query = [QKQuery selectQueryFromTable:QKTestTableName];
+ QKQuery *query = [QKQuery selectQueryFromTable:QKTestTableName];
+
+ [query setUseQuotedIdentifiers:NO];
+ [query setQueryDatabase:QKDatabaseMySQL];
- [_query setUseQuotedIdentifiers:NO];
- [_query setQueryDatabase:QKDatabaseMySQL];
+ [query setDatabase:QKTestDatabaseName];
- [_query setDatabase:QKTestDatabaseName];
+ [query addField:QKTestFieldOne];
+ [query addField:QKTestFieldTwo];
+ [query addField:QKTestFieldThree];
+ [query addField:QKTestFieldFour];
- [_query addField:QKTestFieldOne];
- [_query addField:QKTestFieldTwo];
- [_query addField:QKTestFieldThree];
- [_query addField:QKTestFieldFour];
+ [query addParameter:QKTestFieldOne operator:QKEqualityOperator value:[NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
- [_query addParameter:QKTestFieldOne operator:QKEqualityOperator value:[NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
+ [query orderByField:QKTestFieldOne descending:NO];
- [_query orderByField:QKTestFieldOne descending:NO];
+ [self setQuery:query];
}
#pragma mark -
@@ -69,21 +68,21 @@
- (void)testCallingClearOnAQueryCorretlyResetsItToItsDefaultState
{
- [_query clear];
+ [[self query] clear];
- STAssertNil([_query table], @"query table");
- STAssertNil([_query database], @"query database");
+ STAssertNil([[self query] table], @"query table");
+ STAssertNil([[self query] database], @"query database");
- STAssertTrue([_query useQuotedIdentifiers], @"query use quoted identifiers");
- STAssertTrue([[_query identifierQuote] isEqualToString:EMPTY_STRING], @"query identifier quote");
- STAssertTrue([[_query fields] count] == 0, @"query fields");
- STAssertTrue([[_query parameters] count] == 0, @"query parameters");
- STAssertTrue([[_query updateParameters] count] == 0, @"query update parameters");
- STAssertTrue([[_query groupByFields] count] == 0, @"query group by fields");
- STAssertTrue([[_query orderByFields] count] == 0, @"query order by fields");
+ STAssertTrue([[self query] useQuotedIdentifiers], @"query use quoted identifiers");
+ STAssertTrue([[[self query] identifierQuote] isEqualToString:EMPTY_STRING], @"query identifier quote");
+ STAssertTrue([[[self query] fields] count] == 0, @"query fields");
+ STAssertTrue([[[self query] parameters] count] == 0, @"query parameters");
+ STAssertTrue([[[self query] updateParameters] count] == 0, @"query update parameters");
+ STAssertTrue([[[self query] groupByFields] count] == 0, @"query group by fields");
+ STAssertTrue([[[self query] orderByFields] count] == 0, @"query order by fields");
- STAssertEquals([_query queryType], QKUnknownQuery, @"query type");
- STAssertEquals([_query queryDatabase], QKDatabaseUnknown, @"query database");
+ STAssertEquals([[self query] queryType], QKUnknownQuery, @"query type");
+ STAssertEquals([[self query] queryDatabase], QKDatabaseUnknown, @"query database");
}
@end
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h
new file mode 100644
index 00000000..ba3d9020
--- /dev/null
+++ b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h
@@ -0,0 +1,40 @@
+//
+// $Id$
+//
+// QKSelectQueryGroupByTests.h
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 18, 2012
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import "QKTestCase.h"
+
+#import <QueryKit/QueryKit.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface QKSelectQueryGroupByTests : QKTestCase
+
++ (void)addTestForDatabase:(QKQueryDatabase)database withIdentifierQuote:(NSString *)quote toTestSuite:(SenTestSuite *)testSuite;
+
+@end \ No newline at end of file
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m
index 649f3173..076cb9cb 100644
--- a/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m
+++ b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m
@@ -28,29 +28,51 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
+#import "QKSelectQueryGroupByTests.h"
#import "QKTestConstants.h"
-#import <QueryKit/QueryKit.h>
-#import <SenTestingKit/SenTestingKit.h>
+@implementation QKSelectQueryGroupByTests
+
+#pragma mark -
+#pragma mark Initialisation
-@interface QKSelectQueryGroupByTests : SenTestCase
++ (id)defaultTestSuite
{
- QKQuery *_query;
+ SenTestSuite *testSuite = [[SenTestSuite alloc] initWithName:NSStringFromClass(self)];
+
+ [self addTestForDatabase:QKDatabaseUnknown withIdentifierQuote:EMPTY_STRING toTestSuite:testSuite];
+ [self addTestForDatabase:QKDatabaseMySQL withIdentifierQuote:QKMySQLIdentifierQuote toTestSuite:testSuite];
+ [self addTestForDatabase:QKDatabasePostgreSQL withIdentifierQuote:QKPostgreSQLIdentifierQuote toTestSuite:testSuite];
+
+ return [testSuite autorelease];
}
-@end
-
-@implementation QKSelectQueryGroupByTests
++ (void)addTestForDatabase:(QKQueryDatabase)database withIdentifierQuote:(NSString *)quote toTestSuite:(SenTestSuite *)testSuite
+{
+ for (NSInvocation *invocation in [self testInvocations])
+ {
+ SenTestCase *test = [[QKSelectQueryGroupByTests alloc] initWithInvocation:invocation database:database identifierQuote:quote];
+
+ [testSuite addTest:test];
+
+ [test release];
+ }
+}
#pragma mark -
#pragma mark Setup
- (void)setUp
{
- _query = [QKQuery selectQueryFromTable:QKTestTableName];
+ QKQuery *query = [QKQuery selectQueryFromTable:QKTestTableName];
+
+ [query setQueryDatabase:[self database]];
+ [query setUseQuotedIdentifiers:[self identifierQuote] && [[self identifierQuote] length] > 0];
+
+ [query addField:QKTestFieldOne];
+ [query addField:QKTestFieldTwo];
- [_query addField:QKTestFieldOne];
- [_query addField:QKTestFieldTwo];
+ [self setQuery:query];
}
#pragma mark -
@@ -58,45 +80,25 @@
- (void)testSelectQueryTypeIsCorrect
{
- STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"select query type");
+ STAssertTrue([[[self query] query] hasPrefix:@"SELECT"], nil);
}
- (void)testSelectQueryGroupByIsCorrect
{
- [_query groupByField:QKTestFieldOne];
+ [[self query] groupByField:QKTestFieldOne];
- NSString *query = [NSString stringWithFormat:@"GROUP BY `%@`", QKTestFieldOne];
-
- STAssertTrue([[_query query] hasSuffix:query], @"select query group by");
-}
-
-- (void)testSelectQueryGroupByWithoutQuotesIsCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
- [_query groupByField:QKTestFieldOne];
-
- NSString *query = [NSString stringWithFormat:@"GROUP BY %@", QKTestFieldOne];
-
- STAssertTrue([[_query query] hasSuffix:query], @"select query group by without quotes");
+ NSString *query = [NSString stringWithFormat:@"GROUP BY %1$@%2$@%1$@", [self identifierQuote], QKTestFieldOne];
+
+ STAssertTrue([[[self query] query] hasSuffix:query], nil);
}
- (void)testSelectQueryGroupByMultipleFieldsIsCorrect
{
- [_query groupByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil]];
-
- NSString *query = [NSString stringWithFormat:@"GROUP BY `%@`, `%@`", QKTestFieldOne, QKTestFieldTwo];
-
- STAssertTrue([[_query query] hasSuffix:query], @"select query group by multiple fields");
-}
-
-- (void)testSelectQueryGroupByMultipleFieldsWithoutQuotesIsCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
- [_query groupByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil]];
+ [[self query] groupByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil]];
- NSString *query = [NSString stringWithFormat:@"GROUP BY %@, %@", QKTestFieldOne, QKTestFieldTwo];
+ NSString *query = [NSString stringWithFormat:@"GROUP BY %1$@%2$@%1$@, %1$@%3$@%1$@", [self identifierQuote], QKTestFieldOne, QKTestFieldTwo];
- STAssertTrue([[_query query] hasSuffix:query], @"select query group by multiple fields without quotes");
+ STAssertTrue([[[self query] query] hasSuffix:query], nil);
}
@end
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h
new file mode 100644
index 00000000..f16ee659
--- /dev/null
+++ b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h
@@ -0,0 +1,40 @@
+//
+// $Id$
+//
+// QKSelectQueryOrderByTests.h
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 18, 2012
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import "QKTestCase.h"
+
+#import <QueryKit/QueryKit.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface QKSelectQueryOrderByTests : QKTestCase
+
++ (void)addTestForDatabase:(QKQueryDatabase)database withIdentifierQuote:(NSString *)quote toTestSuite:(SenTestSuite *)testSuite;
+
+@end
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m
index 2f467bea..ad13ce33 100644
--- a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m
+++ b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m
@@ -28,29 +28,51 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
+#import "QKSelectQueryOrderByTests.h"
#import "QKTestConstants.h"
-#import <QueryKit/QueryKit.h>
-#import <SenTestingKit/SenTestingKit.h>
+@implementation QKSelectQueryOrderByTests
+
+#pragma mark -
+#pragma mark Initialisation
-@interface QKSelectQueryOrderByTests : SenTestCase
++ (id)defaultTestSuite
{
- QKQuery *_query;
+ SenTestSuite *testSuite = [[SenTestSuite alloc] initWithName:NSStringFromClass(self)];
+
+ [self addTestForDatabase:QKDatabaseUnknown withIdentifierQuote:EMPTY_STRING toTestSuite:testSuite];
+ [self addTestForDatabase:QKDatabaseMySQL withIdentifierQuote:QKMySQLIdentifierQuote toTestSuite:testSuite];
+ [self addTestForDatabase:QKDatabasePostgreSQL withIdentifierQuote:QKPostgreSQLIdentifierQuote toTestSuite:testSuite];
+
+ return [testSuite autorelease];
}
-@end
-
-@implementation QKSelectQueryOrderByTests
++ (void)addTestForDatabase:(QKQueryDatabase)database withIdentifierQuote:(NSString *)quote toTestSuite:(SenTestSuite *)testSuite
+{
+ for (NSInvocation *invocation in [self testInvocations])
+ {
+ SenTestCase *test = [[QKSelectQueryOrderByTests alloc] initWithInvocation:invocation database:database identifierQuote:quote];
+
+ [testSuite addTest:test];
+
+ [test release];
+ }
+}
#pragma mark -
#pragma mark Setup
- (void)setUp
{
- _query = [QKQuery selectQueryFromTable:QKTestTableName];
+ QKQuery *query = [QKQuery selectQueryFromTable:QKTestTableName];
+
+ [query setQueryDatabase:[self database]];
+ [query setUseQuotedIdentifiers:[self identifierQuote] && [[self identifierQuote] length] > 0];
- [_query addField:QKTestFieldOne];
- [_query addField:QKTestFieldTwo];
+ [query addField:QKTestFieldOne];
+ [query addField:QKTestFieldTwo];
+
+ [self setQuery:query];
}
#pragma mark -
@@ -58,89 +80,45 @@
- (void)testSelectQueryTypeIsCorrect
{
- STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"select query type");
+ STAssertTrue([[[self query] query] hasPrefix:@"SELECT"], nil);
}
- (void)testSelectQueryOrderByAscendingIsCorrect
{
- [_query orderByField:QKTestFieldOne descending:NO];
+ [[self query] orderByField:QKTestFieldOne descending:NO];
- NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` ASC", QKTestFieldOne];
-
- STAssertTrue([[_query query] hasSuffix:query], @"");
-}
-
-- (void)testSelectQueryOrderByAscendingWithoutQuotesIsCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
- [_query orderByField:QKTestFieldOne descending:NO];
-
- NSString *query = [NSString stringWithFormat:@"ORDER BY %@ ASC", QKTestFieldOne];
+ NSString *query = [NSString stringWithFormat:@"ORDER BY %1$@%2$@%1$@ ASC", [self identifierQuote], QKTestFieldOne];
- STAssertTrue([[_query query] hasSuffix:query], @"select query order by without quotes");
+ STAssertTrue([[[self query] query] hasSuffix:query], nil);
}
- (void)testSelectQueryOrderByMultipleFieldsAscendingIsCorrect
{
- [_query orderByField:QKTestFieldOne descending:NO];
- [_query orderByField:QKTestFieldTwo descending:NO];
+ [[self query] orderByField:QKTestFieldOne descending:NO];
+ [[self query] orderByField:QKTestFieldTwo descending:NO];
- NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` ASC, `%@` ASC", QKTestFieldOne, QKTestFieldTwo];
+ NSString *query = [NSString stringWithFormat:@"ORDER BY %1$@%2$@%1$@ ASC, %1$@%3$@%1$@ ASC", [self identifierQuote], QKTestFieldOne, QKTestFieldTwo];
- STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields ascending when quoted");
-}
-
-- (void)testSelectQueryOrderByMultipleFieldsAscendingWithoutQuotesIsCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
-
- [_query orderByField:QKTestFieldOne descending:NO];
- [_query orderByField:QKTestFieldTwo descending:NO];
-
- NSString *query = [NSString stringWithFormat:@"ORDER BY %@ ASC, %@ ASC", QKTestFieldOne, QKTestFieldTwo];
-
- STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields ascending without quotes");
+ STAssertTrue([[[self query] query] hasSuffix:query], nil);
}
- (void)testSelectQueryOrderByDescendingIsCorrect
{
- [_query orderByField:QKTestFieldOne descending:YES];
+ [[self query] orderByField:QKTestFieldOne descending:YES];
- NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` DESC", QKTestFieldOne];
+ NSString *query = [NSString stringWithFormat:@"ORDER BY %1$@%2$@%1$@ DESC", [self identifierQuote], QKTestFieldOne];
- STAssertTrue([[_query query] hasSuffix:query], @"select query order by descending");
-}
-
-- (void)testSelectQueryOrderByDescendingWithoutQuotesIsCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
- [_query orderByField:QKTestFieldOne descending:YES];
-
- NSString *query = [NSString stringWithFormat:@"ORDER BY %@ DESC", QKTestFieldOne];
-
- STAssertTrue([[_query query] hasSuffix:query], @"select query order by descending without quotes");
+ STAssertTrue([[[self query] query] hasSuffix:query], nil);
}
- (void)testSelectQueryOrderByMultipleFieldsDescendingIsCorrect
{
- [_query orderByField:QKTestFieldOne descending:YES];
- [_query orderByField:QKTestFieldTwo descending:YES];
-
- NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` DESC, `%@` DESC", QKTestFieldOne, QKTestFieldTwo];
-
- STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields descending");
-}
-
-- (void)testSelectQueryOrderByMultipleFieldsDescendingWithoutQuotesIsCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
-
- [_query orderByField:QKTestFieldOne descending:YES];
- [_query orderByField:QKTestFieldTwo descending:YES];
+ [[self query] orderByField:QKTestFieldOne descending:YES];
+ [[self query] orderByField:QKTestFieldTwo descending:YES];
- NSString *query = [NSString stringWithFormat:@"ORDER BY %@ DESC, %@ DESC", QKTestFieldOne, QKTestFieldTwo];
+ NSString *query = [NSString stringWithFormat:@"ORDER BY %1$@%2$@%1$@ DESC, %1$@%3$@%1$@ DESC", [self identifierQuote], QKTestFieldOne, QKTestFieldTwo];
- STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields descending without quotes");
+ STAssertTrue([[[self query] query] hasSuffix:query], nil);
}
@end
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryTests.h b/Frameworks/QueryKit/Tests/QKSelectQueryTests.h
new file mode 100644
index 00000000..22c75352
--- /dev/null
+++ b/Frameworks/QueryKit/Tests/QKSelectQueryTests.h
@@ -0,0 +1,40 @@
+//
+// $Id$
+//
+// QKSelectQueryTests.h
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 17, 2012
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import "QKTestCase.h"
+
+#import <QueryKit/QueryKit.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface QKSelectQueryTests : QKTestCase
+
++ (void)addTestForDatabase:(QKQueryDatabase)database withIdentifierQuote:(NSString *)quote toTestSuite:(SenTestSuite *)testSuite;
+
+@end
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m
index 8e12e13a..3eebb707 100644
--- a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m
+++ b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m
@@ -22,39 +22,61 @@
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// ;. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
+#import "QKSelectQueryTests.h"
#import "QKTestConstants.h"
-#import <QueryKit/QueryKit.h>
-#import <SenTestingKit/SenTestingKit.h>
+@implementation QKSelectQueryTests
+
+#pragma mark -
+#pragma mark Initialisation
-@interface QKSelectQueryTests : SenTestCase
++ (id)defaultTestSuite
{
- QKQuery *_query;
+ SenTestSuite *testSuite = [[SenTestSuite alloc] initWithName:NSStringFromClass(self)];
+
+ [self addTestForDatabase:QKDatabaseUnknown withIdentifierQuote:EMPTY_STRING toTestSuite:testSuite];
+ [self addTestForDatabase:QKDatabaseMySQL withIdentifierQuote:QKMySQLIdentifierQuote toTestSuite:testSuite];
+ [self addTestForDatabase:QKDatabasePostgreSQL withIdentifierQuote:QKPostgreSQLIdentifierQuote toTestSuite:testSuite];
+
+ return [testSuite autorelease];
}
-@end
-
-@implementation QKSelectQueryTests
++ (void)addTestForDatabase:(QKQueryDatabase)database withIdentifierQuote:(NSString *)quote toTestSuite:(SenTestSuite *)testSuite
+{
+ for (NSInvocation *invocation in [self testInvocations])
+ {
+ SenTestCase *test = [[QKSelectQueryTests alloc] initWithInvocation:invocation database:database identifierQuote:quote];
+
+ [testSuite addTest:test];
+
+ [test release];
+ }
+}
#pragma mark -
#pragma mark Setup
- (void)setUp
{
- _query = [QKQuery selectQueryFromTable:QKTestTableName];
+ QKQuery *query = [QKQuery selectQueryFromTable:QKTestTableName];
+
+ [query setQueryDatabase:[self database]];
+ [query setUseQuotedIdentifiers:[self identifierQuote] && [[self identifierQuote] length] > 0];
- [_query addField:QKTestFieldOne];
- [_query addField:QKTestFieldTwo];
- [_query addField:QKTestFieldThree];
- [_query addField:QKTestFieldFour];
+ [query addField:QKTestFieldOne];
+ [query addField:QKTestFieldTwo];
+ [query addField:QKTestFieldThree];
+ [query addField:QKTestFieldFour];
- [_query addParameter:QKTestFieldOne operator:QKEqualityOperator value:[NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
+ [query addParameter:QKTestFieldOne operator:QKEqualityOperator value:[NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
+
+ [self setQuery:query];
}
#pragma mark -
@@ -62,55 +84,28 @@
- (void)testSelectQueryTypeIsCorrect
{
- STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"select query type");
+ STAssertTrue([[[self query] query] hasPrefix:@"SELECT"], nil);
}
- (void)testSelectQueryFieldIsCorrect
-{
- NSString *query = [NSString stringWithFormat:@"SELECT `%@`", QKTestFieldOne];
-
- STAssertTrue([[_query query] hasPrefix:query], @"select query field");
-}
-
-- (void)testSelectQueryFieldWithoutQuotesIsCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
-
- NSString *query = [NSString stringWithFormat:@"SELECT %@", QKTestFieldOne];
-
- STAssertTrue([[_query query] hasPrefix:query], @"select query field without quotes");
+{
+ NSString *query = [NSString stringWithFormat:@"SELECT %1$@%2$@%1$@", [self identifierQuote], QKTestFieldOne];
+
+ STAssertTrue([[[self query] query] hasPrefix:query], nil);
}
- (void)testSelectQueryMultipleFieldsWhenQuotedAreCorrect
{
- NSString *query = [NSString stringWithFormat:@"SELECT `%@`, `%@`, `%@`, `%@`", QKTestFieldOne, QKTestFieldTwo, QKTestFieldThree, QKTestFieldFour];
-
- STAssertTrue([[_query query] hasPrefix:query], @"select query multiple fields");
-}
-
-- (void)testSelectQueryMultipleFieldsWithoutQuotesAreCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
-
- NSString *query = [NSString stringWithFormat:@"SELECT %@, %@, %@, %@", QKTestFieldOne, QKTestFieldTwo, QKTestFieldThree, QKTestFieldFour];
+ NSString *query = [NSString stringWithFormat:@"SELECT %1$@%2$@%1$@, %1$@%3$@%1$@, %1$@%4$@%1$@, %1$@%5$@%1$@", [self identifierQuote], QKTestFieldOne, QKTestFieldTwo, QKTestFieldThree, QKTestFieldFour];
- STAssertTrue([[_query query] hasPrefix:query], @"select query multiple fields without quotes");
+ STAssertTrue([[[self query] query] hasPrefix:query], nil);
}
- (void)testSelectQueryConstraintsAreCorrect
{
- NSString *query = [NSString stringWithFormat:@"WHERE `%@` %@ %@", QKTestFieldOne, [QKQueryUtilities stringRepresentationOfQueryOperator:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
+ NSString *query = [NSString stringWithFormat:@"WHERE %1$@%2$@%1$@ %3$@ %4$@", [self identifierQuote], QKTestFieldOne, [QKQueryUtilities stringRepresentationOfQueryOperator:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
- STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"select query constraint");
-}
-
-- (void)testSelectQueryConstraintsWithoutQuotesAreCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
-
- NSString *query = [NSString stringWithFormat:@"WHERE %@ %@ %@", QKTestFieldOne, [QKQueryUtilities stringRepresentationOfQueryOperator:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
-
- STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"select query constraint without quotes");
+ STAssertTrue(([[[self query] query] rangeOfString:query].location != NSNotFound), nil);
}
@end
diff --git a/Frameworks/QueryKit/Tests/QKTestCase.h b/Frameworks/QueryKit/Tests/QKTestCase.h
new file mode 100644
index 00000000..45f1911a
--- /dev/null
+++ b/Frameworks/QueryKit/Tests/QKTestCase.h
@@ -0,0 +1,52 @@
+//
+// $Id$
+//
+// QKTestCase.h
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 18, 2012
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import <QueryKit/QueryKit.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface QKTestCase : SenTestCase
+{
+@private
+ QKQuery *_query;
+
+ NSString *_identifierQuote;
+
+ QKQueryDatabase _database;
+}
+
+@property (readwrite, retain) QKQuery *query;
+
+@property (readwrite, retain) NSString *identifierQuote;
+
+@property (readwrite, assign) QKQueryDatabase database;
+
+- (id)initWithInvocation:(NSInvocation *)invocation database:(QKQueryDatabase)database identifierQuote:(NSString *)quote;
+
+@end
diff --git a/Frameworks/QueryKit/Tests/QKTestCase.m b/Frameworks/QueryKit/Tests/QKTestCase.m
new file mode 100644
index 00000000..c129e07a
--- /dev/null
+++ b/Frameworks/QueryKit/Tests/QKTestCase.m
@@ -0,0 +1,55 @@
+//
+// $Id$
+//
+// QKTestCase.m
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 18, 2012
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import "QKTestCase.h"
+
+@implementation QKTestCase
+
+@synthesize query = _query;
+@synthesize identifierQuote = _identifierQuote;
+@synthesize database = _database;
+
+- (id)initWithInvocation:(NSInvocation *)invocation database:(QKQueryDatabase)database identifierQuote:(NSString *)quote
+{
+ if ((self = [super initWithInvocation:invocation])) {
+ [self setDatabase:database];
+ [self setIdentifierQuote:quote];
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ if (_query) [_query release], _query = nil;
+ if (_identifierQuote) [_identifierQuote release], _identifierQuote = nil;
+}
+
+@end
diff --git a/Frameworks/QueryKit/Tests/QKUpdateQueryTests.h b/Frameworks/QueryKit/Tests/QKUpdateQueryTests.h
new file mode 100644
index 00000000..c4dad17c
--- /dev/null
+++ b/Frameworks/QueryKit/Tests/QKUpdateQueryTests.h
@@ -0,0 +1,40 @@
+//
+// $Id$
+//
+// QKUpdateQueryTests.h
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 17, 2012
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import "QKTestCase.h"
+
+#import <QueryKit/QueryKit.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface QKUpdateQueryTests : QKTestCase
+
++ (void)addTestForDatabase:(QKQueryDatabase)database withIdentifierQuote:(NSString *)quote toTestSuite:(SenTestSuite *)testSuite;
+
+@end \ No newline at end of file
diff --git a/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m b/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m
index 4c585aee..afeb9434 100644
--- a/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m
+++ b/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m
@@ -28,33 +28,54 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
+#import "QKUpdateQueryTests.h"
#import "QKTestConstants.h"
-#import <QueryKit/QueryKit.h>
-#import <SenTestingKit/SenTestingKit.h>
+@implementation QKUpdateQueryTests
+
+#pragma mark -
+#pragma mark Initialisation
-@interface QKUpdateQueryTests : SenTestCase
++ (id)defaultTestSuite
{
- QKQuery *_query;
+ SenTestSuite *testSuite = [[SenTestSuite alloc] initWithName:NSStringFromClass(self)];
+
+ [self addTestForDatabase:QKDatabaseUnknown withIdentifierQuote:EMPTY_STRING toTestSuite:testSuite];
+ [self addTestForDatabase:QKDatabaseMySQL withIdentifierQuote:QKMySQLIdentifierQuote toTestSuite:testSuite];
+ [self addTestForDatabase:QKDatabasePostgreSQL withIdentifierQuote:QKPostgreSQLIdentifierQuote toTestSuite:testSuite];
+
+ return [testSuite autorelease];
}
-@end
-
-@implementation QKUpdateQueryTests
++ (void)addTestForDatabase:(QKQueryDatabase)database withIdentifierQuote:(NSString *)quote toTestSuite:(SenTestSuite *)testSuite
+{
+ for (NSInvocation *invocation in [self testInvocations])
+ {
+ SenTestCase *test = [[NSClassFromString(@"QKUpdateQueryTests") alloc] initWithInvocation:invocation database:database identifierQuote:quote];
+
+ [testSuite addTest:test];
+
+ [test release];
+ }
+}
#pragma mark -
#pragma mark Setup
- (void)setUp
{
- _query = [QKQuery queryTable:QKTestTableName];
+ QKQuery *query = [QKQuery queryTable:QKTestTableName];
+
+ [query setQueryType:QKUpdateQuery];
+ [query setQueryDatabase:[self database]];
+ [query setUseQuotedIdentifiers:[self identifierQuote] && [[self identifierQuote] length] > 0];
- [_query setQueryType:QKUpdateQuery];
+ [query addFieldToUpdate:QKTestFieldOne toValue:QKTestUpdateValueOne];
+ [query addFieldToUpdate:QKTestFieldTwo toValue:QKTestUpdateValueTwo];
- [_query addFieldToUpdate:QKTestFieldOne toValue:QKTestUpdateValueOne];
- [_query addFieldToUpdate:QKTestFieldTwo toValue:QKTestUpdateValueTwo];
+ [query addParameter:QKTestFieldOne operator:QKEqualityOperator value:[NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
- [_query addParameter:QKTestFieldOne operator:QKEqualityOperator value:[NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
+ [self setQuery:query];
}
#pragma mark -
@@ -62,39 +83,21 @@
- (void)testUpdateQueryTypeIsCorrect
{
- STAssertTrue([[_query query] hasPrefix:@"UPDATE"], @"update query type");
+ STAssertTrue([[[self query] query] hasPrefix:@"UPDATE"], nil);
}
- (void)testUpdateQueryFieldsAreCorrect
{
- NSString *query = [NSString stringWithFormat:@"UPDATE `%@` SET `%@` = '%@', `%@` = '%@'", QKTestTableName, QKTestFieldOne, QKTestUpdateValueOne, QKTestFieldTwo, QKTestUpdateValueTwo];
+ NSString *query = [NSString stringWithFormat:@"UPDATE %1$@%2$@%1$@ SET %1$@%3$@%1$@ = '%4$@', %1$@%5$@%1$@ = '%6$@'", [self identifierQuote], QKTestTableName, QKTestFieldOne, QKTestUpdateValueOne, QKTestFieldTwo, QKTestUpdateValueTwo];
- STAssertTrue([[_query query] hasPrefix:query], @"update query fields");
-}
-
-- (void)testUpdateQueryFieldsWithoutQuotesAreCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
-
- NSString *query = [NSString stringWithFormat:@"UPDATE %@ SET %@ = '%@', %@ = '%@'", QKTestTableName, QKTestFieldOne, QKTestUpdateValueOne, QKTestFieldTwo, QKTestUpdateValueTwo];
-
- STAssertTrue([[_query query] hasPrefix:query], @"update query fields without quotes");
+ STAssertTrue([[[self query] query] hasPrefix:query], nil);
}
- (void)testUpdateQueryConstraintIsCorrect
{
- NSString *query = [NSString stringWithFormat:@"WHERE `%@` %@ %@", QKTestFieldOne, [QKQueryUtilities stringRepresentationOfQueryOperator:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
-
- STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"update query constraint");
-}
-
-- (void)testUpdateQueryConstraintWithoutQuotesIsCorrect
-{
- [_query setUseQuotedIdentifiers:NO];
-
- NSString *query = [NSString stringWithFormat:@"WHERE %@ %@ %@", QKTestFieldOne, [QKQueryUtilities stringRepresentationOfQueryOperator:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
-
- STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"update query constraint without quotes");
+ NSString *query = [NSString stringWithFormat:@"WHERE %1$@%2$@%1$@ %3$@ %4$@", [self identifierQuote], QKTestFieldOne, [QKQueryUtilities stringRepresentationOfQueryOperator:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
+
+ STAssertTrue(([[[self query] query] rangeOfString:query].location != NSNotFound), nil);
}
@end