1 // TEST_CFLAGS -framework Foundation
4 #include <objc/runtime.h>
5 #import <Foundation/Foundation.h>
7 #if OBJC_HAVE_TAGGED_POINTERS
9 void testTaggedNumber()
11 NSNumber *taggedNS = [NSNumber numberWithInt: 1234];
12 CFNumberRef taggedCF = (CFNumberRef)objc_unretainedPointer(taggedNS);
15 testassert( CFGetTypeID(taggedCF) == CFNumberGetTypeID() );
16 testassert(_objc_getClassForTag(OBJC_TAG_NSNumber) == [taggedNS class]);
18 CFNumberGetValue(taggedCF, kCFNumberIntType, &result);
19 testassert(result == 1234);
21 testassert(_objc_isTaggedPointer(taggedCF));
22 testassert(_objc_getTaggedPointerTag(taggedCF) == OBJC_TAG_NSNumber);
23 testassert(_objc_makeTaggedPointer(_objc_getTaggedPointerTag(taggedCF), _objc_getTaggedPointerValue(taggedCF)) == taggedCF);
25 // do some generic object-y things to the taggedPointer instance
29 NSMutableDictionary *dict = [NSMutableDictionary dictionary];
30 [dict setObject: taggedNS forKey: @"fred"];
31 testassert(taggedNS == [dict objectForKey: @"fred"]);
32 [dict setObject: @"bob" forKey: taggedNS];
33 testassert([@"bob" isEqualToString: [dict objectForKey: taggedNS]]);
35 NSNumber *iM88 = [NSNumber numberWithInt:-88];
36 NSNumber *i12346 = [NSNumber numberWithInt: 12346];
37 NSNumber *i12347 = [NSNumber numberWithInt: 12347];
39 NSArray *anArray = [NSArray arrayWithObjects: iM88, i12346, i12347, nil];
40 testassert([anArray count] == 3);
41 testassert([anArray indexOfObject: i12346] == 1);
43 NSSet *aSet = [NSSet setWithObjects: iM88, i12346, i12347, nil];
44 testassert([aSet count] == 3);
45 testassert([aSet containsObject: i12346]);
47 [taggedNS performSelector: @selector(intValue)];
48 testassert(![taggedNS isProxy]);
49 testassert([taggedNS isKindOfClass: [NSNumber class]]);
50 testassert([taggedNS respondsToSelector: @selector(intValue)]);
52 (void)[taggedNS description];
58 testTaggedNumber(); // should be tested by CF... our tests are wrong, wrong, wrong.
64 // OBJC_HAVE_TAGGED_POINTERS
66 // not OBJC_HAVE_TAGGED_POINTERS
68 // Tagged pointers not supported. Crash if an NSNumber actually
69 // is a tagged pointer (which means this test is out of date).
74 testassert(*(void **)objc_unretainedPointer([NSNumber numberWithInt:1234]));