Sha256: 59e8063a152e596c5da5993ae74d71d6de9fa96aae4f05023265ad7a4125d7a3

Contents?: true

Size: 1.55 KB

Versions: 32

Compression:

Stored size: 1.55 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "Custom type definitions" do
  it "attach_function with custom typedef" do
    module CustomTypedef
      extend FFI::Library
      ffi_lib TestLibrary::PATH
      typedef :uint, :fubar_t
      attach_function :ret_u32, [ :fubar_t ], :fubar_t
    end
    CustomTypedef.ret_u32(0x12345678).should == 0x12345678
  end
  it "variadic invoker with custom typedef" do
    module VariadicCustomTypedef
      extend FFI::Library
      ffi_lib TestLibrary::PATH
      typedef :uint, :fubar_t
      attach_function :pack_varargs, [ :buffer_out, :string, :varargs ], :void
    end
    buf = FFI::Buffer.new :uint, 10
    VariadicCustomTypedef.pack_varargs(buf, "i", :fubar_t, 0x12345678)
    buf.get_int64(0).should == 0x12345678
  end
  it "Callback with custom typedef parameter" do
    module CallbackCustomTypedef
      extend FFI::Library
      ffi_lib TestLibrary::PATH
      typedef :uint, :fubar3_t
      callback :cbIrV, [ :fubar3_t ], :void
      attach_function :testCallbackU32rV, :testClosureIrV, [ :cbIrV, :fubar3_t ], :void
    end
    i = 0
    CallbackCustomTypedef.testCallbackU32rV(0xdeadbeef) { |v| i = v }
    i.should == 0xdeadbeef
  end
    module StructCustomTypedef
      extend FFI::Library
      ffi_lib TestLibrary::PATH
      typedef :uint, :fubar3_t
      class S < FFI::Struct
        layout :a, :fubar3_t
      end
    end
  it "Struct with custom typedef field" do
    s = StructCustomTypedef::S.new
    s[:a] = 0x12345678
    s.pointer.get_uint(0).should == 0x12345678
  end
end

Version data entries

32 entries across 32 versions & 5 rubygems

Version Path
ffi-ffi-0.5.0 spec/ffi/typedef_spec.rb
remogatto-ffi-0.5.0 spec/ffi/typedef_spec.rb
ffi-0.6.4 spec/ffi/typedef_spec.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/ffi-0.6.3/spec/ffi/typedef_spec.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/ffi-0.6.3/spec/ffi/typedef_spec.rb
ffi-0.6.3-x86-mingw32 spec/ffi/typedef_spec.rb
ffi-0.6.3-x86-mswin32 spec/ffi/typedef_spec.rb
ffi-0.6.3 spec/ffi/typedef_spec.rb
ffi-0.6.2 spec/ffi/typedef_spec.rb
ffi-0.6.1 spec/ffi/typedef_spec.rb
ffi-0.6.0 spec/ffi/typedef_spec.rb
ffi-0.5.4-x86-mswin32 spec/ffi/typedef_spec.rb
ffi-0.5.4-x86-mingw32 spec/ffi/typedef_spec.rb
ffi-0.5.4 spec/ffi/typedef_spec.rb
ffi-0.5.3-x86-mswin32 spec/ffi/typedef_spec.rb
ffi-0.5.3 spec/ffi/typedef_spec.rb
ffi-0.5.3-x86-mingw32 spec/ffi/typedef_spec.rb
minilab-1.1.0-x86-mswin32-60 vendor/ffi-0.4.0-x86-mswin32/spec/ffi/typedef_spec.rb
ffi-0.5.1-x86-mswin32 spec/ffi/typedef_spec.rb
ffi-0.5.1 spec/ffi/typedef_spec.rb