mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-01 17:39:54 +08:00
Add test to ensure we always convert Pointer instances.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
3
test/test/vendor/code/code.h
vendored
3
test/test/vendor/code/code.h
vendored
@@ -125,5 +125,6 @@ typedef struct MyUnionHasBool {
|
||||
@end
|
||||
|
||||
@interface TestVoidPointer : NSObject
|
||||
+ (id)methodWithVoidPointer:(void *)object;
|
||||
+ (id)methodWithObjectVoidPointer:(void *)object;
|
||||
+ (int)methodWithCTypeVoidPointer:(void *)val;
|
||||
@end
|
||||
|
||||
9
test/test/vendor/code/code.m
vendored
9
test/test/vendor/code/code.m
vendored
@@ -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
|
||||
|
||||
2
vm
2
vm
Submodule vm updated: 42e6b7b0cd...7221714a2e
Reference in New Issue
Block a user