Sha256: 6b1022fd5b303f333a20eb92aeff3adc8d953aa10ff364f3c8cc1ec915aee90d

Contents?: true

Size: 685 Bytes

Versions: 3

Compression:

Stored size: 685 Bytes

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))

class Timeval < FFI::Struct
  layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4  
end

module LibC
  extend FFI::Library
  
  attach_function :gettimeofday, [:pointer, :pointer], :int
end

describe FFI::Library, "#attach_function" do
  it "correctly returns a value for gettimeofday" do
    t = Timeval.new
    time = LibC.gettimeofday(t.pointer, nil)
    time.should be_kind_of(Integer)
  end
  
  it "correctly populates a struct for gettimeofday" do
    t = Timeval.new
    time = LibC.gettimeofday(t.pointer, nil)
    t[:tv_sec].should be_kind_of(Numeric)
    t[:tv_usec].should be_kind_of(Numeric)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-0.2.0 specs/rbx/attach_function_spec.rb
ffi-0.1.0 specs/rbx/attach_function_spec.rb
ffi-0.1.1 specs/rbx/attach_function_spec.rb