From 8d54d7379473c3eeec9d6460ba175bbf9d4e474b Mon Sep 17 00:00:00 2001 From: Watson Date: Tue, 15 Apr 2014 10:27:21 +0900 Subject: [PATCH] [test] add specs for RM-468 and RM-457 --- test/test/spec/type_encoding_spec.rb | 31 ++++++++++++++++++++++++++++ test/test/vendor/code/code.h | 23 +++++++++++++++++++++ test/test/vendor/code/code.m | 28 +++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 test/test/spec/type_encoding_spec.rb diff --git a/test/test/spec/type_encoding_spec.rb b/test/test/spec/type_encoding_spec.rb new file mode 100644 index 00000000..102cee52 --- /dev/null +++ b/test/test/spec/type_encoding_spec.rb @@ -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 diff --git a/test/test/vendor/code/code.h b/test/test/vendor/code/code.h index 141b1436..90da1606 100644 --- a/test/test/vendor/code/code.h +++ b/test/test/vendor/code/code.h @@ -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 diff --git a/test/test/vendor/code/code.m b/test/test/vendor/code/code.m index f695d1ed..925ccc08 100644 --- a/test/test/vendor/code/code.m +++ b/test/test/vendor/code/code.m @@ -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 \ No newline at end of file