Libraries/libextobjc/extobjc/Tests/EXTSafeCategoryTest.m
//
//  EXTSafeCategoryTest.m
//  extobjc
//
//  Created by Justin Spahr-Summers on 2010-11-13.
//  Released into the public domain.
//

#import "EXTSafeCategoryTest.h"

// make sure failed safe categories don't crash the test (since we explicitly
// test such a case below)
#ifndef NDEBUG
#define NDEBUG
#endif

#undef DEBUG

#import "EXTSafeCategory.h"

/*** category interface ***/
@interface NSObject (TestExtensions)
- (NSString *)description;
- (NSString *)customDescription;
@end

/*** category implementation ***/
@safecategory(NSObject, TestExtensions)
- (NSString *)description {
    return [self customDescription];
}

- (NSString *)customDescription {
    return @"NSObject(TestExtensions)";
}

@end

/*** logic test code ***/
@implementation EXTSafeCategoryTest
- (void)testSafeCategory {
    NSObject *obj = [[NSObject alloc] init];
    STAssertNotNil(obj, @"could not allocate object of safe category'd class");
    STAssertTrue([obj respondsToSelector:@selector(description)], @"category'd object should respond to pre-existing method selector");
    STAssertTrue([obj respondsToSelector:@selector(customDescription)], @"category'd object should respond to added method selector");
    STAssertFalse([[obj description] isEqualToString:@"NSObject(TestExtensions)"], @"expected -description method to be original implementation, not overriden");
    STAssertEqualObjects([obj customDescription], @"NSObject(TestExtensions)", @"expected -customDescription method to be implemented, and return custom value");
}
@end
