summaryrefslogtreecommitdiff
path: root/spec/ffi/pointer_spec.rb
diff options
context:
space:
mode:
authorWayne Meissner <wmeissner@gmail.com>2010-12-27 15:58:54 +1000
committerWayne Meissner <wmeissner@gmail.com>2010-12-27 15:58:54 +1000
commitfc2fd9d77cd5c869c8cf0425e86d5496df842213 (patch)
tree5fa31ecbd5c2fa21de4203ea6b8bea8ee70de03f /spec/ffi/pointer_spec.rb
parentacd89b5f1c2d7eaca25330b9ea125b12c863cf7e (diff)
downloadffi-fc2fd9d77cd5c869c8cf0425e86d5496df842213.tar.gz
Cleanup some namespace issues
Diffstat (limited to 'spec/ffi/pointer_spec.rb')
-rw-r--r--spec/ffi/pointer_spec.rb41
1 files changed, 15 insertions, 26 deletions
diff --git a/spec/ffi/pointer_spec.rb b/spec/ffi/pointer_spec.rb
index 71d3e73..30e685d 100644
--- a/spec/ffi/pointer_spec.rb
+++ b/spec/ffi/pointer_spec.rb
@@ -17,7 +17,9 @@ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
require 'delegate'
require 'java' if RUBY_PLATFORM =~ /java/
-module LibTest
+module PointerTestLib
+ extend FFI::Library
+ ffi_lib TestLibrary::PATH
attach_function :ptr_ret_int32_t, [ :pointer, :int ], :int
attach_function :ptr_from_address, [ FFI::Platform::ADDRESS_SIZE == 32 ? :uint : :ulong_long ], :pointer
attach_function :ptr_set_pointer, [ :pointer, :int, :pointer ], :void
@@ -38,7 +40,7 @@ describe "Pointer" do
magic = 0x12345678
memory.put_int32(0, magic)
tp = ToPtrTest.new(memory)
- LibTest.ptr_ret_int32_t(tp, 0).should == magic
+ PointerTestLib.ptr_ret_int32_t(tp, 0).should == magic
end
class PointerDelegate < DelegateClass(FFI::Pointer)
def initialize(ptr)
@@ -53,53 +55,40 @@ describe "Pointer" do
magic = 0x12345678
memory.put_int32(0, magic)
ptr = PointerDelegate.new(memory)
- LibTest.ptr_ret_int32_t(ptr, 0).should == magic
+ PointerTestLib.ptr_ret_int32_t(ptr, 0).should == magic
end
it "Fixnum cannot be used as a Pointer argument" do
- lambda { LibTest.ptr_ret_int32(0, 0) }.should raise_error
+ lambda { PointerTestLib.ptr_ret_int32(0, 0) }.should raise_error
end
it "Bignum cannot be used as a Pointer argument" do
- lambda { LibTest.ptr_ret_int32(0xfee1deadbeefcafebabe, 0) }.should raise_error
+ lambda { PointerTestLib.ptr_ret_int32(0xfee1deadbeefcafebabe, 0) }.should raise_error
end
describe "pointer type methods" do
it "#read_pointer" do
memory = FFI::MemoryPointer.new :pointer
- LibTest.ptr_set_pointer(memory, 0, LibTest.ptr_from_address(0xdeadbeef))
+ PointerTestLib.ptr_set_pointer(memory, 0, PointerTestLib.ptr_from_address(0xdeadbeef))
memory.read_pointer.address.should == 0xdeadbeef
end
it "#write_pointer" do
memory = FFI::MemoryPointer.new :pointer
- memory.write_pointer(LibTest.ptr_from_address(0xdeadbeef))
- LibTest.ptr_ret_pointer(memory, 0).address.should == 0xdeadbeef
+ memory.write_pointer(PointerTestLib.ptr_from_address(0xdeadbeef))
+ PointerTestLib.ptr_ret_pointer(memory, 0).address.should == 0xdeadbeef
end
it "#read_array_of_pointer" do
values = [0x12345678, 0xfeedf00d, 0xdeadbeef]
memory = FFI::MemoryPointer.new :pointer, values.size
values.each_with_index do |address, j|
- LibTest.ptr_set_pointer(memory, j * FFI.type_size(:pointer), LibTest.ptr_from_address(address))
+ PointerTestLib.ptr_set_pointer(memory, j * FFI.type_size(:pointer), PointerTestLib.ptr_from_address(address))
end
array = memory.read_array_of_pointer(values.size)
values.each_with_index do |address, j|
array[j].address.should == address
end
end
-
- it "#write_array_of_pointer" do
- values = [0x12345678, 0xfeedf00d, 0xdeadbeef]
- memory = FFI::MemoryPointer.new :pointer, values.size
- memory.write_array_of_pointer(values.map { |address| LibTest.ptr_from_address(address) })
- array = []
- values.each_with_index do |address, j|
- array << LibTest.ptr_ret_pointer(memory, j * FFI.type_size(:pointer))
- end
- values.each_with_index do |address, j|
- array[j].address.should == address
- end
- end
end
@@ -160,7 +149,7 @@ describe "AutoPointer" do
# note that if we called
# AutoPointerTestHelper.method(:release).to_proc inline, we'd
# have a reference to the pointer and it would never get GC'd.
- ap = AutoPointerSubclass.new(LibTest.ptr_from_address(magic))
+ ap = AutoPointerSubclass.new(PointerTestLib.ptr_from_address(magic))
end
AutoPointerTestHelper.gc_everything loop_count
end
@@ -177,7 +166,7 @@ describe "AutoPointer" do
AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times
AutoPointerTestHelper.reset
loop_count.times do
- ap = FFI::AutoPointer.new(LibTest.ptr_from_address(magic),
+ ap = FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
AutoPointerTestHelper.finalizer)
end
AutoPointerTestHelper.gc_everything loop_count
@@ -187,7 +176,7 @@ describe "AutoPointer" do
AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times
AutoPointerTestHelper.reset
loop_count.times do
- ap = FFI::AutoPointer.new(LibTest.ptr_from_address(magic),
+ ap = FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
AutoPointerTestHelper.method(:release))
end
AutoPointerTestHelper.gc_everything loop_count
@@ -215,7 +204,7 @@ describe "AutoPointer#new" do
lambda { FFI::AutoPointer.new(FFI::MemoryPointer.new(:int))}.should raise_error(::TypeError)
end
it "AutoPointer argument raises TypeError" do
- lambda { AutoPointerSubclass.new(AutoPointerSubclass.new(LibTest.ptr_from_address(0))) }.should raise_error(::TypeError)
+ lambda { AutoPointerSubclass.new(AutoPointerSubclass.new(PointerTestLib.ptr_from_address(0))) }.should raise_error(::TypeError)
end
it "Buffer argument raises TypeError" do
lambda { FFI::AutoPointer.new(FFI::Buffer.new(:int))}.should raise_error(::TypeError)