mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-01 09:31:20 +08:00
[test] add specs for RM-468 and RM-457
This commit is contained in:
31
test/test/spec/type_encoding_spec.rb
Normal file
31
test/test/spec/type_encoding_spec.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
describe "BOOL Type Encoding" do
|
||||
it "should be converted when a method has BOOL pointer" do
|
||||
# RM-468
|
||||
ptr = Pointer.new(:bool)
|
||||
ptr.assign(true)
|
||||
obj = TestBoolType.alloc.initWithBoolPtr(ptr)
|
||||
obj.value.should == true
|
||||
|
||||
ptr.assign(false)
|
||||
obj = TestBoolType.alloc.initWithBoolPtr(ptr)
|
||||
obj.value.should == false
|
||||
end
|
||||
|
||||
it "should be converted when a structure name has 'c' characters" do
|
||||
# RM-457
|
||||
obj = MyStructHasBool.new
|
||||
obj.bool_value = true
|
||||
obj = TestBoolType.alloc.initWithStruct(obj)
|
||||
obj.value.should == true
|
||||
|
||||
obj = MyUnionHasBool.new
|
||||
obj.st.bool_value = true
|
||||
obj = TestBoolType.alloc.initWithUnion(obj)
|
||||
obj.value.should == true
|
||||
end
|
||||
|
||||
it "should be converted when BOOL is contained in return value" do
|
||||
obj = TestBoolType.alloc.init
|
||||
obj.returnBool.should == true
|
||||
end
|
||||
end
|
||||
23
test/test/vendor/code/code.h
vendored
23
test/test/vendor/code/code.h
vendored
@@ -100,3 +100,26 @@ void KreateStackBlock(void (^inputBlock)(ReturnsIntBlock));
|
||||
ReturnsIntBlock KreateMallocBlock(int input);
|
||||
ReturnsIntBlock KreateGlobalBlock();
|
||||
|
||||
|
||||
typedef struct MyStructHasBool {
|
||||
BOOL bool_value;
|
||||
} MyStructHasBool;
|
||||
|
||||
typedef struct MyUnionHasBool {
|
||||
MyStructHasBool st;
|
||||
int value;
|
||||
} MyUnionHasBool;
|
||||
|
||||
@interface TestBoolType : NSObject
|
||||
{
|
||||
NSNumber *_value;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) NSNumber *value;
|
||||
|
||||
- (id)initWithBoolPtr:(BOOL*)val;
|
||||
- (id)initWithStruct:(MyStructHasBool)val;
|
||||
- (id)initWithUnion:(MyUnionHasBool)val;
|
||||
- (BOOL)returnBool;
|
||||
|
||||
@end
|
||||
|
||||
28
test/test/vendor/code/code.m
vendored
28
test/test/vendor/code/code.m
vendored
@@ -180,3 +180,31 @@ ReturnsIntBlock KreateGlobalBlock()
|
||||
return ^{ return 42; };
|
||||
}
|
||||
|
||||
/* Test for RM-468, RM-457 */
|
||||
@implementation TestBoolType : NSObject
|
||||
@synthesize value;
|
||||
|
||||
- (id)initWithBoolPtr:(BOOL*)ptr
|
||||
{
|
||||
self.value = [NSNumber numberWithBool:*ptr];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithStruct:(MyStructHasBool)val
|
||||
{
|
||||
self.value = [NSNumber numberWithBool:val.bool_value];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithUnion:(MyUnionHasBool)val
|
||||
{
|
||||
self.value = [NSNumber numberWithBool:val.st.bool_value];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)returnBool
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user