aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m')
-rw-r--r--Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m78
1 files changed, 40 insertions, 38 deletions
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