From ec46ceda6bcb78974fe4f6b6e07425605e4ace02 Mon Sep 17 00:00:00 2001 From: Takayuki YAMAGUCHI Date: Sat, 9 Jun 2018 11:15:05 +0900 Subject: [PATCH] Add spec for Pointer#write_array_of_type --- spec/ffi/pointer_spec.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/ffi/pointer_spec.rb b/spec/ffi/pointer_spec.rb index 8f3be8c02..a1c0a92d5 100644 --- a/spec/ffi/pointer_spec.rb +++ b/spec/ffi/pointer_spec.rb @@ -94,7 +94,26 @@ def to_ptr expect(array[j].address).to eq(address) end end - + + it "#write_array_of_type for uint8" do + values = [10, 227, 32] + memory = FFI::MemoryPointer.new FFI::TYPE_UINT8, values.size + memory.write_array_of_type(FFI::TYPE_UINT8, :put_uint8, values) + array = memory.read_array_of_type(FFI::TYPE_UINT8, :read_uint8, values.size) + values.each_with_index do |val, j| + expect(array[j]).to eq(val) + end + end + + it "#write_array_of_type for uint32" do + values = [10, 227, 32] + memory = FFI::MemoryPointer.new FFI::TYPE_UINT32, values.size + memory.write_array_of_type(FFI::TYPE_UINT32, :put_uint32, values) + array = memory.read_array_of_type(FFI::TYPE_UINT32, :read_uint32, values.size) + values.each_with_index do |val, j| + expect(array[j]).to eq(val) + end + end end describe 'NULL' do