Created
July 3, 2012 10:52
-
-
Save HBehrens/3039051 to your computer and use it in GitHub Desktop.
proof that NSSelectors are unique and different from their character representation
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
// | |
// SelectorTestTests.m | |
// SelectorTestTests | |
// | |
// Created by Heiko Behrens on 29.06.12. | |
// Copyright (c) 2012 BeamApp. All rights reserved. | |
// | |
#import "SelectorTestTests.h" | |
@implementation SelectorTestTests | |
- (void)testSelector | |
{ | |
// create two different instances of NSStrings "selector" | |
NSString* name1 = @"selector"; | |
NSString* name2 = [NSString stringWithFormat:@"%@%@", @"sel", @"ector"]; | |
STAssertEqualObjects(name1, name2, @"equal strings"); | |
STAssertTrue(name1 != name2, @"different string instances"); | |
// NSSelectorFromString returns *same* selector | |
SEL sel_name1 = NSSelectorFromString(name1); | |
SEL sel_name2 = NSSelectorFromString(name2); | |
STAssertEqualObjects(NSStringFromSelector(sel_name1), NSStringFromSelector(sel_name2), @"equals selectors"); | |
STAssertTrue(sel_name1 == sel_name2, @"same selector"); | |
// create two different pointers to char[] "selector" | |
const char* char1 = [name1 UTF8String]; | |
const char* char2 = [name2 UTF8String]; | |
STAssertTrue(name1 != name2, @"different char* pointers"); | |
// sel_registerName returns *same* selector | |
// => does not return same char again | |
SEL sel_char1 = sel_registerName(char1); | |
SEL sel_char2 = sel_registerName(char2); | |
STAssertEqualObjects(NSStringFromSelector(sel_char1), NSStringFromSelector(sel_char2), @"equals selectors"); | |
STAssertTrue(sel_char1 == sel_char2, @"same selector"); | |
// verify in the logs that this test will actually be executed | |
STFail(@"findme"); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment