diff options
author | stuconnolly <stuart02@gmail.com> | 2012-07-18 11:24:06 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-07-18 11:24:06 +0000 |
commit | 523a4334f8bf80a0c441871db93ae83eaaa2a5ed (patch) | |
tree | 896a3890d9bec824b043371ad7626ab0d9ede8df /Frameworks | |
parent | 25f16dd7b9d6de440763f0d0188a0f7e520b2126 (diff) | |
download | sequelpro-523a4334f8bf80a0c441871db93ae83eaaa2a5ed.tar.gz sequelpro-523a4334f8bf80a0c441871db93ae83eaaa2a5ed.tar.bz2 sequelpro-523a4334f8bf80a0c441871db93ae83eaaa2a5ed.zip |
Rework QueryKit's tests to accept parameters allowing use to run them with different data sets.
Diffstat (limited to 'Frameworks')
-rw-r--r-- | Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj | 18 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryConstants.h | 3 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryConstants.m | 32 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryUtilities.m | 4 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QueryKit.h | 1 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKQueryTests.m | 53 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h | 40 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m | 78 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h | 40 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m | 116 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryTests.h | 40 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryTests.m | 95 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKTestCase.h | 52 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKTestCase.m | 55 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKUpdateQueryTests.h | 40 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKUpdateQueryTests.m | 75 |
16 files changed, 520 insertions, 222 deletions
diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj index cd0563ff..91dc8e16 100644 --- a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj +++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj @@ -16,10 +16,12 @@ 1726976715AC3DD2009586E1 /* QKQueryDatabases.h in Headers */ = {isa = PBXBuildFile; fileRef = 1726976515AC3DD2009586E1 /* QKQueryDatabases.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1726979515AEE939009586E1 /* QKQueryStringAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1726979315AEE939009586E1 /* QKQueryStringAdditions.h */; }; 1726979615AEE939009586E1 /* QKQueryStringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1726979415AEE939009586E1 /* QKQueryStringAdditions.m */; }; + 173F094A15B5720A00371974 /* QKQueryConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 173F094915B5720A00371974 /* QKQueryConstants.m */; }; 17577F6715A98FEA00CDF67A /* QKTestConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 17577F6615A98FEA00CDF67A /* QKTestConstants.m */; }; 17577FC615A99AC000CDF67A /* QKQueryConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 17577FC415A99AC000CDF67A /* QKQueryConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1757801E15A9A14400CDF67A /* QKQueryGenericParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = 1757801C15A9A14400CDF67A /* QKQueryGenericParameter.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1757801F15A9A14400CDF67A /* QKQueryGenericParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1757801D15A9A14400CDF67A /* QKQueryGenericParameter.m */; }; + 179FEECA15B6CE50009B34F0 /* QKTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 179FEEC915B6CE50009B34F0 /* QKTestCase.m */; }; 17E5951F14F301DF0054EE08 /* QKQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951614F301DF0054EE08 /* QKQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; 17E5952014F301DF0054EE08 /* QKQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 17E5951714F301DF0054EE08 /* QKQuery.m */; }; 17E5952114F301DF0054EE08 /* QKQueryOperators.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951814F301DF0054EE08 /* QKQueryOperators.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -59,11 +61,18 @@ 1726976515AC3DD2009586E1 /* QKQueryDatabases.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryDatabases.h; sourceTree = "<group>"; }; 1726979315AEE939009586E1 /* QKQueryStringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryStringAdditions.h; sourceTree = "<group>"; }; 1726979415AEE939009586E1 /* QKQueryStringAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryStringAdditions.m; sourceTree = "<group>"; }; + 173F093115B56E3400371974 /* QKSelectQueryTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKSelectQueryTests.h; sourceTree = "<group>"; }; + 173F094915B5720A00371974 /* QKQueryConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryConstants.m; sourceTree = "<group>"; }; + 173F096315B5774400371974 /* QKUpdateQueryTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKUpdateQueryTests.h; sourceTree = "<group>"; }; 17577F6515A98FEA00CDF67A /* QKTestConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKTestConstants.h; sourceTree = "<group>"; }; 17577F6615A98FEA00CDF67A /* QKTestConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKTestConstants.m; sourceTree = "<group>"; }; 17577FC415A99AC000CDF67A /* QKQueryConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryConstants.h; sourceTree = "<group>"; }; 1757801C15A9A14400CDF67A /* QKQueryGenericParameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryGenericParameter.h; sourceTree = "<group>"; }; 1757801D15A9A14400CDF67A /* QKQueryGenericParameter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryGenericParameter.m; sourceTree = "<group>"; }; + 179FEEB915B6CC0C009B34F0 /* QKSelectQueryOrderByTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKSelectQueryOrderByTests.h; sourceTree = "<group>"; }; + 179FEEC515B6CD55009B34F0 /* QKSelectQueryGroupByTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKSelectQueryGroupByTests.h; sourceTree = "<group>"; }; + 179FEEC815B6CE50009B34F0 /* QKTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKTestCase.h; sourceTree = "<group>"; }; + 179FEEC915B6CE50009B34F0 /* QKTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKTestCase.m; sourceTree = "<group>"; }; 17E5951614F301DF0054EE08 /* QKQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQuery.h; sourceTree = "<group>"; }; 17E5951714F301DF0054EE08 /* QKQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQuery.m; sourceTree = "<group>"; }; 17E5951814F301DF0054EE08 /* QKQueryOperators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryOperators.h; sourceTree = "<group>"; }; @@ -178,8 +187,11 @@ 17322A7214FA645300F0CF9B /* SELECT Tests */ = { isa = PBXGroup; children = ( + 173F093115B56E3400371974 /* QKSelectQueryTests.h */, 17E5969814F307B70054EE08 /* QKSelectQueryTests.m */, + 179FEEB915B6CC0C009B34F0 /* QKSelectQueryOrderByTests.h */, 1713ECAF14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m */, + 179FEEC515B6CD55009B34F0 /* QKSelectQueryGroupByTests.h */, 1713ECD714F970BB0013C4F0 /* QKSelectQueryGroupByTests.m */, ); name = "SELECT Tests"; @@ -188,6 +200,7 @@ 17322A7414FA646000F0CF9B /* UPDATE Tests */ = { isa = PBXGroup; children = ( + 173F096315B5774400371974 /* QKUpdateQueryTests.h */, 1719E4BA151F51EA003F98C5 /* QKUpdateQueryTests.m */, ); name = "UPDATE Tests"; @@ -231,6 +244,7 @@ 17E5951814F301DF0054EE08 /* QKQueryOperators.h */, 1726976515AC3DD2009586E1 /* QKQueryDatabases.h */, 17577FC415A99AC000CDF67A /* QKQueryConstants.h */, + 173F094915B5720A00371974 /* QKQueryConstants.m */, ); name = Constants; sourceTree = "<group>"; @@ -262,6 +276,8 @@ 17F48D1415B2DCA900C6455B /* Other */ = { isa = PBXGroup; children = ( + 179FEEC815B6CE50009B34F0 /* QKTestCase.h */, + 179FEEC915B6CE50009B34F0 /* QKTestCase.m */, 17577F6515A98FEA00CDF67A /* QKTestConstants.h */, 17577F6615A98FEA00CDF67A /* QKTestConstants.m */, ); @@ -394,6 +410,7 @@ 1719E4BD151F51F1003F98C5 /* QKUpdateQueryTests.m in Sources */, 17577F6715A98FEA00CDF67A /* QKTestConstants.m in Sources */, 1726972915AAF6CE009586E1 /* QKQueryTests.m in Sources */, + 179FEECA15B6CE50009B34F0 /* QKTestCase.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -409,6 +426,7 @@ 1726979615AEE939009586E1 /* QKQueryStringAdditions.m in Sources */, 17F48BA915B27F6500C6455B /* QKQueryOrderBy.m in Sources */, 17F48BC415B289C100C6455B /* QKQueryConstruct.m in Sources */, + 173F094A15B5720A00371974 /* QKQueryConstants.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Frameworks/QueryKit/Source/QKQueryConstants.h b/Frameworks/QueryKit/Source/QKQueryConstants.h index 57c7a55b..65bfcbd8 100644 --- a/Frameworks/QueryKit/Source/QKQueryConstants.h +++ b/Frameworks/QueryKit/Source/QKQueryConstants.h @@ -29,3 +29,6 @@ // OTHER DEALINGS IN THE SOFTWARE. #define EMPTY_STRING @"" + +extern NSString *QKMySQLIdentifierQuote; +extern NSString *QKPostgreSQLIdentifierQuote; diff --git a/Frameworks/QueryKit/Source/QKQueryConstants.m b/Frameworks/QueryKit/Source/QKQueryConstants.m new file mode 100644 index 00000000..67fb6eb3 --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryConstants.m @@ -0,0 +1,32 @@ +// +// $Id$ +// +// QKQueryConstants.m +// 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. + +NSString *QKMySQLIdentifierQuote = @"`"; +NSString *QKPostgreSQLIdentifierQuote = @"\""; diff --git a/Frameworks/QueryKit/Source/QKQueryUtilities.m b/Frameworks/QueryKit/Source/QKQueryUtilities.m index 06396ddc..d376ea57 100644 --- a/Frameworks/QueryKit/Source/QKQueryUtilities.m +++ b/Frameworks/QueryKit/Source/QKQueryUtilities.m @@ -46,10 +46,10 @@ static NSString *QKUnrecognisedQueryOperatorException = @"QKUnrecognisedQueryOpe NSString *character = EMPTY_STRING; if (database == QKDatabaseMySQL) { - character = @"`"; + character = QKMySQLIdentifierQuote; } else if (database == QKDatabasePostgreSQL) { - character = @""""; + character = QKPostgreSQLIdentifierQuote; } return character; diff --git a/Frameworks/QueryKit/Source/QueryKit.h b/Frameworks/QueryKit/Source/QueryKit.h index 0ae6b406..3a57920d 100644 --- a/Frameworks/QueryKit/Source/QueryKit.h +++ b/Frameworks/QueryKit/Source/QueryKit.h @@ -31,6 +31,7 @@ #import <QueryKit/QKQuery.h> #import <QueryKit/QKQueryTypes.h> #import <QueryKit/QKQueryOrderBy.h> +#import <QueryKit/QKQueryConstants.h> #import <QueryKit/QKQueryOperators.h> #import <QueryKit/QKQueryDatabases.h> #import <QueryKit/QKQueryParameter.h> 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 |