From 4aebe5fb9cdcd145ef3b3135700e27d13315effd Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Tue, 10 Jul 2012 10:25:09 +0000 Subject: Additional QueryKit tests. --- .../QueryKit/QueryKit.xcodeproj/project.pbxproj | 10 ++- Frameworks/QueryKit/Source/QKQuery.h | 18 ++++-- Frameworks/QueryKit/Source/QKQuery.m | 7 +- .../QueryKit/Source/QKQueryGenericParameter.h | 6 +- Frameworks/QueryKit/Source/QKQueryParameter.h | 2 +- Frameworks/QueryKit/Source/QKQueryTypes.h | 1 + Frameworks/QueryKit/Tests/QKQueryTests.h | 39 +++++++++++ Frameworks/QueryKit/Tests/QKQueryTests.m | 75 ++++++++++++++++++++++ Frameworks/QueryKit/Tests/QKTestConstants.h | 1 + Frameworks/QueryKit/Tests/QKTestConstants.m | 3 +- 10 files changed, 146 insertions(+), 16 deletions(-) create mode 100644 Frameworks/QueryKit/Tests/QKQueryTests.h create mode 100644 Frameworks/QueryKit/Tests/QKQueryTests.m (limited to 'Frameworks') diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj index 921b867d..5be0b1b1 100644 --- a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj +++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 1719E47D151E8CA7003F98C5 /* QKQueryUpdateParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = 1719E47B151E8CA7003F98C5 /* QKQueryUpdateParameter.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1719E47E151E8CA7003F98C5 /* QKQueryUpdateParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1719E47C151E8CA7003F98C5 /* QKQueryUpdateParameter.m */; }; 1719E4BD151F51F1003F98C5 /* QKUpdateQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1719E4BA151F51EA003F98C5 /* QKUpdateQueryTests.m */; }; + 1726972915AAF6CE009586E1 /* QKQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1726972815AAF6CE009586E1 /* QKQueryTests.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, ); }; }; @@ -50,6 +51,8 @@ 1719E47C151E8CA7003F98C5 /* QKQueryUpdateParameter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryUpdateParameter.m; sourceTree = ""; }; 1719E4B9151F51EA003F98C5 /* QKUpdateQueryTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKUpdateQueryTests.h; sourceTree = ""; }; 1719E4BA151F51EA003F98C5 /* QKUpdateQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKUpdateQueryTests.m; sourceTree = ""; }; + 1726972715AAF6CE009586E1 /* QKQueryTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryTests.h; sourceTree = ""; }; + 1726972815AAF6CE009586E1 /* QKQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryTests.m; sourceTree = ""; }; 17577F6515A98FEA00CDF67A /* QKTestConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKTestConstants.h; sourceTree = ""; }; 17577F6615A98FEA00CDF67A /* QKTestConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKTestConstants.m; sourceTree = ""; }; 17577FC415A99AC000CDF67A /* QKQueryConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryConstants.h; sourceTree = ""; }; @@ -201,6 +204,8 @@ 17577FA015A994EB00CDF67A /* Common */ = { isa = PBXGroup; children = ( + 1726972715AAF6CE009586E1 /* QKQueryTests.h */, + 1726972815AAF6CE009586E1 /* QKQueryTests.m */, 17577F6515A98FEA00CDF67A /* QKTestConstants.h */, 17577F6615A98FEA00CDF67A /* QKTestConstants.m */, ); @@ -228,10 +233,10 @@ isa = PBXGroup; children = ( 17577FA015A994EB00CDF67A /* Common */, - 17322A7614FA648100F0CF9B /* INSERT Tests */, - 17322A7514FA647200F0CF9B /* DELETE Tests */, 17322A7414FA646000F0CF9B /* UPDATE Tests */, 17322A7214FA645300F0CF9B /* SELECT Tests */, + 17322A7614FA648100F0CF9B /* INSERT Tests */, + 17322A7514FA647200F0CF9B /* DELETE Tests */, ); path = Tests; sourceTree = ""; @@ -357,6 +362,7 @@ 1713ECD814F970BB0013C4F0 /* QKSelectQueryGroupByTests.m in Sources */, 1719E4BD151F51F1003F98C5 /* QKUpdateQueryTests.m in Sources */, 17577F6715A98FEA00CDF67A /* QKTestConstants.m in Sources */, + 1726972915AAF6CE009586E1 /* QKQueryTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Frameworks/QueryKit/Source/QKQuery.h b/Frameworks/QueryKit/Source/QKQuery.h index 1cb93d15..e3b7f148 100644 --- a/Frameworks/QueryKit/Source/QKQuery.h +++ b/Frameworks/QueryKit/Source/QKQuery.h @@ -62,37 +62,41 @@ /** * @property _database The database the query is to be run against (optional). */ -@property (readwrite, retain, getter=database, setter=setDatabase:) NSString *_database; +@property(readwrite, retain, getter=database, setter=setDatabase:) NSString *_database; /** * @property _table The table the query is to be run against. */ -@property (readwrite, retain, getter=table, setter=setTable:) NSString *_table; +@property(readwrite, retain, getter=table, setter=setTable:) NSString *_table; /** * @property _parameters The parameters (constraints) of the query. */ -@property (readwrite, retain, getter=parameters, setter=setParameters:) NSMutableArray *_parameters; +@property(readwrite, retain, getter=parameters, setter=setParameters:) NSMutableArray *_parameters; /** * @property _fields The fields of the query. */ -@property (readwrite, retain, getter=fields, setter=setFields:) NSMutableArray *_fields; +@property(readwrite, retain, getter=fields, setter=setFields:) NSMutableArray *_fields; /** * @property _updateFields The fields of an UPDATE query. */ -@property (readwrite, retain, getter=updateParameters, setter=setUpdateParameters:) NSMutableArray *_updateParameters; +@property(readwrite, retain, getter=updateParameters, setter=setUpdateParameters:) NSMutableArray *_updateParameters; /** * @property _queryType The type of query to be built. */ -@property (readwrite, assign, getter=queryType, setter=setQueryType:) QKQueryType _queryType; +@property(readwrite, assign, getter=queryType, setter=setQueryType:) QKQueryType _queryType; /** * @property _useQuotes Indicates whether or not the query's fields should be quoted. */ -@property (readwrite, assign, getter=useQuotes) BOOL _useQuotes; +@property(readwrite, assign, getter=useQuotes) BOOL _useQuotes; + +@property(readonly, getter=groupByFields) NSMutableArray *_groupByFields; + +@property(readonly, getter=orderByFields) NSMutableArray *_orderByFields; + (QKQuery *)queryTable:(NSString *)table; + (QKQuery *)selectQueryFromTable:(NSString *)table; diff --git a/Frameworks/QueryKit/Source/QKQuery.m b/Frameworks/QueryKit/Source/QKQuery.m index 124bb5d2..c60f3162 100644 --- a/Frameworks/QueryKit/Source/QKQuery.m +++ b/Frameworks/QueryKit/Source/QKQuery.m @@ -60,6 +60,8 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; @synthesize _fields; @synthesize _updateParameters; @synthesize _useQuotes; +@synthesize _groupByFields; +@synthesize _orderByFields; #pragma mark - #pragma mark Initialization @@ -85,7 +87,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; [self setFields:[[NSMutableArray alloc] init]]; [self setUpdateParameters:[[NSMutableArray alloc] init]]; [self setParameters:[[NSMutableArray alloc] init]]; - [self setQueryType:(QKQueryType)-1]; + [self setQueryType:QKUnknownQuery]; [self setUseQuotes:YES]; _orderDescending = NO; @@ -119,7 +121,8 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; { [self setTable:nil]; [self setDatabase:nil]; - [self setQueryType:(QKQueryType)-1]; + [self setUseQuotes:YES]; + [self setQueryType:QKUnknownQuery]; [_fields removeAllObjects]; [_parameters removeAllObjects]; diff --git a/Frameworks/QueryKit/Source/QKQueryGenericParameter.h b/Frameworks/QueryKit/Source/QKQueryGenericParameter.h index ba1e63cd..63e9b529 100644 --- a/Frameworks/QueryKit/Source/QKQueryGenericParameter.h +++ b/Frameworks/QueryKit/Source/QKQueryGenericParameter.h @@ -38,16 +38,16 @@ /** * @property _field The field component of the parameter. */ -@property (readwrite, retain, getter=field, setter=setField:) NSString *_field; +@property(readwrite, retain, getter=field, setter=setField:) NSString *_field; /** * @property _quoteField Indicates whether or not this parameters field should be quoted. */ -@property (readwrite, assign, getter=useQuotes, setter=setUseQuotes:) BOOL _useQuotes; +@property(readwrite, assign, getter=useQuotes, setter=setUseQuotes:) BOOL _useQuotes; /** *@property _value The value component of the parameter. */ -@property (readwrite, retain, getter=value, setter=setValue:) id _value; +@property(readwrite, retain, getter=value, setter=setValue:) id _value; @end diff --git a/Frameworks/QueryKit/Source/QKQueryParameter.h b/Frameworks/QueryKit/Source/QKQueryParameter.h index b2436468..8cbcafd6 100644 --- a/Frameworks/QueryKit/Source/QKQueryParameter.h +++ b/Frameworks/QueryKit/Source/QKQueryParameter.h @@ -46,7 +46,7 @@ /** * @property _operator The operator component of the parameter. */ -@property (readwrite, assign, getter=operator, setter=setOperator:) QKQueryOperator _operator; +@property(readwrite, assign, getter=operator, setter=setOperator:) QKQueryOperator _operator; + (QKQueryParameter *)queryParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value; diff --git a/Frameworks/QueryKit/Source/QKQueryTypes.h b/Frameworks/QueryKit/Source/QKQueryTypes.h index 96978ce2..9416a0aa 100644 --- a/Frameworks/QueryKit/Source/QKQueryTypes.h +++ b/Frameworks/QueryKit/Source/QKQueryTypes.h @@ -35,6 +35,7 @@ */ typedef enum { + QKUnknownQuery = -1, QKSelectQuery, QKUpdateQuery, QKInsertQuery, diff --git a/Frameworks/QueryKit/Tests/QKQueryTests.h b/Frameworks/QueryKit/Tests/QKQueryTests.h new file mode 100644 index 00000000..767235eb --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKQueryTests.h @@ -0,0 +1,39 @@ +// +// $Id$ +// +// QKQueryTests.h +// QueryKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 9, 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 +#import + +@interface QKQueryTests : SenTestCase +{ + QKQuery *_query; +} + +@end diff --git a/Frameworks/QueryKit/Tests/QKQueryTests.m b/Frameworks/QueryKit/Tests/QKQueryTests.m new file mode 100644 index 00000000..63b0ec73 --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKQueryTests.m @@ -0,0 +1,75 @@ +// +// $Id$ +// +// QKQueryTests.m +// QueryKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 9, 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 "QKQueryTests.h" +#import "QKTestConstants.h" + +@implementation QKQueryTests + +#pragma mark - +#pragma mark Setup + +- (void)setUp +{ + _query = [QKQuery selectQueryFromTable:QKTestTableName]; + + [_query setUseQuotes:NO]; + + [_query setDatabase:QKTestDatabaseName]; + + [_query addField:QKTestFieldOne]; + [_query addField:QKTestFieldTwo]; + [_query addField:QKTestFieldThree]; + [_query addField:QKTestFieldFour]; + + [_query addParameter:QKTestFieldOne operator:QKEqualityOperator value:[NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; + + [_query orderByField:QKTestFieldOne descending:NO]; +} + +#pragma mark - +#pragma mark Tests + +- (void)testCallingClearOnAQueryCorretlyResetsItToItsDefaultState +{ + [_query clear]; + + STAssertNil([_query table], @"query table"); + STAssertNil([_query database], @"query database"); + STAssertTrue([_query useQuotes], @"query use quotes"); + STAssertTrue([_query queryType] == QKUnknownQuery, @"query type"); + 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"); +} + +@end diff --git a/Frameworks/QueryKit/Tests/QKTestConstants.h b/Frameworks/QueryKit/Tests/QKTestConstants.h index 920ff060..10e3fa7e 100644 --- a/Frameworks/QueryKit/Tests/QKTestConstants.h +++ b/Frameworks/QueryKit/Tests/QKTestConstants.h @@ -28,6 +28,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. +extern NSString *QKTestDatabaseName; extern NSString *QKTestTableName; extern NSString *QKTestFieldOne; diff --git a/Frameworks/QueryKit/Tests/QKTestConstants.m b/Frameworks/QueryKit/Tests/QKTestConstants.m index 419d2987..bf16aa9c 100644 --- a/Frameworks/QueryKit/Tests/QKTestConstants.m +++ b/Frameworks/QueryKit/Tests/QKTestConstants.m @@ -28,7 +28,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -NSString *QKTestTableName = @"test_table"; +NSString *QKTestDatabaseName = @"test_database"; +NSString *QKTestTableName = @"test_table"; NSString *QKTestFieldOne = @"test_field1"; NSString *QKTestFieldTwo = @"test_field2"; -- cgit v1.2.3