Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 65 additions & 12 deletions Tests/EXTPassthroughTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,120 @@
#import "EXTPassthroughTest.h"

@interface InnerClass : NSObject
@property (nonatomic, getter = isEnabled) BOOL enabled;

- (void)voidMethod;
- (int)methodWithString:(NSString *)str;
- (int)methodWithString:(NSString *)str number:(NSNumber *)num;

@property (nonatomic, getter = hasFlakyCrust, setter = topWithFlakyCrust:) BOOL flakyCrust;
@property (nonatomic, getter = isALaMode) BOOL aLaMode;
@property (strong, nonatomic, setter = assignFilling:, getter = whatIsTheFilling) NSString * filling;
@property (nonatomic) NSTimeInterval bakingTime;

@end

@interface OuterClass : NSObject
@property (nonatomic, strong) InnerClass *inner;

@property (nonatomic, getter = hasFlakyCrust, setter = topWithFlakyCrust:) BOOL flakyCrust;
@property (nonatomic) BOOL aLaMode;
@property (strong, nonatomic) NSString * fruitType;

@end

@interface OuterClass (DelegatedMethods)
@property (nonatomic, getter = isEnabled) BOOL enabled;

- (void)renamedMethod;
- (int)methodWithString:(NSString *)str;
- (int)methodWithString:(NSString *)str number:(NSNumber *)num;
@end

@interface OuterClass (DelegatedProperty)
@property (nonatomic) NSTimeInterval bakingTime;
@end

@implementation EXTPassthroughTest

- (void)testPassthroughMethods {
OuterClass *outer = [[OuterClass alloc] init];
STAssertNotNil(outer, @"");

[outer renamedMethod];
STAssertEquals([outer methodWithString:@"foo"], 3, @"");
STAssertEquals([outer methodWithString:@"foobar" number:@5], 11, @"");
}

- (void)testPassthroughProperty {
- (void)testPassthroughPropertyCustomAccessors {
OuterClass *outer = [[OuterClass alloc] init];
STAssertNotNil(outer, @"");
STAssertFalse(outer.enabled, @"");
STAssertFalse(outer.inner.enabled, @"");
STAssertFalse(outer.flakyCrust, @"");
STAssertFalse(outer.inner.flakyCrust, @"");

outer.flakyCrust = YES;
STAssertTrue(outer.flakyCrust, @"");
STAssertTrue(outer.inner.flakyCrust, @"");
}

outer.enabled = YES;
STAssertTrue(outer.enabled, @"");
STAssertTrue(outer.inner.enabled, @"");
- (void)testPassthroughPropertySameBaseNameDifferentAccessors {
OuterClass *outer = [[OuterClass alloc] init];
STAssertNotNil(outer, @"");
STAssertFalse(outer.aLaMode, @"");
STAssertFalse(outer.inner.aLaMode, @"");

outer.aLaMode = YES;
STAssertTrue(outer.aLaMode, @"");
STAssertTrue(outer.inner.aLaMode, @"");
}

- (void)testPassthroughPropertyDifferentNames {
OuterClass *outer = [[OuterClass alloc] init];
STAssertNotNil(outer, @"");
STAssertEqualObjects(nil, outer.fruitType, @"");
STAssertEqualObjects(nil, outer.inner.filling, @"");

outer.fruitType = @"Pear";
STAssertEqualObjects(@"Pear", outer.fruitType, @"");
STAssertEqualObjects(@"Pear", outer.inner.filling, @"");
}

- (void)testPassthroughPropertySameNames {
OuterClass *outer = [[OuterClass alloc] init];
STAssertNotNil(outer, @"");
STAssertEquals(0.0, outer.bakingTime, @"");
STAssertEquals(0.0, outer.inner.bakingTime, @"");

outer.bakingTime = 75.0;
STAssertEqualsWithAccuracy(75.0, outer.bakingTime, 0.5, @"");
STAssertEqualsWithAccuracy(75.0, outer.inner.bakingTime, 0.5, @"");
}


@end

@implementation OuterClass
@passthrough(OuterClass, renamedMethod, self.inner, voidMethod);
@passthrough(OuterClass, methodWithString:, self.inner);
@passthrough(OuterClass, methodWithString:number:, [self inner]);
@passthrough(OuterClass, isEnabled, self.inner);
@passthrough(OuterClass, setEnabled:, self.inner);

@passthrough_property(OuterClass, flakyCrust, self.inner);
@passthrough_property(OuterClass, fruitType, self.inner, filling);
@passthrough_property(OuterClass, aLaMode, self.inner, aLaMode);

- (id)init {
self = [super init];
if (!self)
return nil;

self.inner = [[InnerClass alloc] init];
return self;
}

@end

@implementation OuterClass (DelegatedProperty)
@passthrough_property(OuterClass, bakingTime, self.inner);
@end

@implementation InnerClass

- (void)voidMethod {
Expand Down
Loading