[ImmediateRef] Add failing tests.

This commit is contained in:
Eloy Durán
2014-01-31 17:29:24 +01:00
parent fe655a4424
commit 3e43dcccda
3 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
describe "ImmediateRef" do
class << self
# Tagged pointers are only available on 64-bit platforms.
alias_method :on_64bit_it, RUBY_ARCH =~ /64/ ? :it : :xit
end
on_64bit_it "forwards messages to the wrapped tagged pointer object" do
ref = TaggedNSObjectSubclass.taggedObject(42)
ref.class.should == TaggedNSObjectSubclass
ref.taggedValue.should == 42
ref.should == TaggedNSObjectSubclass.taggedObject(42)
end
on_64bit_it "returns the tagged pointer object's methods" do
ref = TaggedNSObjectSubclass.taggedObject(42)
ref.public_methods(false).should == [:taggedValue, :'isEqualTo:']
end
on_64bit_it "returns the tagged pointer object's description" do
ref = TaggedNSObjectSubclass.taggedObject(42)
ref.inspect.should.start_with '#<TaggedNSObjectSubclass'
end
end

View File

@@ -90,3 +90,11 @@ typedef int (^ReturnsIntBlock)();
void KreateStackBlock(void (^inputBlock)(ReturnsIntBlock));
ReturnsIntBlock KreateMallocBlock(int input);
ReturnsIntBlock KreateGlobalBlock();
#ifdef __LP64__
@interface TaggedNSObjectSubclass : NSObject
+ (id)taggedObject:(uintptr_t)value;
- (uintptr_t)taggedValue;
- (BOOL)isEqualTo:(id)other;
@end
#endif

View File

@@ -177,3 +177,33 @@ ReturnsIntBlock KreateGlobalBlock()
{
return ^{ return 42; };
}
#ifdef __LP64__
void _objc_insert_tagged_isa(unsigned char slotNumber, Class isa);
#define SLOT_NUMBER 7
@implementation TaggedNSObjectSubclass
+ (void)load;
{
_objc_insert_tagged_isa(SLOT_NUMBER, [TaggedNSObjectSubclass class]);
}
+ (id)taggedObject:(uintptr_t)value;
{
return (id)(1UL | ((uintptr_t)SLOT_NUMBER << 1) | (value << 4));
}
- (uintptr_t)taggedValue
{
return (uintptr_t)self >> 4;
}
- (BOOL)isEqualTo:(id)other;
{
return [other isKindOfClass:[TaggedNSObjectSubclass class]] &&
[self taggedValue] == [other taggedValue];
}
@end
#endif