From c411237b6426129796d03bd9d4be7700235f199a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Thu, 8 May 2014 16:52:06 +0200 Subject: [PATCH] Add test to ensure we always convert Pointer instances. --- test/test/spec/pointer_spec.rb | 13 +++++++++++++ test/test/spec/type_encoding_spec.rb | 6 ------ test/test/vendor/code/code.h | 3 ++- test/test/vendor/code/code.m | 9 ++++++++- vm | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/test/test/spec/pointer_spec.rb b/test/test/spec/pointer_spec.rb index e10b7ac5..37204195 100644 --- a/test/test/spec/pointer_spec.rb +++ b/test/test/spec/pointer_spec.rb @@ -6,3 +6,16 @@ describe "Pointer" do TestMethod.testPointerToStrings(ptr, length:vals.size).should == vals.inject(0) { |m, v| m + v } end end + +describe "Void-pointers" do + it "does not try to convert an object" do + obj = Object.new + TestVoidPointer.methodWithObjectVoidPointer(obj).should == obj + end + + it "does convert a Pointer to the actual data" do + pointer = Pointer.new('i') + pointer[0] = 42 + TestVoidPointer.methodWithCTypeVoidPointer(pointer).should == 42 + end +end diff --git a/test/test/spec/type_encoding_spec.rb b/test/test/spec/type_encoding_spec.rb index db9286c8..183a9ba4 100644 --- a/test/test/spec/type_encoding_spec.rb +++ b/test/test/spec/type_encoding_spec.rb @@ -30,9 +30,3 @@ describe "BOOL Type Encoding" do end end -describe "Void-pointers" do - it "does not try to convert an object with a type of `void *`" do - obj = Object.new - TestVoidPointer.methodWithVoidPointer(obj).should == obj - end -end diff --git a/test/test/vendor/code/code.h b/test/test/vendor/code/code.h index 06d5782d..e71dacc9 100644 --- a/test/test/vendor/code/code.h +++ b/test/test/vendor/code/code.h @@ -125,5 +125,6 @@ typedef struct MyUnionHasBool { @end @interface TestVoidPointer : NSObject -+ (id)methodWithVoidPointer:(void *)object; ++ (id)methodWithObjectVoidPointer:(void *)object; ++ (int)methodWithCTypeVoidPointer:(void *)val; @end diff --git a/test/test/vendor/code/code.m b/test/test/vendor/code/code.m index 185a478d..44dd6b47 100644 --- a/test/test/vendor/code/code.m +++ b/test/test/vendor/code/code.m @@ -210,8 +210,15 @@ ReturnsIntBlock KreateGlobalBlock() @end @implementation TestVoidPointer -+ (id)methodWithVoidPointer:(void *)object; + ++ (id)methodWithObjectVoidPointer:(void *)object; { return (id)object; } + ++ (int)methodWithCTypeVoidPointer:(void *)val; +{ + return *(int *)val; +} + @end diff --git a/vm b/vm index 42e6b7b0..7221714a 160000 --- a/vm +++ b/vm @@ -1 +1 @@ -Subproject commit 42e6b7b0cd6dfad997883fe7ccd17eeeb187b13f +Subproject commit 7221714a2ebc1a9fb494a9e69f9af2191e9e5e6e