Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored objects assertions to a separate class to be used as a bas…
…e class for unit cases which need to do these assertions. Note that we couldn't use class methods as we do with GBTestObjectsRegistry as we use SenTest macros which require failWithException: method be declared in the test case class.
- Loading branch information
Showing
5 changed files
with
118 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// GBObjectsAssertor.h | ||
// appledoc | ||
// | ||
// Created by Tomaz Kragelj on 27.7.10. | ||
// Copyright (C) 2010, Gentle Bytes. All rights reserved. | ||
// | ||
|
||
#import "GBIvarData.h" | ||
#import "GBMethodData.h" | ||
|
||
// Need to derive from SenTestCase otherwise ST macros used wouldn't work... | ||
@interface GBObjectsAssertor : SenTestCase | ||
|
||
- (void)assertIvar:(GBIvarData *)ivar matches:(NSString *)firstType,... NS_REQUIRES_NIL_TERMINATION; | ||
- (void)assertMethod:(GBMethodData *)method matchesInstanceComponents:(NSString *)firstItem,... NS_REQUIRES_NIL_TERMINATION; | ||
- (void)assertMethod:(GBMethodData *)method matchesClassComponents:(NSString *)firstItem,... NS_REQUIRES_NIL_TERMINATION; | ||
- (void)assertMethod:(GBMethodData *)method matchesPropertyComponents:(NSString *)firstItem,... NS_REQUIRES_NIL_TERMINATION; | ||
- (void)assertMethod:(GBMethodData *)method matchesType:(GBMethodType)type start:(NSString *)first components:(va_list)args; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// GBObjectsAssertor.m | ||
// appledoc | ||
// | ||
// Created by Tomaz Kragelj on 27.7.10. | ||
// Copyright (C) 2010, Gentle Bytes. All rights reserved. | ||
// | ||
|
||
#import "GBObjectsAssertor.h" | ||
|
||
@implementation GBObjectsAssertor | ||
|
||
- (void)assertIvar:(GBIvarData *)ivar matches:(NSString *)firstType,... { | ||
NSMutableArray *arguments = [NSMutableArray array]; | ||
va_list args; | ||
va_start(args, firstType); | ||
for (NSString *arg=firstType; arg != nil; arg=va_arg(args, NSString*)) { | ||
[arguments addObject:arg]; | ||
} | ||
va_end(args); | ||
|
||
assertThatInteger([[ivar ivarTypes] count], equalToInteger([arguments count] - 1)); | ||
for (NSUInteger i=0; i<[arguments count] - 1; i++) | ||
assertThat([ivar.ivarTypes objectAtIndex:i], is([arguments objectAtIndex:i])); | ||
|
||
assertThat(ivar.ivarName, is([arguments lastObject])); | ||
} | ||
|
||
- (void)assertMethod:(GBMethodData *)method matchesInstanceComponents:(NSString *)firstItem,... { | ||
va_list args; | ||
va_start(args,firstItem); | ||
[self assertMethod:method matchesType:GBMethodTypeInstance start:firstItem components:args]; | ||
va_end(args); | ||
} | ||
|
||
- (void)assertMethod:(GBMethodData *)method matchesClassComponents:(NSString *)firstItem,... { | ||
va_list args; | ||
va_start(args,firstItem); | ||
[self assertMethod:method matchesType:GBMethodTypeClass start:firstItem components:args]; | ||
va_end(args); | ||
} | ||
|
||
- (void)assertMethod:(GBMethodData *)method matchesPropertyComponents:(NSString *)firstItem,... { | ||
va_list args; | ||
va_start(args,firstItem); | ||
[self assertMethod:method matchesType:GBMethodTypeProperty start:firstItem components:args]; | ||
va_end(args); | ||
} | ||
|
||
- (void)assertMethod:(GBMethodData *)method matchesType:(GBMethodType)type start:(NSString *)first components:(va_list)args { | ||
// Note that we flatten all the arguments to make assertion methods simpler; nice trick but we do need to | ||
// use custom macros instead of hamcrest to get more meaningful description in case of failure :( | ||
STAssertEquals(method.methodType, type, @"Method type doesn't match!"); | ||
|
||
NSMutableArray *arguments = [NSMutableArray arrayWithObject:first]; | ||
NSString *arg; | ||
while ((arg = va_arg(args, NSString*))) { | ||
[arguments addObject:arg]; | ||
} | ||
|
||
NSUInteger i=0; | ||
|
||
for (NSString *attribute in method.methodAttributes) { | ||
STAssertEqualObjects(attribute, [arguments objectAtIndex:i++], @"Property attribute doesn't match at flat idx %ld!", i-1); | ||
} | ||
|
||
for (NSString *type in method.methodResultTypes) { | ||
STAssertEqualObjects(type, [arguments objectAtIndex:i++], @"Method result doesn't match at flat idx %ld!", i-1); | ||
} | ||
|
||
for (GBMethodArgument *argument in method.methodArguments) { | ||
STAssertEqualObjects(argument.argumentName, [arguments objectAtIndex:i++], @"Method argument name doesn't match at flat idx %ld!", i-1); | ||
if (argument.argumentTypes) { | ||
for (NSString *type in argument.argumentTypes) { | ||
STAssertEqualObjects(type, [arguments objectAtIndex:i++], @"Method argument type doesn't match at flat idx %ld!", i-1); | ||
} | ||
} | ||
if (argument.argumentVar) { | ||
STAssertEqualObjects(argument.argumentVar, [arguments objectAtIndex:i++], @"Method argument var doesn't match at flat idx %ld!", i-1); | ||
} | ||
} | ||
|
||
STAssertEquals(i, [arguments count], @"Flattened method has %ld components, expected %ld!", i, [arguments count]); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters