mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-17 12:20:25 +08:00
[ImmediateRef] Add failing tests.
This commit is contained in:
23
test/test/spec/immediateref_spec.rb
Normal file
23
test/test/spec/immediateref_spec.rb
Normal 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
|
||||
8
test/test/vendor/code/code.h
vendored
8
test/test/vendor/code/code.h
vendored
@@ -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
|
||||
|
||||
30
test/test/vendor/code/code.m
vendored
30
test/test/vendor/code/code.m
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user